commit 662aece80645cbe89733d85f292859f98cf54048 Author: cozman Date: Mon May 19 22:58:01 2003 +0000 Initial revision diff --git a/include/GewiButton.h b/include/GewiButton.h new file mode 100755 index 0000000..e32279c --- /dev/null +++ b/include/GewiButton.h @@ -0,0 +1,49 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file GewiButton.h + \brief Definition file for GewiButton. + + Definition file for GewiButton, a simple button class. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewibutton_h__ +#define __gewibutton_h__ + +#include "GewiEngine.h" +#include "GewiWidget.h" + +namespace Gewi +{ + +class GButton : public GWidget +{ + protected: + bool rPressed; + GButtonType rType; + ResourceID rNormalImage; + ResourceID rPressedImage; + public: + GButton(GContainer *parent=NULL); + + virtual void Create(float x, float y, float width, float height, ResourceID normalImg, ResourceID pressImg, GButtonType type=G_PRESS); + virtual void Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch); + virtual void Show(); + + bool IsPressed(); + void SetState(bool state); +}; + +} + +#endif //__gewibutton_h__ diff --git a/include/GewiContainer.h b/include/GewiContainer.h new file mode 100755 index 0000000..c9cdf61 --- /dev/null +++ b/include/GewiContainer.h @@ -0,0 +1,51 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewicontainer_h__ +#define __gewicontainer_h__ + +#include "GewiIncludes.h" +#include "GewiWidgetList.h" +#include "GewiWidget.h" + +namespace Gewi +{ + +class GContainer : public GWidget +{ + //friend here is used simply to allow GWidget proper access to what used to belong to it before + //the class split GWidget needs access to Add/ReleaseChild but to make them public would _reduce_ + //encapsulation (for those keeping score, this is to many people the only effective use of friend) + friend GWidget; + + protected: + WidgetList rChildList; + void AddChild(GWidget *widget); + void ReleaseChild(GWidget *widget); + void InsertWidget(WidgetNode *node); + public: + GContainer(GContainer *parent=NULL); + void Move(float x, float y); + void Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch); + void Show(); +}; + +} + +#endif //__gewicontainer_h__ diff --git a/include/GewiEngine.h b/include/GewiEngine.h new file mode 100755 index 0000000..f67b2f8 --- /dev/null +++ b/include/GewiEngine.h @@ -0,0 +1,69 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewiengine_h__ +#define __gewiengine_h__ + +#include "GewiIncludes.h" +#include "GewiWidgetList.h" + +namespace Gewi +{ + +class GewiEngine +{ + private: + static GewiEngine *sInstance; + static SDL_EventFilter sOldFilter; + vector mImageVec; + vector mFontVec; + WidgetList mWidgetList; + + //singleton setup// + private: + GewiEngine(); + public: + static const ResourceID InvalidID = UINT_MAX; //UINT_MAX b/c many compilers don't like numeric_limits + static GewiEngine* GetInstance(); + static void ReleaseInstance(); + + //utilities// + static int EventFilter(SDL_Event *event); + static char TranslateKey(SDL_keysym key); + void Display(); + + //resource management// + ResourceID AddResource(ZImage *image); + ResourceID AddResource(ZFont *font); + ZImage* Image(ResourceID id); + ZFont* Font(ResourceID id); + void FreeResources(); + + //widget management// + private: + void InsertWidget(WidgetNode *node); + public: + void Register(GWidget *widget); + void SendMessage(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch); + void DeleteWidget(GWidget *widget); +}; + +} + +#endif //__gewiengine_h__ diff --git a/include/GewiIncludes.h b/include/GewiIncludes.h new file mode 100755 index 0000000..20ddbc0 --- /dev/null +++ b/include/GewiIncludes.h @@ -0,0 +1,36 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewiincludes_h__ +#define __gewiincludes_h__ + +#include +#include +#include +#include "ZEngine.h" +typedef unsigned int WidgetID; +typedef unsigned int ResourceID; +enum GewiEvent { GE_LDOWN, GE_LUP, GE_RDOWN, GE_RUP, GE_KDOWN, GE_KUP, GE_GOTFOCUS, GE_LOSTFOCUS }; +enum _GewiJustify { GJ_CENTER = 0, GJ_LEFT = 1<<0, GJ_RIGHT = 1<<1, GJ_TOP = 1<<2, GJ_BOTTOM = 1<<3 }; +enum GButtonType { G_PRESS, G_HOVER }; +typedef unsigned int GewiJustify; +using namespace std; +using namespace ZE; + +#endif //__gewiincludes_h__ \ No newline at end of file diff --git a/include/GewiSlider.h b/include/GewiSlider.h new file mode 100755 index 0000000..416c744 --- /dev/null +++ b/include/GewiSlider.h @@ -0,0 +1,63 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewislider_h__ +#define __gewislider_h__ + +#include "GewiEngine.h" +#include "GewiWidget.h" + +namespace Gewi +{ + +class GSlider : public GWidget +{ + protected: + bool rPressed; + ResourceID rBackground; + ResourceID rSlider; + float rMin,rMax,rPos; + int rIncrement; + public: + GSlider(); + + virtual void Create(float x, float y, float width, float height, ResourceID backgroundImg, ResourceID sliderImg, + float min, float max, int increment); + + void SetPos(float pos); + float GetPos(); +}; + +class GHorizSlider : public GSlider +{ + public: + virtual void Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch); + virtual void Show(); +}; + +class GVertSlider : public GSlider +{ + public: + virtual void Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch); + virtual void Show(); +}; + +} + +#endif //__gewislider_h__ diff --git a/include/GewiStaticText.h b/include/GewiStaticText.h new file mode 100755 index 0000000..1f8e215 --- /dev/null +++ b/include/GewiStaticText.h @@ -0,0 +1,52 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewistatictext_h__ +#define __gewistatictext_h__ + +#include "GewiEngine.h" +#include "GewiWidget.h" + +namespace Gewi +{ + +class GStaticText : public GWidget +{ + protected: + ResourceID rBackgroundImage; + ResourceID rFont; + string rText; + ZImage rTextBuf; + int rXOff,rYOff; + GewiJustify rJustify; + public: + GStaticText(GContainer *parent=NULL); + + virtual void Create(float x, float y, float width, float height, + ResourceID font, ResourceID backgroundImg=GewiEngine::InvalidID, string text=" ", GewiJustify just=GJ_CENTER); + virtual void Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch); + virtual void Show(); + + void SetText(string text); + string GetText(); +}; + +} + +#endif //__gewistatictext_h__ diff --git a/include/GewiTextButton.h b/include/GewiTextButton.h new file mode 100755 index 0000000..a750d81 --- /dev/null +++ b/include/GewiTextButton.h @@ -0,0 +1,49 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewitextbutton_h__ +#define __gewitextbutton_h__ + +#include "GewiEngine.h" +#include "GewiButton.h" + +namespace Gewi +{ + +class GTextButton : public GButton +{ + protected: + string rText; + ZImage rTextBuf; + int rXOff,rYOff; + ResourceID rFont; + public: + GTextButton(GContainer *parent=NULL); + + virtual void Create(float x, float y, float width, float height, ResourceID normalImg, ResourceID pressImg, ResourceID font, + string text=" ", GButtonType type=G_PRESS); + virtual void Show(); + + void SetText(string text); + string GetText(); +}; + +} + +#endif //__gewitextbutton_h__ diff --git a/include/GewiTextField.h b/include/GewiTextField.h new file mode 100755 index 0000000..d16f1af --- /dev/null +++ b/include/GewiTextField.h @@ -0,0 +1,53 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewitextfield_h__ +#define __gewitextfield_h__ + +#include "GewiEngine.h" +#include "GewiWidget.h" + +namespace Gewi +{ + +class GTextField : public GWidget +{ + protected: + string rText; + ZImage rBuffer; + ResourceID rFont; + ResourceID rBackground; + int rMaxChars,rLeftPadding; + public: + GTextField(GContainer *parent=NULL); + ~GTextField(); + + void Kill(); + + virtual void Create(float x, float y, float width, float height, ResourceID font, ResourceID backgroundImg, int maxChars=256, int leftPad=0); + virtual void Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch); + virtual void Show(); + + void SetText(string text); + string GetText(); +}; + +} + +#endif //__gewiewitextfield_h__ diff --git a/include/GewiWidget.h b/include/GewiWidget.h new file mode 100755 index 0000000..e88ebdf --- /dev/null +++ b/include/GewiWidget.h @@ -0,0 +1,65 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewiwidget_h__ +#define __gewiwidget_h__ + +#include "GewiIncludes.h" + +namespace Gewi +{ + + +class GewiEngine; +class GContainer; + +class GWidget +{ + protected: + GewiEngine *rGewi; + ZEngine *rZE; + ZRect rBoundRect; + GContainer *rParent; + float rRelX,rRelY; + bool rVisible; + bool rAlive; + + public: + GWidget(GContainer *parent=NULL); + virtual ~GWidget(); + + void FitParent(); + void ToggleVisible(); + + virtual void Kill(); + virtual void Create(float x, float y, float width, float height); + virtual void Move(float x, float y); + virtual void Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch)=0; + virtual void Show()=0; + + float X(); + float Y(); + bool Visible(); + bool MouseInWidget(); + bool Contains(Sint16 x, Sint16 y); +}; + +} + +#endif //__gewiwidget_h__ diff --git a/include/GewiWidgetList.h b/include/GewiWidgetList.h new file mode 100755 index 0000000..9403dc7 --- /dev/null +++ b/include/GewiWidgetList.h @@ -0,0 +1,60 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewiwidgetlist_h__ +#define __gewiwidgetlist_h__ + +#include "GewiIncludes.h" + +namespace Gewi +{ + +class GWidget; + +class WidgetNode +{ + public: + WidgetNode(); + GWidget *widget; + WidgetNode *prev; + WidgetNode *next; +}; + +class WidgetList +{ + private: + WidgetNode *mWidgetList; + WidgetNode *mClick; + + void DeleteWidgetMem(WidgetNode *node); + public: + WidgetList(); + + void AddWidget(WidgetNode *node); + void DeleteWidget(GWidget *widget); + void DeleteWidgets(); + + void Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch); + void FitParent(); + void ShowWidgets(); +}; + +} + +#endif //__gewiwidgetlist_h__ diff --git a/include/GewiWindow.h b/include/GewiWindow.h new file mode 100755 index 0000000..f01fa10 --- /dev/null +++ b/include/GewiWindow.h @@ -0,0 +1,45 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#ifndef __gewiwindow_h__ +#define __gewiwindow_h__ + +#include "GewiEngine.h" +#include "GewiContainer.h" + +namespace Gewi +{ + +class GWindow : public GContainer +{ + protected: + bool rDrag; + float rDragX,rDragY; + ResourceID rBackground; + public: + GWindow(); + + virtual void Create(float x, float y, float width, float height, ResourceID backgroundImg); + virtual void Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch); + virtual void Show(); +}; + +} + +#endif //__gewiwindow_h__ diff --git a/src/GewiButton.cpp b/src/GewiButton.cpp new file mode 100755 index 0000000..4110f83 --- /dev/null +++ b/src/GewiButton.cpp @@ -0,0 +1,94 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiButton.h" + +namespace Gewi +{ + +GButton::GButton(GContainer *parent) : + GWidget(parent), + rPressed(false), + rType(G_PRESS), + rNormalImage(GewiEngine::InvalidID), + rPressedImage(GewiEngine::InvalidID) +{ +} + +void GButton::Create(float x, float y, float width, float height, ResourceID normalImg, ResourceID pressImg, GButtonType type) +{ + GWidget::Create(x,y,width,height); + rNormalImage = normalImg; + rPressedImage = pressImg; + rType = type; +} + +void GButton::Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch) +{ + if(event == GE_LUP && MouseInWidget()) + { + rPressed = !rPressed; //toggle button state on mouseup + } +} + +void GButton::Show() +{ + float x,y; + unsigned int w,h; + x = rBoundRect.X(); + y = rBoundRect.Y(); + + //images must be "resized" with each draw, disadvantage to shared resources + //yet luckily the ZImage resize system is only two assignments, not actual stretching code + //if resize is to be rewritten the shared resources system of Gewi should be reconsidered + w = static_cast(rBoundRect.Width()); + h = static_cast(rBoundRect.Height()); + rGewi->Image(rPressedImage)->Resize(w,h); + rGewi->Image(rNormalImage)->Resize(w,h); + + if(rVisible) + { + if(rType == G_PRESS) //G_PRESS: standard press button, down when pressed, up when not + { + if(rPressed) + rGewi->Image(rPressedImage)->Draw(x,y); + else + rGewi->Image(rNormalImage)->Draw(x,y); + } + else if(rType == G_HOVER) //G_HOVER: button shows as down when hovered over + { + if(MouseInWidget()) + rGewi->Image(rPressedImage)->Draw(x,y); + else + rGewi->Image(rNormalImage)->Draw(x,y); + } + } +} + +bool GButton::IsPressed() +{ + return rPressed; +} + +void GButton::SetState(bool state) +{ + rPressed = state; +} + +} diff --git a/src/GewiContainer.cpp b/src/GewiContainer.cpp new file mode 100755 index 0000000..64cc6c6 --- /dev/null +++ b/src/GewiContainer.cpp @@ -0,0 +1,62 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiContainer.h" + +namespace Gewi +{ + +void GContainer::AddChild(GWidget *widget) +{ + WidgetNode *node = new WidgetNode; + node->widget = widget; + rChildList.AddWidget(node); //create new child on top +} + +void GContainer::ReleaseChild(GWidget *widget) //this simply releases a child, usually called when the child is being destroyed +{ + rChildList.DeleteWidget(widget); +} + +void GContainer::InsertWidget(WidgetNode *node) //insert at front +{ + rChildList.AddWidget(node); +} + +GContainer::GContainer(GContainer *parent) +{ +} + +void GContainer::Move(float x, float y) +{ + GWidget::Move(x,y); + rChildList.FitParent(); //fit each child to parent +} + +void GContainer::Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch) +{ + rChildList.Message(rawEvent,event,mouseX,mouseY,ch); +} + +void GContainer::Show() +{ + rChildList.ShowWidgets(); +} + +} diff --git a/src/GewiEngine.cpp b/src/GewiEngine.cpp new file mode 100755 index 0000000..5091fd2 --- /dev/null +++ b/src/GewiEngine.cpp @@ -0,0 +1,190 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiWidget.h" +#include "GewiEngine.h" + +namespace Gewi +{ + +GewiEngine *GewiEngine::sInstance=NULL; +SDL_EventFilter GewiEngine::sOldFilter=NULL; + +GewiEngine::GewiEngine() +{ + sOldFilter = SDL_GetEventFilter(); //store event filter and set the new one + SDL_SetEventFilter((SDL_EventFilter)GewiEngine::EventFilter); + SDL_EnableUNICODE(1); //needed for the key translation + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL); +} + + +GewiEngine* GewiEngine::GetInstance() +{ + if(!sInstance) + sInstance = new GewiEngine; + + return sInstance; +} + +void GewiEngine::ReleaseInstance() +{ + if(sInstance) + { + sInstance->FreeResources(); + sInstance->mWidgetList.DeleteWidgets(); + delete sInstance; + sInstance = NULL; + //set everything back to default + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_INTERVAL,SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableUNICODE(0); + SDL_SetEventFilter(sOldFilter); + } +} + +int GewiEngine::EventFilter(SDL_Event *event) +{ + static char noChar = static_cast(0); + GewiEngine *gewi = GewiEngine::GetInstance(); + char ch; + + switch(event->type) + { + case SDL_MOUSEBUTTONDOWN: + if(event->button.button == SDL_BUTTON_LEFT) + gewi->SendMessage(event,GE_LDOWN,event->button.x,event->button.y,noChar); + if(event->button.button == SDL_BUTTON_RIGHT) + gewi->SendMessage(event,GE_RDOWN,event->button.x,event->button.y,noChar); + break; + case SDL_MOUSEBUTTONUP: + if(event->button.button == SDL_BUTTON_LEFT) + gewi->SendMessage(event,GE_LUP,event->button.x,event->button.y,noChar); + if(event->button.button == SDL_BUTTON_RIGHT) + gewi->SendMessage(event,GE_RUP,event->button.x,event->button.y,noChar); + break; + case SDL_KEYDOWN: + ch = TranslateKey(event->key.keysym); + gewi->SendMessage(event,GE_KDOWN,0,0,ch); + break; + case SDL_KEYUP: + ch = TranslateKey(event->key.keysym); + gewi->SendMessage(event,GE_KUP,0,0,ch); + break; + case SDL_QUIT: + //. + break; + default: + break; + } + return 1; //pass the event on +} + +char GewiEngine::TranslateKey(SDL_keysym key) +{ + char ch; + + if(key.unicode && key.unicode <= 255) + ch = static_cast(key.unicode); + else + ch = static_cast(127); + + if(ch >= 'a' && ch <= 'z' && (key.mod & KMOD_SHIFT)) + ch -= 20; //capitalize + + return ch; +} + +void GewiEngine::Display() +{ + mWidgetList.ShowWidgets(); +} + +ResourceID GewiEngine::AddResource(ZImage *image) +{ + mImageVec.push_back(image); + return static_cast(mImageVec.size()-1); +} + +ResourceID GewiEngine::AddResource(ZFont *font) +{ + mFontVec.push_back(font); + return static_cast(mFontVec.size()-1); +} + +ZImage* GewiEngine::Image(ResourceID id) +{ + //do range checking + if(id >= 0 && id < mImageVec.size()) + return mImageVec[id]; + else + return NULL; +} + +ZFont* GewiEngine::Font(ResourceID id) +{ + //do range checking + if(id >= 0 && id < mFontVec.size()) + return mFontVec[id]; + else + return NULL; +} + +void GewiEngine::FreeResources() +{ + for(ResourceID i=0; i < mImageVec.size(); i++) + { + if(mImageVec[i]) + { + mImageVec[i]->Release(); + delete mImageVec[i]; + } + } + for(ResourceID i=0; i < mFontVec.size(); i++) + { + if(mFontVec[i]) + { + mFontVec[i]->Release(); + delete mFontVec[i]; + } + } +} + +void GewiEngine::Register(GWidget *widget) +{ + WidgetNode *node = new WidgetNode; + node->widget = widget; + mWidgetList.AddWidget(node); +} + +void GewiEngine::SendMessage(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch) +{ + mWidgetList.Message(rawEvent,event,mouseX,mouseY,ch); +} + +void GewiEngine::DeleteWidget(GWidget *widget) //finds + frees memory of widget +{ + mWidgetList.DeleteWidget(widget); +} + +void GewiEngine::InsertWidget(WidgetNode *node) //insert at front +{ + mWidgetList.AddWidget(node); +} + +} diff --git a/src/GewiSlider.cpp b/src/GewiSlider.cpp new file mode 100755 index 0000000..b6a5e65 --- /dev/null +++ b/src/GewiSlider.cpp @@ -0,0 +1,134 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiSlider.h" + +namespace Gewi +{ + +GSlider::GSlider() : + GWidget(), + rPressed(false), + rBackground(GewiEngine::InvalidID), + rSlider(GewiEngine::InvalidID), + rMin(0), + rMax(1), + rPos(0), + rIncrement(0) +{} + +void GSlider::Create(float x, float y, float width, float height, ResourceID backgroundImg, ResourceID sliderImg, + float min, float max, int increment) +{ + GWidget::Create(x,y,width,height); + rBackground = backgroundImg; + rSlider = sliderImg; + rMin = min; + rMax = max; + rIncrement = increment; + SetPos(rPos); //clamp inside +} + +void GSlider::SetPos(float pos) +{ + if(rIncrement) + { + int rounded; + + if(pos - static_cast(pos) < 0.5) //move to closest integer + rounded = static_cast(floorf(pos)+rIncrement/2); + else + rounded = static_cast(ceilf(pos)+rIncrement/2); + pos = static_cast(rounded-rounded%rIncrement); //snap to a multiple of increment + } + + if(pos < rMin) + pos = rMin; + if(pos > rMax) + pos = rMax; + rPos = pos; +} + +float GSlider::GetPos() +{ + return rPos; +} + +void GHorizSlider::Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch) +{ + //doesn't check if mouse is in widget because Show actually checks that for the drawing + if(event == GE_LDOWN) + rPressed = true; + else if(event == GE_LUP && rPressed) + { + //min + (Distance Past Rect.X / Rect.Width) + SetPos(rMin+((mouseX-rBoundRect.X())/rBoundRect.Width())*(rMax-rMin)); + rPressed = false; + } +} + +void GHorizSlider::Show() +{ + float xPos; + + if(rPressed && !rZE->LButtonPressed() || !MouseInWidget()) //dont allow them to drag pointer out of box + Message(NULL,GE_LUP,rZE->MouseX(),rZE->MouseY(),static_cast(0)); //fake a message + + //the slider is centered about the current position + if(rPressed) + xPos = rZE->MouseX()-rGewi->Image(rSlider)->Width()/2.0f; + else + xPos = rBoundRect.X()+(((rPos-rMin)/(rMax-rMin))*rBoundRect.Width())-rGewi->Image(rSlider)->Width()/2.0f; + + //draw from resources + rGewi->Image(rBackground)->Draw(rBoundRect.X(),rBoundRect.Y()); + rGewi->Image(rSlider)->Draw(xPos,rBoundRect.Y()); +} + +void GVertSlider::Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch) +{ + //doesn't check if mouse is in widget because Show actually checks that (to avoid being dragged outside) + if(event == GE_LDOWN) + rPressed = true; + else if(event == GE_LUP && rPressed) + { + SetPos(rMin+((mouseY-rBoundRect.Y())/rBoundRect.Height())*(rMax-rMin)); //clamp when they release the button + rPressed = false; + } +} + +void GVertSlider::Show() +{ + float yPos; + + if(!rZE->LButtonPressed() || !MouseInWidget()) //dont allow them to drag pointer out of box + Message(NULL,GE_LUP,rZE->MouseX(),rZE->MouseY(),static_cast(0)); //faking a message + + //the slider is centered about the current position + if(rPressed) + yPos = rZE->MouseY()-rGewi->Image(rSlider)->Height()/2.0f; + else + yPos = rBoundRect.Y()+(((rPos-rMin)/(rMax-rMin))*rBoundRect.Height())-rGewi->Image(rSlider)->Height()/2.0f; + + //draw from resources + rGewi->Image(rBackground)->Draw(rBoundRect.X(),rBoundRect.Y()); + rGewi->Image(rSlider)->Draw(rBoundRect.X(),yPos); +} + +} diff --git a/src/GewiStaticText.cpp b/src/GewiStaticText.cpp new file mode 100755 index 0000000..5d74459 --- /dev/null +++ b/src/GewiStaticText.cpp @@ -0,0 +1,107 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiStaticText.h" + +namespace Gewi +{ + +GStaticText::GStaticText(GContainer *parent) : + GWidget(parent), + rBackgroundImage(GewiEngine::InvalidID), + rFont(GewiEngine::InvalidID), + rXOff(0), + rYOff(0), + rJustify(GJ_CENTER) +{ +} + + +void GStaticText::Create(float x, float y, float width, float height, + ResourceID font, ResourceID backgroundImg, string text, GewiJustify justify) +{ + GWidget::Create(x,y,width,height); + + rBackgroundImage = backgroundImg; + rFont = font; + rJustify = justify; //must justify pre-SetText + SetText(text); +} + +void GStaticText::Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch) +{ + //static text ignores messages +} + +void GStaticText::Show() +{ + //images must call Resize with each draw (shared resources) + if(rBackgroundImage != GewiEngine::InvalidID) + rGewi->Image(rBackgroundImage)->Resize(static_cast(rBoundRect.Width()),static_cast(rBoundRect.Height())); + + if(rBackgroundImage != GewiEngine::InvalidID) + rGewi->Image(rBackgroundImage)->Draw(rBoundRect.X(),rBoundRect.Y()); + rTextBuf.Draw(rBoundRect.X()+rXOff,rBoundRect.Y()+rYOff); //draw text shifted by offset +} + + +void GStaticText::SetText(string text) +{ + int w,h; + + rText = text; + rGewi->Font(rFont)->DrawText(rText,rTextBuf); + + w=rTextBuf.Width(); + h=rTextBuf.Height(); + + //center each by default + rXOff = static_cast(rBoundRect.Width()-w)/2; + rYOff = static_cast(rBoundRect.Height()-h)/2; + + if(rJustify & GJ_LEFT) + { + printf("left"); + rXOff = 0; + } + else if(rJustify & GJ_RIGHT) + { + printf("right"); + rXOff = static_cast(rBoundRect.Width()-w); + } + + if(rJustify & GJ_TOP) + { + printf("top"); + rYOff = 0; + } + else if(rJustify & GJ_BOTTOM) + { + printf("bottom"); + rYOff = static_cast(rBoundRect.Height()-h); + } + printf("\n"); +} + +string GStaticText::GetText() +{ + return rText; +} + +} diff --git a/src/GewiTextButton.cpp b/src/GewiTextButton.cpp new file mode 100755 index 0000000..a210b2b --- /dev/null +++ b/src/GewiTextButton.cpp @@ -0,0 +1,66 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiTextButton.h" + +namespace Gewi +{ + +GTextButton::GTextButton(GContainer *parent) : + GButton(parent), + rXOff(0), + rYOff(0), + rFont(GewiEngine::InvalidID) +{} + + +void GTextButton::Create(float x, float y, float width, float height, ResourceID normalImg, ResourceID pressImg, ResourceID font, + string text, GButtonType type) +{ + GButton::Create(x,y,width,height,normalImg,pressImg,type); + rFont = font; + SetText(text); +} + +void GTextButton::Show() +{ + GButton::Show(); //draw button before text + + //TODO: calculate decent pressed offset based upon scale + if(rPressed) + rTextBuf.Draw(rBoundRect.X()+rXOff+5,rBoundRect.Y()+rYOff+3); //draw text shifted by offset + a bit (for pressed look) + else + rTextBuf.Draw(rBoundRect.X()+rXOff,rBoundRect.Y()+rYOff); //draw text shifted by offset +} + +void GTextButton::SetText(string text) +{ + rText = text; + rGewi->Font(rFont)->DrawText(rText,rTextBuf); + //center the text + rXOff = static_cast(rBoundRect.Width()-rTextBuf.Width())/2; + rYOff = static_cast(rBoundRect.Height()-rTextBuf.Height())/2; +} + +string GTextButton::GetText() +{ + return rText; +} + +} diff --git a/src/GewiTextField.cpp b/src/GewiTextField.cpp new file mode 100755 index 0000000..ff471db --- /dev/null +++ b/src/GewiTextField.cpp @@ -0,0 +1,85 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiTextField.h" + +namespace Gewi +{ + +GTextField::GTextField(GContainer *parent) : + GWidget(parent), + rFont(GewiEngine::InvalidID), + rBackground(GewiEngine::InvalidID), + rMaxChars(256), + rLeftPadding(0) +{} + +GTextField::~GTextField() +{ +} + +void GTextField::Kill() +{ + rBuffer.Release(); + GWidget::Kill(); +} + +void GTextField::Create(float x, float y, float width, float height, ResourceID font, ResourceID backgroundImg, int maxChars, int leftPad) +{ + GWidget::Create(x,y,width,height); + rFont = font; + rBackground = backgroundImg; + rMaxChars = maxChars; + rLeftPadding = leftPad; +} + +void GTextField::Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch) +{ + if(event == GE_KDOWN) + { + //casted to avoid warning + if((isgraph(ch) || ch == ' ') && rText.length() < static_cast(rMaxChars)) //only add characters + spaces + rText += ch; + else if(ch == '\b') + rText = rText.length() ? rText.substr(0,rText.length()-1) : ""; //go back one character + + rGewi->Font(rFont)->DrawText(rText.length() ? rText : " ",rBuffer); + } +} + +void GTextField::Show() +{ + rGewi->Image(rBackground)->Resize(static_cast(rBoundRect.Width()),static_cast(rBoundRect.Height())); + rGewi->Image(rBackground)->Draw(rBoundRect.X(),rBoundRect.Y()); + if(rBuffer.IsLoaded()) //don't draw empty buffer image + rBuffer.Draw(rLeftPadding+rBoundRect.X(),rBoundRect.Y()+(rBoundRect.Height()-rBuffer.Height())/2); +} + +void GTextField::SetText(string text) +{ + rText = text; + rGewi->Font(rFont)->DrawText(rText,rBuffer); +} + +string GTextField::GetText() +{ + return rText; +} + +} diff --git a/src/GewiWidget.cpp b/src/GewiWidget.cpp new file mode 100755 index 0000000..e06c9b8 --- /dev/null +++ b/src/GewiWidget.cpp @@ -0,0 +1,112 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiWidget.h" +#include "GewiEngine.h" +#include "GewiContainer.h" + +namespace Gewi +{ + +void GWidget::FitParent() //adjust to relative pos + parent pos +{ + if(rParent) + rBoundRect.Move(rRelX+rParent->X(),rRelY+rParent->Y()); + else + rBoundRect.Move(rRelX,rRelY); +} + +GWidget::GWidget(GContainer *parent) : + rGewi(GewiEngine::GetInstance()), + rZE(ZEngine::GetInstance()), + rParent(parent), + rRelX(0), + rRelY(0), + rVisible(true), + rAlive(true) +{ + if(rParent) + rParent->AddChild(this); + else + rGewi->Register(this); +} + +GWidget::~GWidget() +{ +} + +void GWidget::ToggleVisible() +{ + rVisible = !rVisible; +} + +void GWidget::Kill() +{ + if(rParent) + { + rParent->ReleaseChild(this); + rParent = NULL; + } + else + rGewi->DeleteWidget(this); + + //rChildList.DeleteWidgets(); + rAlive = rVisible = false; +} + +void GWidget::Create(float x, float y, float width, float height) +{ + Move(x,y); + rBoundRect.Resize(width,height); + rVisible = true; +} + +void GWidget::Move(float x, float y) +{ + rRelX = x; + rRelY = y; + FitParent(); //use relative x and relative y to position this inside the parent +} + +float GWidget::X() +{ + return rBoundRect.X(); +} + +float GWidget::Y() +{ + return rBoundRect.Y(); +} + +bool GWidget::Visible() +{ + return rVisible; +} + +bool GWidget::MouseInWidget() +{ + return rZE->MouseInRect(&rBoundRect.SDLrect()); +} + +bool GWidget::Contains(Sint16 x, Sint16 y) +{ + return rBoundRect.Contains(static_cast(x), static_cast(y)); +} + +} diff --git a/src/GewiWidgetList.cpp b/src/GewiWidgetList.cpp new file mode 100755 index 0000000..c60d716 --- /dev/null +++ b/src/GewiWidgetList.cpp @@ -0,0 +1,176 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiWidgetList.h" +#include "GewiWidget.h" //needed for definition + +namespace Gewi +{ + +WidgetNode::WidgetNode() : + widget(NULL), + prev(NULL), + next(NULL) +{ +} + +void WidgetList::DeleteWidgetMem(WidgetNode *node) +{ + if(node == mWidgetList) //special case if deleting top node + { + if(mWidgetList->next != mWidgetList) + mWidgetList = mWidgetList->next; + else + mWidgetList = NULL; + } + //adjust links and actually delete node + node->prev->next = node->next; + node->next->prev = node->prev; + delete node; +} + +WidgetList::WidgetList() : + mWidgetList(NULL), + mClick(NULL) +{ +} + +void WidgetList::AddWidget(WidgetNode *node) +{ + if(mWidgetList == NULL) + { + node->next = node->prev = node; + } + else + { + //make connections + node->next = mWidgetList; + node->prev = mWidgetList->prev; + mWidgetList->prev->next = node; + mWidgetList->prev = node; + } + + mWidgetList = node; +} + +void WidgetList::DeleteWidget(GWidget *widget) +{ + WidgetNode *cur = mWidgetList, *found = NULL; + + if(mWidgetList) + { + do + { + if(cur->widget == widget) + found = cur; + cur = cur->next; + } while(cur != mWidgetList && !found); + + if(found) + DeleteWidgetMem(found); + } +} + +void WidgetList::DeleteWidgets() +{ + WidgetNode *cur = mWidgetList; + while(mWidgetList) + { + cur = cur->next; + cur->prev->widget->Kill(); + } +} + +void WidgetList::Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch) +{ + GWidget *tmp=NULL; + + if(mWidgetList) + { + if(event == GE_LDOWN || event == GE_RDOWN) //mouse down + { + if(mWidgetList->widget->MouseInWidget()) //in focus + { + mWidgetList->widget->Message(rawEvent,event,mouseX,mouseY,ch); + } + else //not in focus + { + WidgetNode *cur=mWidgetList; + do + { + cur = cur->next; + if(cur->widget->MouseInWidget()) + { + mClick = cur; //click in out of focus window == save this and check if mouse up occurs within + break; + } + }while(cur->next != mWidgetList); + } + } + else if(event == GE_LUP || event == GE_RUP) //mouse up + { + if(mWidgetList->widget->MouseInWidget()) //inside the active + { + mWidgetList->widget->Message(rawEvent,event,mouseX,mouseY,ch); + } + else if(mClick && mClick->widget->MouseInWidget()) //inside the mouse down - make active + { + //unlink the node.. then move to the front of the list + mClick->prev->next = mClick->next; + mClick->next->prev = mClick->prev; + mClick->widget->Message(rawEvent,event==GE_LUP?GE_LDOWN:GE_RDOWN,mouseX,mouseY,ch); //simulate the lost button-down event + mWidgetList->widget->Message(NULL,GE_LOSTFOCUS,mouseX,mouseY,ch); //let current focus know it is focus no more + mClick->widget->Message(NULL,GE_GOTFOCUS,mouseX,mouseY,ch); //let new focus it got focus + mClick->widget->Message(rawEvent,event,mouseX,mouseY,ch); //send this event + AddWidget(mClick); //reinsert node + } + mClick = NULL; //on up there is no mClick, it simply holds where the mouse was pressed in + } + else //non-mouseclick events + { + mWidgetList->widget->Message(rawEvent,event,mouseX,mouseY,ch); + } + } +} + +void WidgetList::FitParent() +{ + WidgetNode *cur = mWidgetList; + if(mWidgetList) //make every child fit it's parent + { + do + { + cur->widget->FitParent(); + cur = cur->next; + }while(cur != mWidgetList); + } +} + +void WidgetList::ShowWidgets() +{ + WidgetNode *cur = mWidgetList; + do + { + cur = cur->prev; //draw from back to front, through list in reverse + if(cur->widget->Visible()) + cur->widget->Show(); + }while(cur != mWidgetList); +} + +} diff --git a/src/GewiWindow.cpp b/src/GewiWindow.cpp new file mode 100755 index 0000000..54fc4c6 --- /dev/null +++ b/src/GewiWindow.cpp @@ -0,0 +1,77 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format. +
$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $
+ \author James Turk +**/ + +#include "GewiWindow.h" + +namespace Gewi +{ + +GWindow::GWindow() : + GContainer(), + rDrag(false), + rDragX(0), + rDragY(0), + rBackground(GewiEngine::InvalidID) +{} + +void GWindow::Create(float x, float y, float width, float height, ResourceID backgroundImg) +{ + GWidget::Create(x,y,width,height); + rBackground = backgroundImg; +} + +void GWindow::Message(SDL_Event *rawEvent, GewiEvent event, Uint16 mouseX, Uint16 mouseY, char ch) +{ + if(event == GE_LDOWN) + { + //keep dragging window while mouse is down + rDrag = true; + rDragX = rBoundRect.X()-mouseX; + rDragY = rBoundRect.Y()-mouseY; + } + else if(event == GE_LUP) + { + //release mouse-drag and actually move window + Move(rZE->MouseX()+rDragX,rZE->MouseY()+rDragY); + rDrag = false; + rDragX = rDragY = 0; + } + GContainer::Message(rawEvent,event,mouseX,mouseY,ch); //send to children +} + +void GWindow::Show() +{ + if(rVisible) + { + if(rDrag) + { + Move(rZE->MouseX()+rDragX,rZE->MouseY()+rDragY); //draw at dragged position if mouse is held + if(!rZE->LButtonPressed()) + rDrag = false; + } + + //resize (shared resources) and draw + rGewi->Image(rBackground)->Resize(static_cast(rBoundRect.Width()),static_cast(rBoundRect.Height())); + rGewi->Image(rBackground)->Draw(rBoundRect.X(),rBoundRect.Y()); + + GContainer::Show(); //important that a window draws it's children + } +} + +} diff --git a/test/bin/data/b1.bmp b/test/bin/data/b1.bmp new file mode 100755 index 0000000..b3cf409 Binary files /dev/null and b/test/bin/data/b1.bmp differ diff --git a/test/bin/data/b2.bmp b/test/bin/data/b2.bmp new file mode 100755 index 0000000..935a976 Binary files /dev/null and b/test/bin/data/b2.bmp differ diff --git a/test/bin/data/bg3.bmp b/test/bin/data/bg3.bmp new file mode 100755 index 0000000..46e06ad Binary files /dev/null and b/test/bin/data/bg3.bmp differ diff --git a/test/bin/data/bg4.bmp b/test/bin/data/bg4.bmp new file mode 100755 index 0000000..26be6d6 Binary files /dev/null and b/test/bin/data/bg4.bmp differ diff --git a/test/bin/data/rainbow.bmp b/test/bin/data/rainbow.bmp new file mode 100755 index 0000000..801ed82 Binary files /dev/null and b/test/bin/data/rainbow.bmp differ diff --git a/test/bin/data/skin1.bmp b/test/bin/data/skin1.bmp new file mode 100755 index 0000000..fe2e4f3 Binary files /dev/null and b/test/bin/data/skin1.bmp differ diff --git a/test/bin/data/slider.bmp b/test/bin/data/slider.bmp new file mode 100755 index 0000000..015a94f Binary files /dev/null and b/test/bin/data/slider.bmp differ diff --git a/test/bin/data/slider2.bmp b/test/bin/data/slider2.bmp new file mode 100755 index 0000000..13fb12a Binary files /dev/null and b/test/bin/data/slider2.bmp differ diff --git a/test/bin/data/text.bmp b/test/bin/data/text.bmp new file mode 100755 index 0000000..257162c Binary files /dev/null and b/test/bin/data/text.bmp differ diff --git a/test/gewiTest00.cpp b/test/gewiTest00.cpp new file mode 100755 index 0000000..0432a4c --- /dev/null +++ b/test/gewiTest00.cpp @@ -0,0 +1,147 @@ +/******************************************************************************* + This file is Part of the Gewi GUI Library for ZEngine. + Gewi and ZEngine Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. (see licensing.txt) + + The maintainer of this library is James Turk (james@conceptofzero.net) + this library is found at the home of ZEngine http://zengine.sourceforge.net +*******************************************************************************/ +#define _CRTDBG_MAP_ALLOC +#include +#include + +#include "ZEngine.h" +#include "GewiEngine.h" +#include "GButton.h" +#include "GTextButton.h" +#include "GWindow.h" +#include "GTextField.h" +#include "GSlider.h" +#include "GStaticText.h" +using namespace ZE; + +void Init() +{ + ZEngine *ze = ZEngine::GetInstance(); + + ZConfigFile cfg("gewiTest.zcf"); + int w,h,bpp; + bool fs; + string title; + + w = cfg.GetInt("screen","width",800); + h = cfg.GetInt("screen","height",600); + bpp = cfg.GetInt("screen","bpp",32); + fs = cfg.GetBool("screen","fullscreen",false); + title = cfg.GetString("screen","title","Gewi Test"); + + ze->SetupDisplay(w,h,bpp,fs); + ze->CreateDisplay(title); +} + +void Test1() +{ + ZEngine *ze = ZEngine::GetInstance(); + Gewi *gewi = Gewi::GetInstance(); + ZImage bg("rainbow.bmp"),buf; + ResourceID id1,id2,id3,id4,id5,id6,id7,id8,id9; + GWindow w1; + GTextButton tb1; + GTextField t1,t2(&w1); + GButton b1(&w1); + GHorizSlider s1; + GVertSlider s2; + GButton hb1(&w1); + GStaticText st1; + + bg.Resize(800,600); + + ZImage *temp,*temp2,*temp3,*temp4,*temp5,*temp6,*temp7,*temp8; + ZFont *font; + temp = new ZImage("b1.bmp"); + temp2 = new ZImage("b2.bmp"); + temp3 = new ZImage("skin1.bmp"); + temp4 = new ZImage("text.bmp"); + temp5 = new ZImage("bg3.bmp"); + temp6 = new ZImage("slider.bmp"); + temp7 = new ZImage("bg4.bmp"); + temp8 = new ZImage("slider2.bmp"); + font = new ZFont("c:\\windows\\fonts\\arial.ttf",20); + temp->SetColorKey(255,0,255); + temp2->SetColorKey(255,0,255); + temp3->SetColorKey(255,0,255); + id1 = gewi->AddResource(temp); + id2 = gewi->AddResource(temp2); + id3 = gewi->AddResource(temp3); + id4 = gewi->AddResource(font); + id5 = gewi->AddResource(temp4); + id6 = gewi->AddResource(temp5); + id7 = gewi->AddResource(temp6); + id8 = gewi->AddResource(temp7); + id9 = gewi->AddResource(temp8); + temp4->SetColorKey(255,0,255); + temp6->SetColorKey(255,0,255); + temp8->SetColorKey(255,0,255); + + w1.Create(300,300,300,300,id3); + b1.Create(50,30,10,10,id1,id2); + t1.Create(100,100,500,50,id4,id5,20,20); + t2.Create(50,200,200,50,id4,id5,20,20); + tb1.Create(400,200,300,50,id1,id2,id4,"restore window"); + s1.Create(100,500,200,50,id6,id7,0,3,1); + s2.Create(700,200,50,200,id8,id9,0,200,5); + hb1.Create(70,40,100,100,id1,id2,G_HOVER); + st1.Create(100,100,100,100,id4,Gewi::InvalidID,"static",GJ_CENTER); + + do + { + ze->CheckEvents(); + + if(ze->IsActive()) + { + if(ze->KeyIsPressed(SDLK_ESCAPE)) + ze->RequestQuit(); + + font->DrawText(FormatStr("%f",s1.GetPos()),buf); + bg.Draw(0,0); + temp3->SetAlpha(63+s1.GetPos()*64); + gewi->Display(); + + buf.Draw(0.0f,s2.GetPos()); + + if(b1.IsPressed() && w1.Visible()) + { + w1.ToggleVisible(); + tb1.SetState(false); + b1.SetState(false); + } + if(tb1.IsPressed() && !w1.Visible()) + { + w1.ToggleVisible(); + b1.SetState(false); + tb1.SetState(false); + } + if(hb1.IsPressed()) + ze->RequestQuit(); + + ze->Update(); + + } + + } while(!ze->QuitRequested()); + + Gewi::ReleaseInstance(); +} + +int main(int argc, char *argv[]) +{ +// _crtBreakAlloc=163; + Init(); + + Test1(); + + ZEngine::ReleaseInstance(); + _CrtDumpMemoryLeaks(); + return 0; +} \ No newline at end of file diff --git a/todo_release.txt b/todo_release.txt new file mode 100755 index 0000000..9b43f09 --- /dev/null +++ b/todo_release.txt @@ -0,0 +1 @@ +make source files conform \ No newline at end of file diff --git a/vc7/gewi.sln b/vc7/gewi.sln new file mode 100755 index 0000000..5a489b3 --- /dev/null +++ b/vc7/gewi.sln @@ -0,0 +1,23 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gewi", "gewi.vcproj", "{3B6AA6AE-01BC-470E-AAB1-3A76C252D3C3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gewitest", "gewitest.vcproj", "{F5974221-8DB8-4BC1-B944-EE62F44A9114}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + {F5974221-8DB8-4BC1-B944-EE62F44A9114}.0 = {3B6AA6AE-01BC-470E-AAB1-3A76C252D3C3} + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {3B6AA6AE-01BC-470E-AAB1-3A76C252D3C3}.Release.ActiveCfg = Release|Win32 + {3B6AA6AE-01BC-470E-AAB1-3A76C252D3C3}.Release.Build.0 = Release|Win32 + {F5974221-8DB8-4BC1-B944-EE62F44A9114}.Release.ActiveCfg = Release|Win32 + {F5974221-8DB8-4BC1-B944-EE62F44A9114}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/vc7/gewi.vcproj b/vc7/gewi.vcproj new file mode 100755 index 0000000..17ed06f --- /dev/null +++ b/vc7/gewi.vcproj @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vc7/gewitest.vcproj b/vc7/gewitest.vcproj new file mode 100755 index 0000000..b555229 --- /dev/null +++ b/vc7/gewitest.vcproj @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +