PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

My GUI framework (based on gd201b)

Hi there,

This is my GUI framework based on gd201b.
The XPE was inspired by Borland's Delphi and C++Builder.
I wanted a generic C++ GUI framework to build app's easily and quickly.

I promise that I'll upload examples for this framework as soon as possible.

You can download this framework with full source code following link.

http://www.icecookie.net/zeroboard/data ... rj/XPE.zip

ps. There is no documents. Sorry. ^^
Hams · 17 Jul 2003, 15:24 UTC — My GUI framework (based on gd201b)
Omok (Renju) and Gostop (Korean card game) was development with this framework.

For more information of this games, see the game list.

you can see the list of all games created with GD following link.

http://www.gapidraw.com/main-gamelist.asp
I've been working on my own GUI framework for GapiDraw as well. I'll be interested to take a look at your GUI when I get home. What license is this released under? LGPL?
Jae-Pil Jung · 18 Jul 2003, 03:12 UTC — Yes, license is under LGPL.
Thomas wrote:
I've been working on my own GUI framework for GapiDraw as well. I'll be interested to take a look at your GUI when I get home. What license is this released under? LGPL?


Hi,
(I am Hams. I registered to PocketMatrix today. ^^)

The license is under LGPL.

Thank you. ^^
Pejo Software - Per · 18 Jul 2003, 09:02 UTC
This looks really great!
I just had a short look at it though. I also had some plans for making a generic framwork to use with our upcoming games but now I really must consider if I should use this instead.

There are generally a few things one should think on when making these kind of frameworks:
-Is it flexible and extendible enough.
-Does it hurt performance or consume to much memory.
-Portability, A framework that lets application run on different platforms without changing to much would be great.
-Complexity. Is it easy to use, understand and maintain.

I just had a quick look at your framwork and by that I can not evalute how well it meets the above criterias but it sure looked elegant.

I have a question though, How have you incorporated stl in your WCE builds. I am using StlPort in my WCE programs but then I must use the stlport namespace instead of std (maybe this has changed in newer versions, I am still using an old one).
I guess it's been changed, coz I'm also using stlport and std is the name of the namespace.
Pejo Software - Per · 18 Jul 2003, 11:19 UTC
Yes you are right! It seemst to work with v4.0 that I am using. Maybe it was version 3.2 that required the stlport namespace.
Btw, I'm also working on a GUI framework. :) It seems that lots of guys miss it. Has anyone thought about starting an open source project to develop such a thing so that anyone could contribute to it?
Sparkie wrote:Has anyone thought about starting an open source project to develop such a thing so that anyone could contribute to it?

I've thought about it in the past. My GUI framework just isn't generic enough for other people to use.
I thought about doing a commercial one, but don't really have the time now to devote to it. I created a really nice component library for DirectX a few years ago that had a scripting interface so an artist could easily lay out the GUI without knowing any programming.
Pejo Software - Per · 19 Jul 2003, 12:37 UTC
I also did a framework a couple of years ago that used a "skinning" concept with xml files. I was thinking of reuse some of those ideas when making a framework for GD. For example I used a concept of state variables that could be used by the skin implementation in order to catch the dynamic behaviour of the application. The problems I had was that the xml file could get quite big, the price for being flexible.
But if there is a GUI framwork out there that simplifies GUI development enough without sacrificing too much freedom and performance, I will probably go for that even though it might not fullfill all my wishes.
Yes, its a double-edged sword. Since GUI aesthetics are so subjective, its very difficult to create a system generic enough to please everyone without massive overhead. The beauty of the system I devised was that the developer could easily take the artist created script and hardcode the settings, freeing up much needed resources. Since we're developing on the desktop, this type of system would work quite well.
As a (former) Delphi programmer I really like the concept of XPE and feel "right at home" with it. :D

Hams: however, I have a few questions:
    * Is there any progress on this framework?
    * Are you going to update it to work with GD 2.04? If so, when will it be available?
    * Could you place comments in the source code in English, so we all can read them :oops: ?!
    * Are there any more examples?
    * Is there a website for Xpe yet?

Wouter (aka Centaur)
Jae-Pil Jung · 07 Aug 2003, 06:18 UTC
Hi Centaur,

