Code Editor GUI Component.

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Code Editor GUI Component.

Post by hybrid »

If you want to join irrExt for maintaining the package please contact me by mail first. Otherwise please provide the full sources together with all needed media files and an example usage with a full main.cpp. Some downloadhoster will be enough, as I'll just copy the files once.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Code Editor GUI Component.

Post by christianclavet »

Wow! Nice work Lonesome Ducky! I'm working on an better example/gui demo with the code editor and the new syntax highlighting you implemented is really impressive!

I'm adding new option to change the elements colors, and not be stuck with the predefined or base skin colors, cleaning up a little and fixing little problems.

You added a new contextual menu, but strangely, it seem to lose it pointer after each call to the event. Is there a place where you remove the pointer? (I want to keep it so we can change the labels for the contextual menu, in English it's still good, but I would like it to have the possibility to be multilingual).

Just found out that the text wordwrap need some tune up... Text goes under the scrollbar instead of breaking before reaching it. (I'm sure this was present before you even started working on this). Found the problem in the breaktext() method and it's fixed now.

I will try to make it as nice as possible, then will propose it to IrrExt...
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Re: Code Editor GUI Component.

Post by Lonesome Ducky »

I was going to try and make the syntax highlighting faster by only checking for keywords when the text is modified, but another project took my time. As for the context menu, I dunno exactly. But the context menu only exists after right click, and then the pointer points to nothing once something is chosen or the user clicked something else since the context menu is gone. If you want to make it multilingual, you can find where it adds the choices in proccessMouse. Sounds like your changes will make it look and work more professionally, I'll bet it'll get into irrExt.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Code Editor GUI Component.

Post by christianclavet »

Thanks!

Done some fixes and polished a little the class. My example can switch the interface from english to french to show that you can customize the text in the component. Colors are also all customizable in the line count display. Put some "enums" for the contextual menu, so it's easy to figure out. Fixed the problem with the line breaking at the wrong place (also recalculate the line break when you hide/show the linecount). I kept the way you create/delete pointer for the contextual menu, texts are simply created from an string array (array size is referenced from the last enum), So i think if we add more stuff to the editor it will be easy to still support multilingual and still be easy to expand. Just add one an enum and the array size increase with it.

The current example show most of the types of highlighting works as in theses 2 pics:
The main menu displayed here is separate from the interface, but we can do copy/paste/undo operations since you implemented the commands. I show in the example code how to access them from outside the GUI component. We can switch "live" the interface language from english to french. (Would be really easy to add other languages (lating based))

This screen show the example with the english interface and give examples of highlighting:
Image

This screen show the example with the french interface, notice that we can also change the submenu language of the editor
Image

If you look at the group example, there is a little problem.. Nothing major... I will have to investigate your portion of code. I defined 2 groups:
Group 1: start text: "(", end text: ")"
Group 2: start text: "Feature(", end text: ")"

Since the 2 groups have the same ending text and the second goes into line break, it pick the first occurance of the group, the group1 highlight is picked when it should be group2.
If the text stay on the same line, it's ok and the highlighing works.

I will write the documentation tomorrow for all the new stuff that we added to it. And will be in position to propose it. The archive will be hosted from my web site for a while.
EDIT (2011/08/26): Updated the screenshots and made the archive available for download
http://www.clavet.org/files/download/code_editor.zip 3.39Mb
Last edited by christianclavet on Fri Aug 26, 2011 1:47 pm, edited 1 time in total.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Re: Code Editor GUI Component.

Post by Lonesome Ducky »

I'll try looking into that problem too. There's also another problem I've found where a group is not highlighted because the line it starts on is offscreen, that group beginning is never checked or found. A way of solving this (albeit not quickly) is to look for group start keywords in all lines, but only draw those on screen. Also, I think it would be nice to add an option to change the background color, if there isn't one already
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Code Editor GUI Component.

Post by christianclavet »

Hi, Yes, you can almost change all the colors inside this GUI element. I havent fixed yet the group hightlight when it reach a linebreak.

Hybrid gave me access to the SVN and now the code editor is also safe there.

I'm thinking of other stuff we might add to it later:
- Improve the serialisation as it seem important for a lot of users including CuteAlien (Need to learn how it's done before goofing there :D )
- Check how I can make the horizontal scrollbar work. (Horizontal scrolling can still work, but you need to scroll with the directional keys on the keyboard)
- Add a search & replace method (this could be called from another GUI from outside the class)
- Would be fun to have "code hinting" as we have in MSVC/CodeBlock (limit it to the current keywords)
- Once 1.8 is out, implement the TAB key capture so it's doesnt change the focus. (Cannot be done with 1.7.2)
netpipe
Posts: 669
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: Code Editor GUI Component.

Post by netpipe »

main.cpp|274|error: cannot allocate an object of abstract type ‘irr::gui::CGUIEditBoxIRB’|
CGUICodeEditor.h|53|note: because the following virtual functions are pure within ‘irr::gui::CGUIEditBoxIRB’:|
IGUIEditBox.h|33|note: virtual irr::gui::IGUIFont* irr::gui::IGUIEditBox::getOverrideFont() const|
IGUIEditBox.h|38|note: virtual irr::gui::IGUIFont* irr::gui::IGUIEditBox::getActiveFont() const|
IGUIEditBox.h|51|note: virtual const irr::video::SColor& irr::gui::IGUIEditBox::getOverrideColor() const|
IGUIEditBox.h|61|note: virtual bool irr::gui::IGUIEditBox::isOverrideColorEnabled() const|
IGUIEditBox.h|64|note: virtual void irr::gui::IGUIEditBox::setDrawBackground(bool)|
||=== Build finished: 7 errors, 0 warnings ===|
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Code Editor GUI Component.

Post by christianclavet »

It build perfectly on MSVC... You tried to compile it on what? (Can you tell me what compiler/platform you're on?)

Strange from the report here, it get stuck because it seem to search for declarations of virtual functions that are not there (getOverrideFont, getActiveFont(), getOverrideColor(), isOverrideColorEnabled(), setDrawBackground). If you check the source, theses functions are not implemented and its assumed they would take the ones from the inherited class.

I did not override theses functions and it compile fine. With a little googling around for this, found out that your compiler (I don't know what) has found theses function to be PURE VIRTUAL. And from the info gathered a PURE VIRTUAL function MUST be implemented. Before I go there and implement all of those, I need to know what you attempted, and on what compiler/platform to understand why it has found thoses functions as PURE VIRTUAL, as MSVC do not.
netpipe
Posts: 669
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: Code Editor GUI Component.

Post by netpipe »

linux with gcc yeild that build log. thanks for the fast response
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Code Editor GUI Component.

Post by christianclavet »

Ok. Checked more the details about this. Look like a metamorphism problem that is occurring with your compiler. The class has and use all the same overridden functions names as CGUIEditBox.h, and after checking the function names that were mentioned, checked for them in the CGUIEditBox.h implementation and they are not present, so they seem to be implemented in its parent class (IGUIElement) it inherit.

For some reason, your compiler is not able to determine the proper class metamorphism and since it doesn't find the implementation (look to me it doesn't understand that the function implementation is in IGUIelement class). A quick "hack" would be to create those functions in the editor class itself. Since I'm only starting to get around in C++, I can't find a "right" solution for this at the moment. If someone with more experience would propose something.... (The MSVC compiler doesn't find any problem to compile)

Anyway, thank for reporting this. Before today, I never heard of "PURE VIRTUAL" functions... So I learned something new.
tbw
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: Code Editor GUI Component.

Post by tbw »

Really cool stuff! :o
netpipe
Posts: 669
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: Code Editor GUI Component.

Post by netpipe »

is the pure virtual bug fixed yet ?
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Code Editor GUI Component.

Post by christianclavet »

Not yet. I will have to create a project inside codeblock. Don't have the time right now. Someone working with codeblock have the time to check this?
netpipe
Posts: 669
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: Code Editor GUI Component.

Post by netpipe »

its sooo cool and i cant seem to fix it... :(

here's source with C::B prj file

http://www.xup.to/dl,15944796/code_editor.tar/ cb file is inside the src dir
Last edited by netpipe on Thu Nov 06, 2014 12:57 pm, edited 1 time in total.
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Code Editor GUI Component.

Post by christianclavet »

Can you get IRR RPG builder and check the codeblock project? (Andres is doing the Linux port) Since this code editor is a component of the project, perhaps you could check the project and see what in it make it work on Linux...
Post Reply