Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Developing a code edit box with sfml  (Read 5480 times)

0 Members and 1 Guest are viewing this topic.

erklest22

  • Newbie
  • *
  • Posts: 3
    • View Profile
Developing a code edit box with sfml
« on: August 27, 2014, 11:59:38 am »
I would like to create a new custom code edit box control for a cross-platform editor but I'm currently evaluating some frameworks like SDL, Cairo and SFML.

Is it possible to implement a text edit box control (with code syntax highlighting and smooth scrolling) in SFML? Does SFML provide hw acceleration only when using openGL?

Any thought is welcome  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Developing a code edit box with sfml
« Reply #1 on: August 27, 2014, 12:02:02 pm »
Quote
Is it possible to implement a text edit box control (with code syntax highlighting and smooth scrolling) in SFML?
It is always possible to implement xxx with yyy. If you want more details, you'll have to ask more precise questions.

Quote
Does SFML provide hw acceleration only when using openGL?
SFML (for its graphics part) is entirely based on OpenGL. So you always have hardware acceleration, even if you don't use OpenGL directly.

But to me, it seems strange to write such a thing with a 2D library. It would be much easier with a GUI toolkit (Qt, GTK, wxWidgets, ...). Isn't the editor based on such a framework?
Laurent Gomila - SFML developer

erklest22

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Developing a code edit box with sfml
« Reply #2 on: August 27, 2014, 01:10:21 pm »
Thanks for the answer. The control I'm looking for strives for flexibility and might have features similar to sublime text's one (i.e. multiple carets, drawings here and there, etc...) so implementing all those features as hacks for existing controls sounds like suicide to me (maybe I'm wrong though). I thought of Cairo in the first place since GTK+ (newer versions) uses it, but it seems porting to win32 isn't that great and I would have to rewrite the controls in something that works on Windows.

I'm a newbie in this field though and I might be getting something wrong.

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: Developing a code edit box with sfml
« Reply #3 on: August 27, 2014, 09:05:05 pm »
Thanks for the answer. The control I'm looking for strives for flexibility and might have features similar to sublime text's one (i.e. multiple carets, drawings here and there, etc...) so implementing all those features as hacks for existing controls sounds like suicide to me (maybe I'm wrong though). I thought of Cairo in the first place since GTK+ (newer versions) uses it, but it seems porting to win32 isn't that great and I would have to rewrite the controls in something that works on Windows.

I'm a newbie in this field though and I might be getting something wrong.

Well as Laurent suggested, definitely sounds like a job for GTK to me. Actually developing a fully working flexible GUI (like in Sublime text) with SFML sounds like suicide to me. Thankfully we have Gwen, TGui and SFGui so if you really want to take the SFML road take a look at those. I don't really understand what you mean with porting to Windows. Gimp is built on GTK and works great on Windows?

Believe me, building a decent Gui with 2d library is pain in the ass. That's why they usually tend to be projects on their own, like the ones I mentioned.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Developing a code edit box with sfml
« Reply #4 on: August 27, 2014, 09:15:28 pm »
I'd do this with Qt. Not SFML - not a chance.

erklest22

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Developing a code edit box with sfml
« Reply #5 on: August 27, 2014, 11:28:23 pm »
Thanks everyone for your help!

I took a look at SFGUI and I'm wondering if it's worth the hassle in my case: I should provide two or three custom controls in my window (and I would like to draw them all from scratch). Since I don't need any buttons, combo boxes or any other control provided by SFGUI I'm wondering if I should use SFGUI in order to mock the "widget" containers it has.

What I mean is: drawing two or three custom controls in a SFML window feels like issuing all the drawing commands in the rendering loop for ALL the controls (no modularity at all, probably also slower since everything gets invalidated each time and all the commands need to be re-issued). Does SFGUI handle selective redrawing only for a widget that needs it?

I know I'm being particular (and also noob) but I'm just trying to learn and find what could work for me.

My new guess is that I might need this sort of "widget distinction" provided by SFGUI and create a widget that works for me (basically handling all events and doing all the drawing I need into a method returning a RenderingQueue like BREW::CreateMyCustomControlDrawable)

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Developing a code edit box with sfml
« Reply #6 on: August 28, 2014, 05:42:51 am »
SFGUI will always try its best to squeeze the most performance out of even the most horrible code ::).

But... as the others have already mentioned, why even bother with putting the controls inside the SFML window in the first place?

Widget toolkits like Qt, wxWidgets and GTK are at least as portable as SFML, and are highly optimized and tailored for use cases like yours. It isn't that hard to embed an SFML drawing surface inside a control and draw to that instead. That way, you use SFML for what it is meant for: rendering. The rest of the complex UI that you will probably end up with in your editor will happily be taken care of by the widget toolkit.

There is currently no up-to-date tutorial on embedding SFML into other windows or controls, but if you resort to the example code, the API documentation and even the older (1.6) tutorials, you should be able to figure it out without too much effort. If you have questions, you can always ask them here.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).