Planeshift

pawsmanager.h

Go to the documentation of this file.
00001 /*
00002  * pawsmanager.h - Author: Andrew Craig
00003  *
00004  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  *
00019  * pawsmanager.h: interface for the PawsManager class.
00020  *
00021  *----------------------------------------------------------------------------
00022  */
00023 
00024 #ifndef PAWS_MANAGER_HEADER
00025 #define PAWS_MANAGER_HEADER
00026 
00027 #include <csutil/ref.h>
00028 #include <csutil/parray.h>
00029 #include <csutil/hash.h>
00030 #include <csutil/csstring.h>
00031 #include <csgeom/vector3.h>
00032 
00033 #include <iutil/vfs.h>
00034 #include <iutil/document.h>
00035 
00036 #include "util/mathscript.h"
00037 #include "util/log.h"
00038 
00039 #include "pawsmouse.h"
00040 #include "psmousebinds.h"
00041 #include "pawsstyles.h"
00042 
00043 struct iObjectRegistry;
00044 struct iGraphics2D;
00045 struct iGraphics3D;
00046 struct iXWindow;
00047 struct iEvent;
00048 class psLocalization;
00049 
00050 struct iSoundManager;
00051 
00052 class pawsWidget;
00053 class pawsWidgetFactory;
00054 
00055 class pawsMainWidget;
00056 class pawsTextureManager;
00057 class pawsPrefManager;
00058 
00059 struct iPAWSSubscriber;
00060 struct PAWSData;
00061 struct PAWSSubscription;
00062 
00067 typedef csHash<PAWSSubscription*,csString> PAWSSubscriptionsHash;
00068 
00069 #if defined(CS_PLATFORM_UNIX) && defined(INCLUDE_CLIPBOARD)
00070 
00072 #define csevSelectionNotify(reg) (csEventNameRegistry::GetID((reg), "crystalspace.xwindow.clipboard.selection.notify"))
00073 
00074 #endif
00075 
00076 #define CONFIG_TOOLTIPS_FILE_NAME       "/planeshift/userdata/options/tooltips.xml"
00077 #define CONFIG_TOOLTIPS_FILE_NAME_DEF   "/planeshift/data/options/tooltips_def.xml"
00078 
00082 class PawsManager : public Singleton<PawsManager>
00083 {
00084 public:
00085 
00086     PawsManager(iObjectRegistry* objectReg, const char* skin, const char* skinBase = NULL);
00087 
00088     virtual ~PawsManager();
00089 
00091     void SetMainWidget(pawsMainWidget* widg);
00092 
00096     bool HandleEvent(iEvent &event);
00097 
00100     void Draw();
00101 
00104     void Draw3D();
00105 
00107     iGraphics2D* GetGraphics2D()
00108     {
00109         return graphics2D;
00110     }
00111 
00113     iGraphics3D* GetGraphics3D()
00114     {
00115         return graphics3D;
00116     }
00117 
00119     iObjectRegistry* GetObjectRegistry()
00120     {
00121         return objectReg;
00122     }
00123 
00125     iEventNameRegistry* GetEventNameRegistry()
00126     {
00127         return nameRegistry;
00128     }
00129 
00131     pawsTextureManager* GetTextureManager()
00132     {
00133         return textureManager;
00134     }
00135 
00136     void UseR2T(bool r2t)
00137     {
00138         render2texture = r2t;
00139     }
00140 
00141     bool UsingR2T() const
00142     {
00143         return render2texture;
00144     }
00145 
00147     bool LoadSkinDefinition(const char* zip);
00148 
00155     void RegisterWidgetFactory(pawsWidgetFactory* factory);
00156 
00165     bool LoadWidget(const char* widgetFile);
00166 
00175     pawsWidget* LoadWidgetFromString(const char* widgetDefinition);
00176 
00177 
00181     pawsWidget* LoadWidget(iDocumentNode* widgetNode);
00182 
00195     bool LoadChildWidgets(const char* widgetFile, csArray<pawsWidget*> &loadedWidgets);
00196 
00197 
00206     pawsWidget* CreateWidget(const char* factoryName);
00207 
00217     pawsWidget* CreateWidget(const char* factoryName, const pawsWidget* origin);
00218 
00220     void AddObjectView(pawsWidget* widget)
00221     {
00222         objectViews.Push(widget);
00223     }
00224 
00225     bool LoadObjectViews();
00226 
00228     void RemoveObjectView(pawsWidget* widget)
00229     {
00230         objectViews.Delete(widget);
00231     }
00232 
00234     pawsWidget* GetCurrentFocusedWidget()
00235     {
00236         return currentFocusedWidget;
00237     }
00238 
00240     bool GetFocusOverridesControls()
00241     {
00242         return focusOverridesControls;
00243     }
00244 
00246     pawsWidget* GetModalWidget()
00247     {
00248         return modalWidget;
00249     }
00250 
00254     void SetCurrentFocusedWidget(pawsWidget* widget);
00255 
00259     void SetModalWidget(pawsWidget* widget);
00260 
00264     void OnWidgetDeleted(pawsWidget* widget);
00265 
00267     void OnWidgetHidden(pawsWidget* widget);
00268 
00272     void MovingWidget(pawsWidget* moving);
00273 
00278     void ResizingWidget(pawsWidget* widget, int flags);
00279 
00281     pawsPrefManager* GetPrefs()
00282     {
00283         return prefs;
00284     }
00285 
00287     pawsMouse* GetMouse()
00288     {
00289         return mouse;
00290     }
00291 
00293     iPawsImage* GetResizeImage()
00294     {
00295         return resizeImg;
00296     }
00297 
00304     pawsWidget* FindWidget(const char* name, bool complain=true);
00305 
00313     bool RemoveWidget(const char* widgetName, bool complain);
00314 
00316     pawsMainWidget* GetMainWidget()
00317     {
00318         return mainWidget;
00319     }
00320 
00322     psLocalization* GetLocalization()
00323     {
00324         return localization;
00325     }
00326 
00328     csString Translate(const csString &orig);
00329 
00337     pawsWidget* GetDragDropWidget();
00338 
00345     void SetDragDropWidget(pawsWidget* dragDropWidget);
00346 
00350     float GetFontFactor()
00351     {
00352         return fontFactor;
00353     };
00354 
00360     void CreateWarningBox(const char* message, pawsWidget* notify = NULL, bool modal = true);
00361 
00370     void CreateYesNoBox(const char* message, pawsWidget* notify = NULL, bool modal = true, bool translate = true);
00371 
00375     bool ApplyStyle(const char* name, iDocumentNode* target);
00376 
00377     /*                          ToolTips Functions/Variables
00378     ------------------------------------------------------------------------*/
00379     int  TooltipsColors[3];      
00380     bool ToolTipEnable;          
00381     bool ToolTipEnableBgColor;   
00382 
00384     bool LoadTooltips(const char* fileName);
00386     csString getToolTipSkinPath();
00388     bool getToolTipEnable()
00389     {
00390         return ToolTipEnable;
00391     };
00393     void setToolTipEnable(bool state)
00394     {
00395         ToolTipEnable = state;
00396     };
00398     bool getToolTipEnableBgColor()
00399     {
00400         return ToolTipEnableBgColor;
00401     };
00403     void setToolTipEnableBgColor(bool state)
00404     {
00405         ToolTipEnableBgColor = state;
00406     };
00408     int getTooltipsColors(int element)
00409     {
00410         return TooltipsColors[element];
00411     };
00413     void setTooltipsColors(int element, int param)
00414     {
00415         TooltipsColors[element] = param;
00416     };
00417 
00418     /*                          Sound Functions
00419     ------------------------------------------------------------------------*/
00420 
00422     iSoundManager* GetSoundManager()
00423     {
00424         return soundManager;
00425     };
00426 
00427     /*                       Subcription Functions
00428     ------------------------------------------------------------------------*/
00429 
00431     void UnSubscribe(iPAWSSubscriber* listener);
00432 
00434     void Subscribe(const char* dataname,iPAWSSubscriber* listener);
00435 
00437     void Publish(const csString &dataname,PAWSData &data);
00438 
00440     void Publish(const csString &dataname,const char* datavalue);
00441 
00443     void Publish(const csString &dataname,bool  datavalue);
00444 
00446     void Publish(const csString &dataname,int   datavalue);
00447 
00449     void Publish(const csString &dataname,unsigned int   datavalue);
00450 
00452     void Publish(const csString &dataname,float datavalue);
00453 
00455     void Publish(const csString &dataname, const char* datavalue, int color);
00456 
00458     void Publish(const csString &dataname);
00459 
00461     csArray<iPAWSSubscriber*> ListSubscribers(const char* dataname);
00462 
00463     MathEnvironment &ExtraScriptVars()
00464     {
00465         return extraScriptVars;
00466     }
00467 
00468     csString &getVFSPathToSkin()
00469     {
00470         return vfsPathToSkin;
00471     }
00472 
00473 #if defined(CS_PLATFORM_UNIX) && defined(INCLUDE_CLIPBOARD)
00474 
00478     void RequestClipboardContent();
00479 #endif
00480 
00481 protected:
00482     MathEnvironment extraScriptVars;
00483 
00484     psPoint MouseLocation(iEvent &ev);
00485 
00487     csString vfsPathToSkin;
00488 
00490     psLocalization* localization;
00491 
00493     pawsPrefManager* prefs;
00494 
00496     pawsWidget* currentFocusedWidget;
00497 
00499     bool focusOverridesControls;
00500 
00502     pawsWidget* mouseoverWidget;
00503 
00505     pawsWidget* lastfadeWidget;
00506 
00508     csTicks timeOver;
00509 
00511     int tipDelay;
00512 
00514     pawsWidget* movingWidget;
00515 
00517     pawsWidget* modalWidget;
00518 
00520     pawsWidget* resizingWidget;
00521 
00523     int resizingFlags;
00524 
00526     void RegisterFactories();
00527 
00536     bool HandleMouseMove(csMouseEventData &data);
00537 
00546     bool HandleMouseDown(csMouseEventData &data);
00547 
00548 
00557     bool HandleDoubleClick(csMouseEventData &data);
00558 
00568     bool HandleMouseUp(csMouseEventData &data);
00569 
00581     bool HandleKeyDown(iEvent &event);
00582 
00583 #if defined(CS_PLATFORM_UNIX) && defined(INCLUDE_CLIPBOARD)
00584 
00593     bool HandleSelectionNotify(iEvent &event);
00594 #endif
00595 
00598     iObjectRegistry* objectReg;
00599 
00603     csRef<iGraphics2D> graphics2D;
00604 
00608     csRef<iGraphics3D> graphics3D;
00609 
00612     csRef<iEventNameRegistry> nameRegistry;
00613 
00615     pawsMainWidget* mainWidget;
00616 
00618     csArray<pawsWidget*> objectViews;
00619 
00621     pawsTextureManager* textureManager;
00622 
00624     pawsMouse* mouse;
00625 
00627     csRef<iPawsImage> resizeImg;
00628 
00630     csPDelArray<pawsWidgetFactory> factories;
00631 
00633     csRef<iVFS> vfs;
00634 
00636     csRef<iDocumentSystem>  xml;
00637 
00639     bool hadKeyDown;
00640 
00642     csRef<iTextureHandle> guiTexture;
00643 
00645     bool render2texture;
00646 
00653     pawsWidget* dragDropWidget;
00654 
00656     float fontFactor;
00657 
00658 
00659     /*                      Sound Member Variables
00660     ------------------------------------------------------------------------*/
00661 
00662     csRef<iSoundManager> soundManager;  
00663 
00669     csPtr<iDocumentNode> ParseWidgetFile(const char* widgetFile);
00670 
00672     pawsStyles* styles;
00673 
00675     PAWSSubscriptionsHash subscriptions;
00676 
00677 
00678     /*                      Shortcuts for events
00679     ------------------------------------------------------------------------*/
00681     csEventID MouseMove;
00683     csEventID MouseDown;
00685     csEventID MouseDoubleClick;
00687     csEventID MouseUp;
00689     csEventID KeyboardDown;
00691     csEventID KeyboardUp;
00692 
00693     /*                      X Clipboard
00694     ------------------------------------------------------------------------*/
00695 #if defined(CS_PLATFORM_UNIX) && defined(INCLUDE_CLIPBOARD)
00696     csRef<iXWindow> xwin;
00697 
00699     csEventID SelectionNotifyEvent;
00700 
00701 #endif
00702 };
00703 
00704 
00706 enum PAWSDATATYPE
00707 {
00708     PAWS_DATA_UNKNOWN,
00709     PAWS_DATA_STR,
00710     PAWS_DATA_BOOL,
00711     PAWS_DATA_INT,
00712     PAWS_DATA_UINT,
00713     PAWS_DATA_FLOAT,
00714     PAWS_DATA_INT_STR
00715 };
00716 
00717 
00718 struct PAWSData
00719 {
00720     static csString temp_buffer;
00721 
00722     PAWSDATATYPE type;
00723     union
00724     {
00725         int intval;
00726         unsigned int uintval;
00727         float floatval;
00728         bool boolval;
00729     };
00730     csString str;  //csString cannot be inside union
00731 
00732     PAWSData()
00733     {
00734         type=PAWS_DATA_UNKNOWN;
00735     }
00736     PAWSData &operator=(PAWSData &other)
00737     {
00738         type = other.type;
00739         intval = other.intval;
00740         str = other.str;
00741         return *this;
00742     }
00743 
00744     bool IsData()
00745     {
00746         return type != PAWS_DATA_UNKNOWN;
00747     }
00748 
00749     const char* GetStr();
00750     float GetFloat();
00751     int GetInt();
00752     unsigned int GetUInt();
00753     bool GetBool();
00754 };
00755 
00756 
00757 struct iPAWSSubscriber
00758 {
00759     virtual void OnUpdateData(const char* name,PAWSData &data) = 0;
00760     virtual void NewSubscription(const char* name) = 0;
00761     virtual ~iPAWSSubscriber() {};
00762 };
00763 
00764 struct PAWSSubscription
00765 {
00766     PAWSData lastKnownValue;
00767     iPAWSSubscriber* subscriber;
00768 };
00769 
00772 #endif
00773 
00774 
00775