Initial revision
							
								
								
									
										49
									
								
								include/GewiButton.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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__
 | ||||
							
								
								
									
										51
									
								
								include/GewiContainer.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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__
 | ||||
							
								
								
									
										69
									
								
								include/GewiEngine.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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<ZImage*> mImageVec; | ||||
|         vector<ZFont*> 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__
 | ||||
							
								
								
									
										36
									
								
								include/GewiIncludes.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \author James Turk | ||||
| **/ | ||||
| 
 | ||||
| #ifndef __gewiincludes_h__ | ||||
| #define __gewiincludes_h__ | ||||
| 
 | ||||
| #include <vector> | ||||
| #include <cmath> | ||||
| #include <limits> | ||||
| #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__
 | ||||
							
								
								
									
										63
									
								
								include/GewiSlider.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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__
 | ||||
							
								
								
									
										52
									
								
								include/GewiStaticText.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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__
 | ||||
							
								
								
									
										49
									
								
								include/GewiTextButton.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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__
 | ||||
							
								
								
									
										53
									
								
								include/GewiTextField.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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__
 | ||||
							
								
								
									
										65
									
								
								include/GewiWidget.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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__
 | ||||
							
								
								
									
										60
									
								
								include/GewiWidgetList.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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__
 | ||||
							
								
								
									
										45
									
								
								include/GewiWindow.h
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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__
 | ||||
							
								
								
									
										94
									
								
								src/GewiButton.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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<unsigned int>(rBoundRect.Width()); | ||||
