Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Work in Progress / Syntex

Author
Message
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 11th Jan 2009 17:13 Edited at: 11th Jan 2009 17:21
As part of my pretty large scale scene / level editor project, I figured it would look nice as well as ease the writing process to have the engine scripts syntax highlighted.
This did not seem all that easy to do though, mainly due to DBP's speed issues. Therefore, I've spent quite some time trying to wrap Scintilla as well as other highlighting freebies into a plugin form usable by DBP. Unfortunately, that just kept on failing with every single library due to .NET issues.

Anyhow, after experimenting with bleGui's canvas gadgets for a while, I realized that they might just have the speed that was neccessary for something like this (needless to say, the RichEdits do not).
And now, after some rather bothersome work, I have a pretty well working (although not with complete functionality as of yet) totally homemade 2D syntax highlighter control written in DBPro (! - I've seen a few posts saying how that was probably impossible ).


The complementary screenshot

You can download a demo application here - try it out and tell me what you think; suggestions, flaws, etc. Also, I have a pretty powerful processor, so I'm rather interrested in hearing whether it runs at a decent framerate for others.

Current features
Type any (I think?) ASCII character into the control.
Completely customisable syntax highlighting (three demo language files are included; DBPro, C++ and the syntax highlighting keyword registration script).
Highlights language constants (scopes, variable types, etc.), keywords (conditional statements, loops, etc.), functions (everything else), comments (lines and blocks), numerics (integer, decimal, binary and hexadecimal notation are supported) and strings (as marked by double quotes; 'c' or <string> are not highlighted). The font and colour of each one of these can be changed at will through the properties dialog.
Pressing the backspace key will delete the previous character.
Using the left and right arrowkeys you can move the cursor to the next / previous column. Moving past the end / beginning of a line will wrap around to the previous / next line.
A (row, column) can also be directly moved to by clicking the corresponding slot.
The scrollbars can be used to change the starting positions of the displaying area (only the visible part is handled each loop).

Notes
This was written to be used as a script editor within another project of mine. It is not supposed to be a DBPro editor - hence very few keywords from the DBPro language is included in the corresponding language file; it is just there for demonstrative purposes. You can always open the .sl files and add in your own keywords though, but bear in mind that for every newly added word, there is another one to check against each loop. Perhaps having hundreds of keywords would drop the loop frequency; I haven't tested that. Also, there is currently a maximum of 1024 keywords that can be registered from a single language file.
Speaking of which, the character data is stored as a two dimensional array, consisting of 10000 rows with 1024 columns each. Exceeding this will cause an "Array index out of bounds" error; I will fix that later tonight though.

Seeing as how the highlighter control is entirely written by me, you will find it lacking of much of the standard windows induced functionality, such as marking text, copy and paste, scrolling the view area with the mouse wheel, etc. I'm planning to try to implement such things though.

Well, there then - happy for some c/c


-> Oh, come on...
chunks chunks
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: ackworth uk
Posted: 11th Jan 2009 17:36 Edited at: 11th Jan 2009 17:44
looks cool can`t wait to see the editor will have a test for you ,good work as always .

You done any music apps or anything lately ,the soft synth you did was cool .


EDIT: Just tried it ,very cool ,would like to see middle mouse button scrolling , it`s a little quirky when using the backspace it somtimes adds an extra letter , other than that superb .

I get fps between 100 & 300 which is ample for this kind of app.

chunks

nvidia geforce 8600gt + amd athlon 64
windows xp pro.
bergice
17
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 11th Jan 2009 19:21
Nice work!

3.19GHz - 7600GT - 1GB - Windows XP
Visit my youtube profile: http://www.youtube.com/user/bergice1
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 12th Jan 2009 04:56
Good stuff and runs pretty well. 80->100fps while highlighting. A bit of CPU hog though. So might need to decouple rendering from the update loop and only refresh the panel when a change event occurs (key press, scroll etc). Been writing a similar control myself recently (For PlayBasic IDE ). Anyway, had a quick go and noticed the following tidbits,

* Keyword matching appears to be case sensitive.




* Sometime when I click the vertical scroll bar to page up, the highlighting disappears. It also occurs in the attached sample.

The only other thing that comes to mind could be dealing with spaces/tabs between Dbpro's multi word keywords.

Attachments

Login to view attachments
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 13th Jan 2009 12:47
Thanks for the comments
I've been working a bit further on it and it now has the additional features of holding down a key (arrowkeys or backspace) for continuos movement / deletion.
Also, when deleting a whole line, the ones below will jump up one row. I'm currently baffling with trying to get it to insert a new line when pressing the return key (and, if present, move the text after the current column down to the new line); when I get my head around this I will upload a new demo.

The mouse wheel can now control the vertical scrollbar as well, but it currently achieves this through the DBPro function mouseMoveZ. It don't so happen that anybody would know how to get this information directly from Windows instead? I tried the WM_MOUSEWHEEL event type (0x20a), but it doesn't work

@Chunks: I think that the extra letter at deletion has been dealt with by the new erasure method
About the music apps, no, not for a while... maybe should have a go at something again

@Kevin: Yes, it is case sensitive. I had no intention of making it otherwise (the script language this is intended for is case sensitive); also, the contents is stored as an array of ascii character codes instead of actual strings, which is faster to process. It would thus be rather bothersome to implement case insensitiveness only for the keywords (naturally, variable names, strings, comments etc. shouldn't be).

About the highlighting dissappearing; it only checks the visible area. Assuming that you have a block comment beginning outside of the visible rows, it will hence not be highlighted (I intend to fix that later on though). The same goes for horizontally scrolling past the beginning of a line statement.
However, I have also noticed that it happens for no particular reasons sometimes when the syntax is indeed visible. I have yet to pinpoint why this happens; it might have something to do with each line beginning with a null character. Scrolling down a bit and then go back up will re-highlight the text though. Mystifying...

Finally, having more than one space in the multi word keywords is no high priority - again, I refer to my event script, which only use single word keywords


Hope to be back with a more functional demo soon


-> Oh, come on...
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 14th Jan 2009 13:21 Edited at: 14th Jan 2009 13:24
Update
Some more proper functionality has been added to the textbox aspects of the control:

The up and down arrowkeys can now be used to move between rows. The active column will remain the same unless the next line has less columns than the current one, in which case it will be set to the last one available. (Just like a standard Windows editbox in other words).

Pressing and holding the arrowkeys or the backspace key will now wait for a set amount of time and then start moving the cursor / erasing characters every 25 milliseconds for as long as the key is held down (again a emulation of other text editing controls).

Writing at a place where there is already characters will now shuffle them forwards instead of overwriting them.

Delete characters or insert new lines anywhere; the pre-existing text will be moved accordingly.
This also fixes the disappearing characters issue as far as I can see.

The vertical scrollbar will have a maximum position such that the last row is visible at the bottom of the control (not at the top as it previously were).
I still have to make the scrollbar thumb larger though.

Scroll through the text using the mouse wheel. (For me, it reacts the same on both my wheels).

Proper error messages and abortion if exceeding the capability of the character array.

The control is only redrawn whenever it is updated; when nothing is happening, the program sleeps. This decreases the CPU load (around 3% useage for me when in idle state; ~8% when written to).

The update frequency is about twice as high when viewing an occupied area (ie. the whole visible area is full with text).

You can download this new demo version from the same link as before (see my first post).


-> Oh, come on...
Kohaku
20
Years of Service
User Offline
Joined: 3rd May 2004
Location: The not very United Kingdom
Posted: 14th Jan 2009 14:57 Edited at: 14th Jan 2009 14:59
Very nice!

I added some syntax highlighting to my AGE engine (below) which uses a RichEdit. It's only basic and yes, it is very slow.

Yours looks way better already. Keep it up!


You are not alone.

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 14th Jan 2009 21:53
Thanks
Your AGE project looks pretty nice.
This is intended for use with an editor as well; I find it makes the script writing quite a bit friendlier.


-> Oh, come on...
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Jan 2009 01:40
Quote: " I'm currently baffling with trying to get it to insert a new line when pressing the return key"


Assuming your text is stored in an array line by line, you could just use "array insert at element".

A few suggestions on your highlighter engine. A binary search could drastically speed up the keyword matching. Think of a search bar that displays results in realtime as you're typing your search word. The more you type, the more specific the possible results become, thus less to loop through. I'm currently trying to implement that myself, possibly by using a filtered keyword list created from the original keyword list. A little extra memory used is a fair trade off for the speed I'm expecting to gain from it (remains to be seen).
Also, you might already be doing this, but only checking syntax for lines that have been altered.

Have you managed to highlight strings yet?

Your signature has been erased by a mod because it's larger than 600x120
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 24th Jan 2009 14:26
I'm using a 10000 rows by 1024 columns byte array for storing the characters one by one currently (once everything is up and working I guess I'll have to try to make it allocate new lines as it needs them, but this works fine for testing purposes - eats a bit inneccessary much memory though). I have made a shuffling function since I wrote that however, so that issue is fixed

Now my problem is trying to mark text by holding the left mouse button and dragging the cursor over the lines... doesn't work too well; perhaps you have some suggestions?

Binary search might not be a bad idea; haven't even thought of it myself *going off to write a sorting method for the keyword array*.

About string highlighting yes, there is actually one in the image in my first post. Here's another pic showing them:

It took some efforts to get working; I'm using states to tell the drawing function about continous font/colour overrides to draw (used for strings, which begin at a double quote and remain until the next one is found, and also for multiline comments between a COMMENT_START keyword and the following COMMENT_END).

Well, thanks for your input and hope your project comes along well too. Those states I spoke about are really useful, so you might want to take that approach too

"We know some things about poodles, for example that they are alive, they can bark, they eat meat..."
- Extract from Objects first with Java.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Jan 2009 00:11
I did text selection before in a text editor dbp challenge. Get the cursor's position at the time of the mouse click as the selection starting point and end it with the mouse's current position as it moves. Any text drawn between those markers should be selected.

Your signature has been erased by a mod because it's larger than 600x120
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th Jan 2009 12:28
finally had a chance to test your program. (i only get online from an iphone or a mac, so i cant tryout on the spot) Mouse scroll works opposite of expected. Have you figured out why the highlighting turns off and on with scrolling? And when typing a string, "cls" would only flicker highlighted when pressing a key, and that keyword was 3-4 lines above the string I was typing. When highlighting does show correctly it is highlighting words accurately.

Your signature has been erased by a mod because it's larger than 600x120
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 28th Jan 2009 22:04
Quote: "Get the cursor's position at the time of the mouse click as the selection starting point and end it with the mouse's current position as it moves."
Yes, that's exactly what I was trying to do. The simple code aside, it gives some strange results for me though. But then, I might not have been properly awake whilst writing that; I shall try to rewrite it whenever I get the time (I've been really swamped the last days ).

Ah, thanks for trying it out
About the scrollbar; you're right - haven't even thought of that. Well, that's easily fixed.
And no, I can't figure out why on earth it refuses to highlight at certain points. I'm pondering whether it could have something to do with the KEYWORD_COMMENT_END keys, but it doesn't seem so. Can't think of anything else causing it though; very odd...
About flickering strings; it did do that at times before. I haven't had that issue in a while though, so I assumed it was fixed... Can you explain when it happens?

I haven't had time to work on this for a while, but I hope to be able to get back onto it before I forget too much. Again, thanks for trying it and pointing this out

"We know some things about poodles, for example that they are alive, they can bark, they eat meat..."
- Extract from Objects first with Java.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Jan 2009 19:46
I downloaded it about a week before trying it out, so I may have had an old version. I'm finally at a point to make a post about my work on my own highlighter.

Your signature has been erased by a mod because it's larger than 600x120

Login to post a reply

Server time is: 2024-11-24 09:08:33
Your offset time is: 2024-11-24 09:08:33