Your support is needed and is appreciated as Amigaworld.net is primarily dependent upon the support of its users.
|
|
|
|
| Poster | Thread | Wanderer
|  |
Re: What to look at if I want to do an texteditor Posted on 3-Feb-2012 16:22:30
| | [ #21 ] |
| |
 |
Cult Member  |
Joined: 16-Aug-2008 Posts: 511
From: Germany | | |
|
| @Trixie
Either I missed it, or the auhtor doesnt really mention the indexed-array variant, which I am using in NTuiTED. What is going on here is that you have an array of pointers. Each pointer points to a line of text. When you insert or delete a line, you only need to move the array of pointers, not the entire text. This is pretty fast, even if the text is a GB of size, and the overhead is pretty low. It is also very fast when you load the text to ram. You can load everything into one block (or several large blocks, if needed), and just set the pointers in the index array. Return code is then replaced by the 0-byte, or you write your visualization like this that you respect the return code. If a line is edited and gets larger, it gets its own memory buffer allocated from a memory pool.
Last edited by Wanderer on 03-Feb-2012 at 04:24 PM.
_________________ -- Author of HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more... Homepage: http://www.hd-rec.de |
| | Status: Offline |
| | tonyw
 |  |
Re: What to look at if I want to do an texteditor Posted on 3-Feb-2012 23:05:37
| | [ #22 ] |
| |
 |
Elite Member  |
Joined: 8-Mar-2003 Posts: 2777
From: Sydney (of course) | | |
|
| @Wanderer
A table of pointers is one way to do it, and the example used in most C reference texts. However, in an AmigaOS environment, a far neater method is to use an Exec List node for each row of text. It is just as quick to run through a List when redrawing a display as it is to run through a table. On the other hand, Insert/Delete (row) operations become trivial, since you don't have to change any pointers to other rows.
The entire text in the buffer can be stored in a single List with one Node per row. To display portion of the List, you only have to maintain a couple of pointers, one to the Node for the first row in the window, another to the last. Whenever the text is scrolled, you move the pointers one row at a time, using Prev() and Next() calls.
The difficult part is maintaining control of lines of text that span two or more rows. Whenever the window width or font size is changed, or the user inserts text into a row, you have to revisit the split of text between the affected rows. It doesn't matter whether you use a lookup table or a List, the problem is the same.
_________________ cheers tony
Hyperion Support Forum: http://forum.hyperion-entertainment.biz/index.php |
| | Status: Offline |
| | Wanderer
|  |
Re: What to look at if I want to do an texteditor Posted on 4-Feb-2012 11:54:52
| | [ #23 ] |
| |
 |
Cult Member  |
Joined: 16-Aug-2008 Posts: 511
From: Germany | | |
|
| @tonyw
Yes, a linked list would work too, but it has more overhead. when editing small text files, none of the methods is a problem. The problem begins when the text file is very large. Many texteditors are really slow here, e.g. if you load a 1GB text file. Building such a linked list simply costs more time than an array. The insert or delete costs are not that drastic in an array, remember that nowadays CPUs can move gigabytes of memory in a second, and insert delete operations are rare compared to typing characters.
Anyway, there are various methods that do the tick, of course.
_________________ -- Author of HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more... Homepage: http://www.hd-rec.de |
| | Status: Offline |
| | jonssonj
 |  |
Re: What to look at if I want to do an texteditor Posted on 6-Feb-2012 19:28:32
| | [ #24 ] |
| |
 |
Regular Member  |
Joined: 1-Mar-2004 Posts: 182
From: Sweden, Bjärred | | |
|
| @Trixie
Yes, I know that I must save the text in a "smart" way. Thanks for the link, I will definitly read it.
Thanks!
BR JJ
_________________ A1 X1000 is here !!! |
| | Status: Offline |
| | jonssonj
 |  |
Re: What to look at if I want to do an texteditor Posted on 6-Feb-2012 19:40:48
| | [ #25 ] |
| |
 |
Regular Member  |
Joined: 1-Mar-2004 Posts: 182
From: Sweden, Bjärred | | |
|
| @all
I have a little problem.
How do I get the char from the intuimsg->Code so I can display it with the Text() function?
I have this code:
switch (intuimsg->Class) {
...
case IDCMP_VANILLAKEY: Move(win->RPort, current.win_x, current.win_y printf("IDCMP_VANILLAKEY (%lc)\n", intuimsg->Code); // This works.
// Text(win->RPort, intuimsg->Code, strlen(intuimsg->Code) // The line above does of course not work, but I do not seem to be able to // find a simple example on how to convert the intuimsg->Code to a string?
Thanks for all your input, I'm really glad that this forum exists. BR JJ
...
}
_________________ A1 X1000 is here !!! |
| | Status: Offline |
| | Kronos
|  |
Re: What to look at if I want to do an texteditor Posted on 6-Feb-2012 20:10:48
| | [ #26 ] |
| |
 |
Super Member  |
Joined: 8-Mar-2003 Posts: 1708
From: Unknown | | |
|
| @jonssonj
Remember that function-calls involving tags (or taglists) should allways end with a TAG_DONE.
Otherwise you might be in for some suprises ....
_________________ - We don't need good ideas, we haven't run out on bad ones yet - blame Canada |
| | Status: Offline |
| | Wanderer
|  |
Re: What to look at if I want to do an texteditor Posted on 6-Feb-2012 20:14:39
| | [ #27 ] |
| |
 |
Cult Member  |
Joined: 16-Aug-2008 Posts: 511
From: Germany | | |
|
| @jonssonj
I would not lisen to the vanilla keys, because you will "loose" the raw keys, such as arrows, and also key up events.
Once you have a raw key, you must call the code below to convert it to the actual text string, mapped by the users locale.
[code] InputEvent ie; ie.ie_NextEvent = 0; ie.ie_Class = IECLASS_RAWKEY; ie.\ie_SubClass = 0; ie.ie_Code = msg->Code; ie.ie_Qualifier = msg->Qualifier; MapRawKey (&ie,temp_stringbuffer,maxbuffer,0); [/code] "msg" is your IDCMP message. The result is a string in temp_stringbuffer. Usually one character, but doesnt have to be.
_________________ -- Author of HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more... Homepage: http://www.hd-rec.de |
| | Status: Offline |
| | jonssonj
 |  |
Re: What to look at if I want to do an texteditor Posted on 6-Feb-2012 21:15:31
| | [ #28 ] |
| |
 |
Regular Member  |
Joined: 1-Mar-2004 Posts: 182
From: Sweden, Bjärred | | |
|
| @Wanderer
Hello and thanks for your help.
I program in winuae and in os3.9 right now and was just wondering if the code you provided is for os 3.x or for os4.x?
To me, a beginner :) it looks like os4.x code, but I might very well be wrong?
BR JJ
_________________ A1 X1000 is here !!! |
| | Status: Offline |
| | Kronos
|  |
Re: What to look at if I want to do an texteditor Posted on 6-Feb-2012 21:32:12
| | [ #29 ] |
| |
 |
Super Member  |
Joined: 8-Mar-2003 Posts: 1708
From: Unknown | | |
|
| @jonssonj
That code should work atleast on anything up from 2.0, maybe even 1.x.
Personally I still think that coding anything that is neither a pure shell command or a game without uitilizing a GUI-toolkit is a fools errand these days, but everyone to his own,,,,
_________________ - We don't need good ideas, we haven't run out on bad ones yet - blame Canada |
| | Status: Offline |
| | Wanderer
|  |
Re: What to look at if I want to do an texteditor Posted on 6-Feb-2012 21:43:07
| | [ #30 ] |
| |
 |
Cult Member  |
Joined: 16-Aug-2008 Posts: 511
From: Germany | | |
|
| @jonssonj
Yes, maybe tell us more about what you acutal plan is. Do you just want to play around and throw it to the trashcan when you are done? Do you have serious ambitions to create a usable texteditor, or a texteditor widget for a GUI Toolkit so other people can use it too?
_________________ -- Author of HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more... Homepage: http://www.hd-rec.de |
| | Status: Offline |
| | jonssonj
 |  |
Re: What to look at if I want to do an texteditor Posted on 6-Feb-2012 23:33:55
| | [ #31 ] |
| |
 |
Regular Member  |
Joined: 1-Mar-2004 Posts: 182
From: Sweden, Bjärred | | |
|
| @Wanderer
Hello!
This little project have several purposes. The first and most important is for me to learn how to program on the Amiga. For me it would be fantastic if this turns out to be usable by others, but that would only be a bonus effect right now.
When you say a GUI toolkit, what GUI toolkit do you mean? I have tried to use the reaction toolkit before, but it is really poorly documented so it's impossible for me as a beginner to learn and I'm not interested to do MUI GUI:s, then I rather do it the "hard" way.
The positive about the hard way is that it is very well documented and there is a lot of examples.
If you have other thoughts then you can very well try to convince me ohterwise :)
BR JJ
_________________ A1 X1000 is here !!! |
| | Status: Offline |
| | jonssonj
 |  |
Re: What to look at if I want to do an texteditor Posted on 15-Feb-2012 16:40:20
| | [ #32 ] |
| |
 |
Regular Member  |
Joined: 1-Mar-2004 Posts: 182
From: Sweden, Bjärred | | |
|
| @all
Hello all again!
I have looked in the rkrm manuals and searched for a way to distinguish between key down and key up but have not found how to do that.
Is there anyone here that can point me in the right direction. I have the following code
[code] case IDCMP_RAWKEY: //if( intuimsg->Code & 0x80) { ie.ie_NextEvent = 0; ie.ie_Class = IECLASS_RAWKEY; ie.ie_SubClass = 0; ie.ie_Code = intuimsg->Code; ie.ie_Qualifier = intuimsg->Qualifier; MapRawKey (&ie, temp_stringbuffer, maxbuffer, NULL);
//printf("temp_stringbuffer %s ", temp_stringbuffer);
Move(win->RPort, current.win_x, current.win_y); Text(win->RPort, (CONST_STRPTR) temp_stringbuffer, strlen(temp_stringbuffer)); current.win_x = current.win_x + 8; //}
//printf("IDCMP_VANILLAKEY (%lc)\n",intuimsg->Code); break;
This code generates two characters on each keypress, one for down and one for up. I saw some example that where using:
if( intuimsg->Code & 0x80) { // code here }
to test for keyup, I think (maybe it was keydown, i do not remember now), but that does not seem to work in my program.
Any help is really appreciated.
Thanks in advance!
_________________ A1 X1000 is here !!! |
| | Status: Offline |
| | Wanderer
|  |
Re: What to look at if I want to do an texteditor Posted on 15-Feb-2012 16:58:15
| | [ #33 ] |
| |
 |
Cult Member  |
Joined: 16-Aug-2008 Posts: 511
From: Germany | | |
|
| @jonssonj
You are doing it right. The actual name is "IECODE_UP_PREFIX", but it evaluates to 0x80. If the Code value has this bit set, it is an "Up" Event, if it is clear, it is "Down" event.
If this doesnt work for you, there must be something else wrong. _________________ -- Author of HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more... Homepage: http://www.hd-rec.de |
| | Status: Offline |
| | Birbo
|  |
Re: What to look at if I want to do an texteditor Posted on 15-Feb-2012 17:11:04
| | [ #34 ] |
| |
 |
Regular Member  |
Joined: 5-Apr-2007 Posts: 330
From: Zurich, Switzerland | | |
|
| Another option would be to write the editor in python like:
http://sourceforge.net/projects/pyword/
_________________ I want to die peacefully in sleep like my grandfather did, not screaming in terror like his passengers. |
| | Status: Offline |
| | broadblues
 |  |
Re: What to look at if I want to do an texteditor Posted on 15-Feb-2012 18:16:54
| | [ #35 ] |
| |
 |
Elite Member  |
Joined: 20-Jul-2004 Posts: 2398
From: Portsmouth England | | |
|
| | | Status: Offline |
| | jonssonj
 |  |
Re: What to look at if I want to do an texteditor Posted on 15-Feb-2012 19:49:27
| | [ #36 ] |
| |
 |
Regular Member  |
Joined: 1-Mar-2004 Posts: 182
From: Sweden, Bjärred | | |
|
| @broadblues
Hello!
No, I have removed the IDCMP_VANILLAKEY.
I found the error I did. I wrote like this:
if( intuimsg->Code & 0x80 == FALSE ) {
// Code here
}
But that did not work because probably the c-compiler processes the 0x80 == FALSE before it consider the & operand. So I changed my code to this:
if( ( intuimsg->Code & 0x80 ) == FALSE ) {
// Code here
}
and then it worked.
Now I have a new question. I was looking at the inputevent.h file and saw the iequalifier codes that you are supposed to be able to use. I tried to do this:
case IDCMP_RAWKEY: if( (intuimsg->Code & 0x80) == FALSE) { ie.ie_NextEvent = 0; ie.ie_Class = IECLASS_RAWKEY; ie.ie_SubClass = 0; ie.ie_Code = intuimsg->Code; ie.ie_Qualifier = intuimsg->Qualifier; MapRawKey (&ie, temp_stringbuffer, maxbuffer, NULL);
//printf("temp_stringbuffer %s ", temp_stringbuffer);
switch(ie.ie_Qualifier) { case IEQUALIFIERB_LSHIFT: printf("lshift"); break; case IEQUALIFIERB_RSHIFT: puts("rshift"); break; case IEQUALIFIERB_CAPSLOCK: puts("capslock"); break; default: Move(win->RPort, current.win_x, current.win_y); Text(win->RPort, (CONST_STRPTR) temp_stringbuffer, strlen(temp_stringbuffer)); current.win_x = current.win_x + 8; break; }
I tried both with IEQUALIFIER_xxx and IEQUALIFIERB_xxx and it does not seem to work. I have tried to print out a message with both puts("message"); and with printf("message"); as you can see in the code above. Is there anyone here that knows where I can read about catching the dead keys on the keyboard? and how do I catch the return key and the backspace key and the delete key and so on?
BR JJ
_________________ A1 X1000 is here !!! |
| | Status: Offline |
| | broadblues
 |  |
Re: What to look at if I want to do an texteditor Posted on 15-Feb-2012 21:09:54
| | [ #37 ] |
| |
 |
Elite Member  |
Joined: 20-Jul-2004 Posts: 2398
From: Portsmouth England | | |
|
| @jonssonj
Quote:
switch(ie.ie_Qualifier) { case IEQUALIFIERB_LSHIFT: printf("lshift"); break; case IEQUALIFIERB_RSHIFT: puts("rshift"); break; case IEQUALIFIERB_CAPSLOCK: puts("capslock"); break;
|
Two errors here:
1. Your are using the bit numbers. You need the Flags versions (without the B in the name) 2. The values are OR'd togther (there can be more than one qualifier ) so you must check like so:
if(ie.ie_Qualifier & IEQUALIFIER_LSHIFT) { printf("Shift\n") } if(ie.ie_Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_LALT)) { printf("Alt & Shift\n"); }
Edit: woops put in | when I meant &
Last edited by broadblues on 15-Feb-2012 at 09:11 PM.
_________________ BroadBlues On Blues BroadBlues On Amiga Walker Broad |
| | Status: Offline |
| | salass00
|  |
Re: What to look at if I want to do an texteditor Posted on 16-Feb-2012 7:46:41
| | [ #38 ] |
| |
 |
Elite Member  |
Joined: 31-Oct-2003 Posts: 2438
From: Finland | | |
|
| @jonssonj
Quote:
if(ie.ie_Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_LALT)) { printf("Alt & Shift\n"); }
|
Note that the printf() statement here will run if left shift and/or left alt are pressed. If it's meant that it should run only if both left shift and left alt are held down some additional code will be needed.
if((ie.ie_Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_LALT)) == (IEQUALIFIER_LSHIFT | IEQUALIFIER_LALT)) { printf("Alt & Shift\n"); }Last edited by salass00 on 16-Feb-2012 at 07:48 AM.
_________________ µA1-C - 750FX 800MHz, 512MB, 20GB HD, DVD-RW, OS4.1 Sam440ep - 440EP 667MHz, 512MB, 700GB HD, DVD-RW, OS4.1 |
| | Status: Offline |
| | jonssonj
 |  |
Re: What to look at if I want to do an texteditor Posted on 16-Feb-2012 13:15:23
| | [ #39 ] |
| |
 |
Regular Member  |
Joined: 1-Mar-2004 Posts: 182
From: Sweden, Bjärred | | |
|
| @all
Ok, I can't get this codesnippet to work. I get a keyup and a keydown as I should, but I do not get the LSHIFT message that I should get.
The codesnippet looks like this:
============================================================ case IDCMP_RAWKEY: if( (intuimsg->Code & IECODE_UP_PREFIX) == IECODE_UP_PREFIX ) { ievent->ie_NextEvent = 0; ievent->ie_Class = IECLASS_RAWKEY; ievent->ie_SubClass = 0; ievent->ie_Code = intuimsg->Code; ievent->ie_Qualifier = intuimsg->Qualifier; numchars = MapRawKey (ievent, temp_stringbuffer, maxbuffer, NULL); } if( (ievent->ie_Qualifier & IEQUALIFIER_LSHIFT) == IEQUALIFIER_LSHIFT ) { puts("lshift\n");
}
puts("Keyup\n"); } else { puts("Keydown\n"); }
break; ===================================================================
I can't find any errors in the code. Maybe I'm blind or something... :)
One more thing, I have noticed that MapRawKey() returns zero when I press shift or alt or amiga keys. Is it supposed to return 0 when I press these keys?
Any advice greatly appreciated.
BR JJ
Last edited by jonssonj on 16-Feb-2012 at 01:19 PM. Last edited by jonssonj on 16-Feb-2012 at 01:16 PM.
_________________ A1 X1000 is here !!! |
| | Status: Offline |
| | Wanderer
|  |
Re: What to look at if I want to do an texteditor Posted on 16-Feb-2012 13:33:39
| | [ #40 ] |
| |
 |
Cult Member  |
Joined: 16-Aug-2008 Posts: 511
From: Germany | | |
|
| @jonssonj
Yes, MapRawKey returns zero because those keys produce the empty string as output. (means no output) Go to a texteditor and press the SHIFT key. What happens? nothing, no text inserted, correct.
_________________ -- Author of HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more... Homepage: http://www.hd-rec.de |
| | Status: Offline |
| |
|
|
|
[ home ][ about us ]
[ forums ][ classifieds ]
[ links ][ news archive ]
[ link to us ][ user account ]
|