|     h = static_cast<unsigned int>(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; | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										62
									
								
								src/GewiContainer.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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(); | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										190
									
								
								src/GewiEngine.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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<char>(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<char>(key.unicode); | ||||
|     else | ||||
|         ch = static_cast<char>(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<ResourceID>(mImageVec.size()-1); | ||||
| } | ||||
| 
 | ||||
| ResourceID GewiEngine::AddResource(ZFont *font) | ||||
| { | ||||
|     mFontVec.push_back(font); | ||||
|     return static_cast<ResourceID>(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); | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										134
									
								
								src/GewiSlider.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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<int>(pos) < 0.5)   //move to closest integer
 | ||||
|             rounded = static_cast<int>(floorf(pos)+rIncrement/2); | ||||
|         else | ||||
|             rounded = static_cast<int>(ceilf(pos)+rIncrement/2); | ||||
|         pos = static_cast<float>(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<char>(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<char>(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); | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										107
									
								
								src/GewiStaticText.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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<unsigned int>(rBoundRect.Width()),static_cast<unsigned int>(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<int>(rBoundRect.Width()-w)/2; | ||||
|     rYOff = static_cast<int>(rBoundRect.Height()-h)/2; | ||||
| 
 | ||||
|     if(rJustify & GJ_LEFT) | ||||
|     { | ||||
|         printf("left"); | ||||
|         rXOff = 0; | ||||
|     } | ||||
|     else if(rJustify & GJ_RIGHT) | ||||
|     { | ||||
|         printf("right"); | ||||
|         rXOff = static_cast<int>(rBoundRect.Width()-w); | ||||
|     } | ||||
| 
 | ||||
|     if(rJustify & GJ_TOP) | ||||
|     { | ||||
|         printf("top"); | ||||
|         rYOff = 0; | ||||
|     } | ||||
|     else if(rJustify & GJ_BOTTOM) | ||||
|     { | ||||
|         printf("bottom"); | ||||
|         rYOff = static_cast<int>(rBoundRect.Height()-h); | ||||
|     } | ||||
|     printf("\n"); | ||||
| } | ||||
| 
 | ||||
| string GStaticText::GetText() | ||||
| { | ||||
|     return rText; | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										66
									
								
								src/GewiTextButton.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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<int>(rBoundRect.Width()-rTextBuf.Width())/2; | ||||
|     rYOff = static_cast<int>(rBoundRect.Height()-rTextBuf.Height())/2; | ||||
| } | ||||
| 
 | ||||
| string GTextButton::GetText() | ||||
| { | ||||
|     return rText; | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										85
									
								
								src/GewiTextField.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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<size_t>(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<unsigned int>(rBoundRect.Width()),static_cast<unsigned int>(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; | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										112
									
								
								src/GewiWidget.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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<float>(x), static_cast<float>(y)); | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										176
									
								
								src/GewiWidgetList.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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); | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										77
									
								
								src/GewiWindow.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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. | ||||
|     <br>$ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $<br> | ||||
|     \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<unsigned int>(rBoundRect.Width()),static_cast<unsigned int>(rBoundRect.Height())); | ||||
|         rGewi->Image(rBackground)->Draw(rBoundRect.X(),rBoundRect.Y()); | ||||
| 
 | ||||
|         GContainer::Show();    //important that a window draws it's children
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								test/bin/data/b1.bmp
									
									
									
									
									
										Executable file
									
								
							
							
						
						| After Width: | Height: | Size: 40 KiB | 
							
								
								
									
										
											BIN
										
									
								
								test/bin/data/b2.bmp
									
									
									
									
									
										Executable file
									
								
							
							
						
						| After Width: | Height: | Size: 40 KiB | 
							
								
								
									
										
											BIN
										
									
								
								test/bin/data/bg3.bmp
									
									
									
									
									
										Executable file
									
								
							
							
						
						| After Width: | Height: | Size: 15 KiB | 
							
								
								
									
										
											BIN
										
									
								
								test/bin/data/bg4.bmp
									
									
									
									
									
										Executable file
									
								
							
							
						
						| After Width: | Height: | Size: 16 KiB | 
							
								
								
									
										
											BIN
										
									
								
								test/bin/data/rainbow.bmp
									
									
									
									
									
										Executable file
									
								
							
							
						
						| After Width: | Height: | Size: 192 KiB | 
							
								
								
									
										
											BIN
										
									
								
								test/bin/data/skin1.bmp
									
									
									
									
									
										Executable file
									
								
							
							
						
						| After Width: | Height: | Size: 192 KiB | 
							
								
								
									
										
											BIN
										
									
								
								test/bin/data/slider.bmp
									
									
									
									
									
										Executable file
									
								
							
							
						
						| After Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								test/bin/data/slider2.bmp
									
									
									
									
									
										Executable file
									
								
							
							
						
						| After Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								test/bin/data/text.bmp
									
									
									
									
									
										Executable file
									
								
							
							
						
						| After Width: | Height: | Size: 10 KiB | 
							
								
								
									
										147
									
								
								test/gewiTest00.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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 <stdlib.h> | ||||
| #include <crtdbg.h> | ||||
| 
 | ||||
| #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; | ||||
| } | ||||
							
								
								
									
										1
									
								
								todo_release.txt
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -0,0 +1 @@ | |||
| make source files conform | ||||
							
								
								
									
										23
									
								
								vc7/gewi.sln
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -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 | ||||
							
								
								
									
										128
									
								
								vc7/gewi.vcproj
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -0,0 +1,128 @@ | |||
| <?xml version="1.0" encoding = "Windows-1252"?> | ||||
| <VisualStudioProject | ||||
| 	ProjectType="Visual C++" | ||||
| 	Version="7.00" | ||||
| 	Name="gewi" | ||||
| 	ProjectGUID="{3B6AA6AE-01BC-470E-AAB1-3A76C252D3C3}" | ||||
| 	Keyword="Win32Proj"> | ||||
| 	<Platforms> | ||||
| 		<Platform | ||||
| 			Name="Win32"/> | ||||
| 	</Platforms> | ||||
| 	<Configurations> | ||||
| 		<Configuration | ||||
| 			Name="Release|Win32" | ||||
| 			OutputDirectory="Release" | ||||
| 			IntermediateDirectory="Release" | ||||
| 			ConfigurationType="4" | ||||
| 			CharacterSet="2"> | ||||
| 			<Tool | ||||
| 				Name="VCCLCompilerTool" | ||||
| 				Optimization="2" | ||||
| 				InlineFunctionExpansion="1" | ||||
| 				OmitFramePointers="TRUE" | ||||
| 				AdditionalIncludeDirectories="../include" | ||||
| 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" | ||||
| 				StringPooling="TRUE" | ||||
| 				RuntimeLibrary="2" | ||||
| 				EnableFunctionLevelLinking="TRUE" | ||||
| 				RuntimeTypeInfo="TRUE" | ||||
| 				UsePrecompiledHeader="0" | ||||
| 				WarningLevel="3" | ||||
| 				Detect64BitPortabilityProblems="TRUE" | ||||
| 				DebugInformationFormat="3"/> | ||||
| 			<Tool | ||||
| 				Name="VCCustomBuildTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCLibrarianTool" | ||||
| 				OutputFile="../lib/Gewi.lib"/> | ||||
| 			<Tool | ||||
| 				Name="VCMIDLTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCPostBuildEventTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCPreBuildEventTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCPreLinkEventTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCResourceCompilerTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCWebServiceProxyGeneratorTool"/> | ||||
| 		</Configuration> | ||||
| 	</Configurations> | ||||
| 	<Files> | ||||
| 		<Filter | ||||
| 			Name="Source Files" | ||||
| 			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiButton.cpp"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiContainer.cpp"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiEngine.cpp"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiSlider.cpp"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiStaticText.cpp"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiTextButton.cpp"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiTextField.cpp"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiWidget.cpp"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiWidgetList.cpp"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\src\GewiWindow.cpp"> | ||||
| 			</File> | ||||
| 		</Filter> | ||||
| 		<Filter | ||||
| 			Name="Header Files" | ||||
| 			Filter="h;hpp;hxx;hm;inl;inc"> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiButton.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiContainer.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiEngine.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiIncludes.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiSlider.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiStaticText.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiTextButton.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiTextField.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiWidget.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiWidgetList.h"> | ||||
| 			</File> | ||||
| 			<File | ||||
| 				RelativePath="..\include\GewiWindow.h"> | ||||
| 			</File> | ||||
| 		</Filter> | ||||
| 	</Files> | ||||
| 	<Globals> | ||||
| 	</Globals> | ||||
| </VisualStudioProject> | ||||
							
								
								
									
										80
									
								
								vc7/gewitest.vcproj
									
									
									
									
									
										Executable file
									
								
							
							
						
						|  | @ -0,0 +1,80 @@ | |||
| <?xml version="1.0" encoding = "Windows-1252"?> | ||||
| <VisualStudioProject | ||||
| 	ProjectType="Visual C++" | ||||
| 	Version="7.00" | ||||
| 	Name="gewitest" | ||||
| 	ProjectGUID="{F5974221-8DB8-4BC1-B944-EE62F44A9114}" | ||||
| 	Keyword="Win32Proj"> | ||||
| 	<Platforms> | ||||
| 		<Platform | ||||
| 			Name="Win32"/> | ||||
| 	</Platforms> | ||||
| 	<Configurations> | ||||
| 		<Configuration | ||||
| 			Name="Release|Win32" | ||||
| 			OutputDirectory="Release" | ||||
| 			IntermediateDirectory="Release" | ||||
| 			ConfigurationType="1" | ||||
| 			CharacterSet="2"> | ||||
| 			<Tool | ||||
| 				Name="VCCLCompilerTool" | ||||
| 				Optimization="2" | ||||
| 				InlineFunctionExpansion="1" | ||||
| 				OmitFramePointers="TRUE" | ||||
| 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" | ||||
| 				StringPooling="TRUE" | ||||
| 				RuntimeLibrary="2" | ||||
| 				EnableFunctionLevelLinking="TRUE" | ||||
| 				UsePrecompiledHeader="0" | ||||
| 				WarningLevel="3" | ||||
| 				Detect64BitPortabilityProblems="TRUE" | ||||
| 				DebugInformationFormat="3"/> | ||||
| 			<Tool | ||||
| 				Name="VCCustomBuildTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCLinkerTool" | ||||
| 				AdditionalOptions="SDL.lib | ||||
| SDLmain.lib | ||||
| OpenGL32.lib | ||||
| SDL_mixer.lib | ||||
| SDL_net.lib | ||||
| SDL_image.lib | ||||
| SDL_ttf.lib | ||||
| ZEngineS.lib | ||||
| c:\home\src\gewi\Release\gewi.lib" | ||||
| 				OutputFile="$(OutDir)/gewitest.exe" | ||||
| 				LinkIncremental="1" | ||||
| 				GenerateDebugInformation="TRUE" | ||||
| 				SubSystem="2" | ||||
| 				OptimizeReferences="2" | ||||
| 				EnableCOMDATFolding="2" | ||||
| 				TargetMachine="1"/> | ||||
| 			<Tool | ||||
| 				Name="VCMIDLTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCPostBuildEventTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCPreBuildEventTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCPreLinkEventTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCResourceCompilerTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCWebServiceProxyGeneratorTool"/> | ||||
| 			<Tool | ||||
| 				Name="VCWebDeploymentTool"/> | ||||
| 		</Configuration> | ||||
| 	</Configurations> | ||||
| 	<Files> | ||||
| 		<Filter | ||||
| 			Name="Source Files" | ||||
| 			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"> | ||||
| 		</Filter> | ||||
| 		<Filter | ||||
| 			Name="Header Files" | ||||
| 			Filter="h;hpp;hxx;hm;inl;inc"> | ||||
| 		</Filter> | ||||
| 	</Files> | ||||
| 	<Globals> | ||||
| 	</Globals> | ||||
| </VisualStudioProject> | ||||
 cozman
						cozman