* Is there any progress on this framework?
- Yes, work in progress.
1) Documents
2) Examples
3) Some bug fix
4) etc, ...

* Are you going to update it to work with GD 2.04?
If so, when will it be available?
- I'll update this framework to work with GD204.

* Could you place comments in the source code in English, so we all can read them ?!
- Yes, work in progress. :D
(I'll upload new version at 31/08/2003. ^^)

* Are there any more examples?
- No, there are no more examples.
But, next version has more examples. ^^

* Is there a website for Xpe yet?
- English website is under development.
(If the website is open, I'll post here.)

Thanks about your concern. ^^
bir · 04 Sep 2003, 21:14 UTC — Updates?
Any news on the updates you had planned?

Thanks
Bolt · 01 Oct 2003, 05:38 UTC — Any updates on your GUI framework?
I migrated the 2.01b code so I could use it in 2.05. But I was wondering if you had done this already?

Thanks.
One thought I had was you could write a C++ version of Java Swing for Pocket PC. As far as GUI toolkits go, it's fairly simple and self-contained. It has the benefit of being fairly popular and well known. So even if it isn't the best toolkit, and even if the Pocket PC version wasn't exactly the same, it might make a good model to copy.

There's also QT and GTK+. GTK+ even already support framebuffer-type devices.

http://developer.gnome.org/doc/API/2.2/ ... uffer.html
Well I've started work on my extremely simple tiny widget toolkit also. :-)

Mostly just a way of reorganizing the code I already have written (mainly menus, toolbars, etc.).
Here's an interesting one.

Instead of writing a virtual keyboard widget that simply edits a string when you click buttons, it would be nice to make it generate actual key events which get fed into the event dispatcher. Then, the widget that has the key focus simply handles the key events, just as if it were on a device with a real keyboard.
(Edited to delete content from duplicate post.)
I spent a bit of time playing around with widgets. Here's a code dump in case any one wants the very preliminary basics. It's inspired by the qt and Swing toolkits.

Assume you have simple classes WPoint (for position), WDim (for size), and WRect (for bounds). I can provide them if necessary.

Then, define a widget class like this:

Code:

class Widget
{


public:

static
void
dispatchEventStylusDoubleClick(
const WPoint& kScreenPosition);

static
void
dispatchEventStylusDown(
const WPoint& kScreenPosition);

static
void
dispatchEventStylusMove(
const WPoint& kScreenPosition);

static
void
dispatchEventStylusUp(
const WPoint& kScreenPosition);

static
CGapiSurface&
getBackBuffer()
{
return *m_pBackBuffer;
}

static
void
setBackBuffer(
CGapiSurface& backBuffer)
{
m_pBackBuffer = &backBuffer;
}

static
void
repaintTopLevelWidgets()
{
for (int n = 0; n != m_cpTopLevelWidget.size(); ++n)
{
m_cpTopLevelWidget[n]->repaint();
}
}


public:

Widget() :
m_pParent(0)
{
addTopLevelWidget(*this);
};

Widget(
Widget& parent) :
m_pParent(&parent)
{
parent.addChild(*this);
};

virtual
void
eventStylusDoubleClick(
const WPoint& kPosition) {};

virtual
void
eventStylusDown(
const WPoint& kPosition) {};

virtual
void
eventStylusMove(
const WPoint& kPosition) {};

virtual
void
eventStylusUp(
const WPoint& kPosition) {};

WRect
getBounds() const
{
return m_bounds;
};

Widget&
getChild(
const int knIndex) const
{
return *m_cpChild[knIndex];
};

Widget*
getChild(
const WPoint& kPosition);

int
getHeight() const
{
return m_bounds.getHeight();
};

int
getNumberOfChildren() const
{
return m_cpChild.size();
};

Widget&
getParent() const
{
return *m_pParent;
};

WPoint
getPosition() const
{
return m_bounds.getPosition();
};

WDim
getSize() const
{
return m_bounds.getSize();
};

int
getWidth() const
{
return m_bounds.getWidth();
};

int
getX() const
{
return m_bounds.getX();
};

int
getY() const
{
return m_bounds.getY();
};

bool
hasChildren() const
{
return !m_cpChild.empty();
};

bool
hasParent() const
{
return m_pParent != 0;
};

bool
isEnabled() const
{
return m_bEnabled;
};

virtual
void
repaint() {};

void
setBounds(
const WRect& kBounds)
{
m_bounds = kBounds;
};

void
setEnabled(
const bool kbEnabled)
{
m_bEnabled = kbEnabled;
};

void
setHeight(
const int knHeight)
{
m_bounds.setHeight(knHeight);
};

void
setPosition(
const WPoint& kPosition)
{
m_bounds.setPosition(kPosition);
};

void
setSize(
const WDim& kSize)
{
m_bounds.setSize(kSize);
};

void
setWidth(
const int knWidth)
{
m_bounds.setWidth(knWidth);
};

void
setX(
const int knX)
{
m_bounds.setX(knX);
};

void
setY(
const int knY)
{
m_bounds.setY(knY);
};

WPoint
translateFromGlobal(
const WPoint& kPosition) const;

WPoint
translateFromParent(
const WPoint& kPosition) const
{
return WPoint(kPosition.getX() - getX(), kPosition.getY() - getY());
}


private:

static
void
addTopLevelWidget(
Widget& widget)
{
m_cpTopLevelWidget.push_back(&widget);
};


private:

static CGapiSurface* m_pBackBuffer;

static std::vector<Widget*> m_cpTopLevelWidget;


private:

void
addChild(
Widget& child)
{
m_cpChild.push_back(&child);
}


private:

Widget* m_pParent;

std::vector<Widget*> m_cpChild;

WRect m_bounds;

bool m_bEnabled;


};


Now, in the .cpp file you have to define the static members and a few functions. First are the child walking functions:

Code:

Widget*
Widget::getChild(
const WPoint& kPosition)
{
if (!WRect(WPoint(), getSize()).contains(kPosition))
{
return 0;
}

for (int nIndex = 0; nIndex != getNumberOfChildren(); ++nIndex)
{
Widget& child = getChild(nIndex);
if (child.getChild(child.translateFromParent(kPosition)))
{
return &child;
}
}

return this;
}


WPoint
Widget::translateFromGlobal(
const WPoint& kPosition) const
{
WPoint position(kPosition);
const Widget* pkWidget = this;
while (pkWidget->hasParent())
{
position = pkWidget->translateFromParent(position);
pkWidget = &pkWidget->getParent();
}
return pkWidget->translateFromParent(position);
}


Next are the static event dispatch functions (do all four like this):

Code:

void
Widget::dispatchEventStylusMove(
const WPoint& kScreenPosition)
{
for (int n = 0; n != m_cpTopLevelWidget.size(); ++n)
{
if (Widget* pWidget =
m_cpTopLevelWidget[n]->getChild(
m_cpTopLevelWidget[n]->translateFromParent(kScreenPosition)))
{
pWidget->eventStylusMove(
pWidget->translateFromGlobal(kScreenPosition));
}
}
}


Now, hook it up to GapiDraw by calling the static event dispatch functions from the corresponding GapiDraw callbacks. So CGapiApplication::StylusMove calls Widget::dispatchEventStylusMove, etc. Make CGapiApplication::ProcessFrame call Widget::repaintTopLevelWidgets. Set the back buffer during initialization by calling Widget::setBackBuffer.

Subclass Widget to make widget classes. Override the event handlers (e.g. Widget::eventStylusMove) to handle events, and override Widget::repaint to draw.

Create a widget object by calling its constructor with no parent if it is top level, or with its parent if it is a child. (But don't make a child statically, or it will race condition with the top level widget vector, that is a known issue.)

Children live within the coordinate system of their parents. When events occur, they are dispatched to the deepest child over which they occur, in the coordinate system of that child. See the translateFromParent and translateFromGlobal coordinate system transforms. All of this assumes children are within their parents and don't overlap.

What would make this a functioning widget toolkit, besides implementing some actual widget classes? Hook up key events to a widget that has the key focus. Add timer events, enter/leave events, etc.

Make repaint also walk its children. Maybe add support for invalidation (delayed repainting), although that's not as necessary for a game that redraws many times per second.

On the bounds front, perhaps add layout managers. Since widget use on PDA games is on a small scale, we can afford to waste a few cycles here, on layout and on coordinate transforms. If not, forego a layout manager and set bounds manually; maybe add caching of global coordinates for everything. But I think widget use on PDAs is limited to games like cards which can afford it, or just a couple of buttons on a busy screen which won't use much resources anyways.

Add all the widget properties such as enabled, visible, etc. And finally add action support so things can happen when you manipulate widgets (like signals/slots in qt or ActionListeners in Swing).

If anyone does anything with this, post here. I'm only doing this because I need a better way to organize my event handling and drawing in my game for a few things like menus and toolbars, primarily for my in-game editor.
I spent the last few hours doing a bit of reading on signals and slots. qt has one implementation, but there are several other libraries with slightly different ways of doing it.

Connecting signals and slots serves much the same purpose as Java's event mechanism, with ActionListener and ActionPerformed and stuff like that. But there are tradeoffs. Mostly, it's nice because you don't have to make little listener classes all the time. It's a bit intrusive in your code, but so is the requirement to either be a listener or accept listeners to notify.

Anyways, here is what seems to be a nice, public domain, single header file implementation using just C++ templates:

http://sigslot.sourceforge.net/

Pay particular attention to the author's short, lucid paper on her implmentation and the various design decisions:

http://sigslot.sourceforge.net/sigslot.pdf

I do recommend giving that paper a quick read. I think I'll try her library and see how it goes.
warmi · 05 Oct 2003, 15:53 UTC — asdasdsa
I use an older version of sigslot in my games ( Anigma, ZRaid) and it works fine.
Back then it required STL so I rewrote it to use Qt container classes ( which I use on PPC) instead.
Sigslot works really nicely, I tried it and I like it.

For my widgets, I just send a paint event to all widgets during process frame, and don't bother painting them otherwise (e.g. no update, repaint, etc.). For a game which redraws constantly, and only has a few widgets, this is acceptable I think. If you don't want to redraw them, you could not send the event during process frame, but then you'd have to make sure your updates were all in the right places (e.g. button click).

Typically in a widget library, widget bounds are in the coordinate system of the parent. Hence, the find child behaviour I posted above in the mouse event dispatch code. This is fine, but when you get to painting, your widget needs to paint to the right area of the screen. This involves either another coordinate transform, or having a painting context that already has the origin set properly. The latter is common, but we don't have such contexts in GapiDraw.

I could implement the former, at some perfomance cost, but I think there is a better approach. Each widget should have a copy of its screen bounds in addition to its bounds in the parent coordinate system. A consequence is that when a widget moves, it has to update all of its children's screen bounds. On the other hand, looking for widgets by screen position is suddenly easier, and painting can use the screen bounds. Since in a game, moving widgets is uncommon and finding/painting widgets happens many times a second, I think this is a good approach. It requires a bit more memory per widget, but a game doesn't have many widgets anyways.
I use something called WR_Painter . It is basically a painting context class.
This class has two constructors accepting either WR_Surface ( a wrapper for GapiDrawSurface) or WR_Window which is a basic window (widget ) class.
All drawing is done thru this class which , as you mentioned, contains transformed coordinates of the widget ( this includes not only the screen position but also the size - since drawing has to be clipped not only to the screen rectangle but also to the parent window rectangle .)
mlepage wrote:
Each widget should have a copy of its screen bounds in addition to its bounds in the parent coordinate system. A consequence is that when a widget moves, it has to update all of its children's screen bounds. On the other hand, looking for widgets by screen position is suddenly easier, and painting can use the screen bounds.


I implemented this approach and it seems to work quite nicely.
mlepage wrote:
Instead of writing a virtual keyboard widget that simply edits a string when you click buttons, it would be nice to make it generate actual key events which get fed into the event dispatcher. Then, the widget that has the key focus simply handles the key events, just as if it were on a device with a real keyboard.


I tried this. Now, on the PC, you can use the virtual keyboard same as on the Pocket PC. But you can also type on the regular keyboard. Works like a charm. To a widget with the focus, it just looks like key events are coming in, doesn't matter whether it is coming from a real keyboard or from a virtual keyboard.