Creating custom controls guide?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

HexDump
Just popping in
Just popping in
Posts: 19
Joined: Fri Mar 07, 2008 11:49

Creating custom controls guide?

Postby HexDump » Mon Mar 10, 2008 11:32

Hi all,

I´m trying to build a mesh browser in ogre. I just need for this a window, a scrollbox (I just want one row) and some static images that will be generated dynamically depending on the width of the window.

I have been checking the docs, etc... and can´t find any tutorial about creating a custom control. I would like to create this as a custom control and make the control update the static images authomatically every 1/30 seconds to not eat too much cpu. This way I could add it to a Window, and athomatically should work without more intervention.

Could anybody give any tip about this?

Thanks in advance,
HexDump.

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Mon Mar 10, 2008 13:20

If I understand correctly, you want a row of images and a horizontal scrollbar to navigate through the images. In addition you also want these images to be dynamic, to possibly render these as 3D objects from Ogre. Well, you're in luck: CEGUI dialog which displays rotating 3D meshes on multiple buttons does all of this.

What would remain to code would be to react to FrameWindow "resize" events such that when it is sufficiently stretched a new image is displayed but if shrunk an image is removed. To help you accomplish this I will say to use absolute position values for the StaticImage (0,50 to 20,20) rather than relative positions (0.0f, 0.8f to 0.15f, 0.95f). Then it becomes a simple matter of retrieving the new FrameWindow's width and determining whether you can add a new StaticImage or need to remove one.

Hope this helps.

HexDump
Just popping in
Just popping in
Posts: 19
Joined: Fri Mar 07, 2008 11:49

Postby HexDump » Mon Mar 10, 2008 13:41

Thanks Rackle for the link, you exactly understood what I need.

I read this code before posting here. The problem with this code is that it is not the way I would like to do this. I mean, I would like to create a new control (A frame window, withh all the widgets I said before) representing something like the one you told me. But I want it to be updated authomatically by CEGUI, etc... I mean, more ore less the way you define a custom control in c#, delphi, etc...

Don´t know if I expressed myself cleartly, an example:

CMeshBrowser : public FrameWindow
{

//Here I would add all controls I need to create the mesh browser.
//I will link events, etc... and overload the method that will be called
//by CEGUI. In this method I will check if it is time to update static images //and I will do this when needed.

}

I would like to take this way of doing things. Is there any problem? Am I a bit offuscated?. This is the way I ussually work with Controls/Widgets/ELements or whatever you call them.

P.D. Well I finally found something: http://www.cegui.org.uk/wiki/index.php/ ... istboxItem

This seems to have the basis to create custom controls. Now I´m having a problem that seems impossible to fix, I get an "inconsisten dll linkage error" in the line "const CEGUI::String EntityBrowser::WidgetTypeName("CEGUI/EntityBrowser");" do anybody know what's happening?.

The full error log is:

1>'WidgetTypeName' : inconsistent dll linkage.
2>ceguiframewindow.h(55) : see previous definition of 'public: static CEGUI::String const CEGUI::FrameWindow::WidgetTypeName'
3>entitybrowser.cpp(9) : error C2491: 'CEGUI::FrameWindow::WidgetTypeName' : definition of dllimport static data member not allowed


Thanks in advance,
HexDump.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Mon Mar 10, 2008 19:09

Hi,

your suggestion of subclassing a Cegui class in your own code is an interesting one. I have never thought of this myself, although i have experience with MFC and wxWidgets :)

Anyway, you should consider Cegui widget classes as 'final', so to speak. So using Cegui widgets mostly works in a 'has a' relation, rather then an 'is a'.

That means that you can write your own class, which has (pointers to) instances of actual Cegui widget instances.

It really depends on your needs. To a certain extent, you can modify an existing looknfeel. For example modify a checkbox by removing the label and turn it into a switch, like an elevator button, while keeping the same internal classes and renderers (the mappings you see in the .scheme files).

An alternative for this is grouping native Cegui class at a higher level, as i suggested earlier. For example you could have a class which manages a button, a label and an input box, and have them act as one autonomous high-level widget.

A 'last' option would be what the CheckboxListitem does: create both a looknfeel and a new native Cegui class. At this level you should be able to subclass an existing Cegui class, but in Cegui itself(!). This -as you can see- requires you to modify Cegui itself and rebuild it. The previous two options can also be used when you use the pre-build Sdk or an existing binding.

About your compile error: IIRC you are declaring a class with a dll export, but the compiler setting uses another (of none at all) setting.

For example:

Code: Select all

class MyDllExport Foo {
}


Then Project Settings->C/C++->Preprocessor should also list 'MyDllExport'.

HTH.
Check out my released snake game using Cegui!

HexDump
Just popping in
Just popping in
Posts: 19
Joined: Fri Mar 07, 2008 11:49

Postby HexDump » Mon Mar 10, 2008 21:00

Thanks for the answer scriptkid.

Well, I will go back to the agregation way, because it seems pretty hard to make this run, and I don´t feel like touching cegui code right now.

This was my first aproach but it is more sensible to me to do it the way I exposed before.


Thanks in advance,
HexDump.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 25 guests