Planeshift
pawsmanager.h
Go to the documentation of this file.
1 /*
2  * pawsmanager.h - Author: Andrew Craig
3  *
4  * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  *
19  * pawsmanager.h: interface for the PawsManager class.
20  *
21  *----------------------------------------------------------------------------
22  */
23 
24 #ifndef PAWS_MANAGER_HEADER
25 #define PAWS_MANAGER_HEADER
26 
27 #include <csutil/ref.h>
28 #include <csutil/parray.h>
29 #include <csutil/hash.h>
30 #include <csutil/csstring.h>
31 #include <csgeom/vector3.h>
32 
33 #include <iutil/vfs.h>
34 #include <iutil/document.h>
35 
36 #include "util/mathscript.h"
37 #include "util/log.h"
38 
39 #include "pawsmouse.h"
40 #include "psmousebinds.h"
41 #include "pawsstyles.h"
42 
43 struct iObjectRegistry;
44 struct iGraphics2D;
45 struct iGraphics3D;
46 struct iXWindow;
47 struct iEvent;
48 class psLocalization;
49 
50 struct iSoundManager;
51 
52 class pawsWidget;
53 class pawsWidgetFactory;
54 
55 class pawsMainWidget;
56 class pawsTextureManager;
57 class pawsPrefManager;
58 
59 struct iPAWSSubscriber;
60 struct PAWSData;
61 struct PAWSSubscription;
62 
67 typedef csHash<PAWSSubscription*,csString> PAWSSubscriptionsHash;
68 
69 #if defined(CS_PLATFORM_UNIX) && defined(INCLUDE_CLIPBOARD)
70 
72 #define csevSelectionNotify(reg) (csEventNameRegistry::GetID((reg), "crystalspace.xwindow.clipboard.selection.notify"))
73 
74 #endif
75 
76 #define CONFIG_TOOLTIPS_FILE_NAME "/planeshift/userdata/options/tooltips.xml"
77 #define CONFIG_TOOLTIPS_FILE_NAME_DEF "/planeshift/data/options/tooltips_def.xml"
78 
82 class PawsManager : public Singleton<PawsManager>
83 {
84 public:
85 
86  PawsManager(iObjectRegistry* objectReg, const char* skin, const char* skinBase = NULL);
87 
88  virtual ~PawsManager();
89 
91  void SetMainWidget(pawsMainWidget* widg);
92 
96  bool HandleEvent(iEvent &event);
97 
100  void Draw();
101 
104  void Draw3D();
105 
107  iGraphics2D* GetGraphics2D()
108  {
109  return graphics2D;
110  }
111 
113  iGraphics3D* GetGraphics3D()
114  {
115  return graphics3D;
116  }
117 
119  iObjectRegistry* GetObjectRegistry()
120  {
121  return objectReg;
122  }
123 
125  iEventNameRegistry* GetEventNameRegistry()
126  {
127  return nameRegistry;
128  }
129 
132  {
133  return textureManager;
134  }
135 
136  void UseR2T(bool r2t)
137  {
138  render2texture = r2t;
139  }
140 
141  bool UsingR2T() const
142  {
143  return render2texture;
144  }
145 
147  bool LoadSkinDefinition(const char* zip);
148 
156 
165  bool LoadWidget(const char* widgetFile);
166 
175  pawsWidget* LoadWidgetFromString(const char* widgetDefinition);
176 
177 
181  pawsWidget* LoadWidget(iDocumentNode* widgetNode);
182 
195  bool LoadChildWidgets(const char* widgetFile, csArray<pawsWidget*> &loadedWidgets);
196 
197 
206  pawsWidget* CreateWidget(const char* factoryName);
207 
217  pawsWidget* CreateWidget(const char* factoryName, const pawsWidget* origin);
218 
220  void AddObjectView(pawsWidget* widget)
221  {
222  objectViews.Push(widget);
223  }
224 
225  bool LoadObjectViews();
226 
229  {
230  objectViews.Delete(widget);
231  }
232 
235  {
236  return currentFocusedWidget;
237  }
238 
241  {
242  return focusOverridesControls;
243  }
244 
247  {
248  return modalWidget;
249  }
250 
254  void SetCurrentFocusedWidget(pawsWidget* widget);
255 
259  void SetModalWidget(pawsWidget* widget);
260 
264  void OnWidgetDeleted(pawsWidget* widget);
265 
267  void OnWidgetHidden(pawsWidget* widget);
268 
272  void MovingWidget(pawsWidget* moving);
273 
278  void ResizingWidget(pawsWidget* widget, int flags);
279 
282  {
283  return prefs;
284  }
285 
288  {
289  return mouse;
290  }
291 
294  {
295  return resizeImg;
296  }
297 
304  pawsWidget* FindWidget(const char* name, bool complain=true);
305 
313  bool RemoveWidget(const char* widgetName, bool complain);
314 
317  {
318  return mainWidget;
319  }
320 
323  {
324  return localization;
325  }
326 
328  csString Translate(const csString &orig);
329 
338 
346 
351  {
352  return fontFactor;
353  };
354 
360  void CreateWarningBox(const char* message, pawsWidget* notify = NULL, bool modal = true);
361 
370  void CreateYesNoBox(const char* message, pawsWidget* notify = NULL, bool modal = true, bool translate = true);
371 
375  bool ApplyStyle(const char* name, iDocumentNode* target);
376 
377  /* ToolTips Functions/Variables
378  ------------------------------------------------------------------------*/
379  int TooltipsColors[3];
382 
384  bool LoadTooltips(const char* fileName);
386  csString getToolTipSkinPath();
389  {
390  return ToolTipEnable;
391  };
393  void setToolTipEnable(bool state)
394  {
395  ToolTipEnable = state;
396  };
399  {
400  return ToolTipEnableBgColor;
401  };
403  void setToolTipEnableBgColor(bool state)
404  {
405  ToolTipEnableBgColor = state;
406  };
408  int getTooltipsColors(int element)
409  {
410  return TooltipsColors[element];
411  };
413  void setTooltipsColors(int element, int param)
414  {
415  TooltipsColors[element] = param;
416  };
417 
418  /* Sound Functions
419  ------------------------------------------------------------------------*/
420 
422  iSoundManager* GetSoundManager()
423  {
424  return soundManager;
425  };
426 
427  /* Subcription Functions
428  ------------------------------------------------------------------------*/
429 
431  void UnSubscribe(iPAWSSubscriber* listener);
432 
434  void Subscribe(const char* dataname,iPAWSSubscriber* listener);
435 
437  void Publish(const csString &dataname,PAWSData &data);
438 
440  void Publish(const csString &dataname,const char* datavalue);
441 
443  void Publish(const csString &dataname,bool datavalue);
444 
446  void Publish(const csString &dataname,int datavalue);
447 
449  void Publish(const csString &dataname,unsigned int datavalue);
450 
452  void Publish(const csString &dataname,float datavalue);
453 
455  void Publish(const csString &dataname, const char* datavalue, int color);
456 
458  void Publish(const csString &dataname);
459 
461  csArray<iPAWSSubscriber*> ListSubscribers(const char* dataname);
462 
464  {
465  return extraScriptVars;
466  }
467 
468  csString &getVFSPathToSkin()
469  {
470  return vfsPathToSkin;
471  }
472 
473 #if defined(CS_PLATFORM_UNIX) && defined(INCLUDE_CLIPBOARD)
474 
478  void RequestClipboardContent();
479 #endif
480 
481 protected:
483 
484  psPoint MouseLocation(iEvent &ev);
485 
487  csString vfsPathToSkin;
488 
491 
494 
497 
500 
503 
506 
508  csTicks timeOver;
509 
511  int tipDelay;
512 
515 
518 
521 
524 
526  void RegisterFactories();
527 
536  bool HandleMouseMove(csMouseEventData &data);
537 
546  bool HandleMouseDown(csMouseEventData &data);
547 
548 
557  bool HandleDoubleClick(csMouseEventData &data);
558 
568  bool HandleMouseUp(csMouseEventData &data);
569 
581  bool HandleKeyDown(iEvent &event);
582 
583 #if defined(CS_PLATFORM_UNIX) && defined(INCLUDE_CLIPBOARD)
584 
593  bool HandleSelectionNotify(iEvent &event);
594 #endif
595 
598  iObjectRegistry* objectReg;
599 
603  csRef<iGraphics2D> graphics2D;
604 
608  csRef<iGraphics3D> graphics3D;
609 
612  csRef<iEventNameRegistry> nameRegistry;
613 
616 
618  csArray<pawsWidget*> objectViews;
619 
622 
625 
627  csRef<iPawsImage> resizeImg;
628 
630  csPDelArray<pawsWidgetFactory> factories;
631 
633  csRef<iVFS> vfs;
634 
636  csRef<iDocumentSystem> xml;
637 
640 
642  csRef<iTextureHandle> guiTexture;
643 
646 
654 
656  float fontFactor;
657 
658 
659  /* Sound Member Variables
660  ------------------------------------------------------------------------*/
661 
662  csRef<iSoundManager> soundManager;
663 
669  csPtr<iDocumentNode> ParseWidgetFile(const char* widgetFile);
670 
673 
676 
677 
678  /* Shortcuts for events
679  ------------------------------------------------------------------------*/
681  csEventID MouseMove;
683  csEventID MouseDown;
685  csEventID MouseDoubleClick;
687  csEventID MouseUp;
689  csEventID KeyboardDown;
691  csEventID KeyboardUp;
692 
693  /* X Clipboard
694  ------------------------------------------------------------------------*/
695 #if defined(CS_PLATFORM_UNIX) && defined(INCLUDE_CLIPBOARD)
696  csRef<iXWindow> xwin;
697 
699  csEventID SelectionNotifyEvent;
700 
701 #endif
702 };
703 
704 
707 {
715 };
716 
717 
718 struct PAWSData
719 {
720  static csString temp_buffer;
721 
723  union
724  {
725  int intval;
726  unsigned int uintval;
727  float floatval;
728  bool boolval;
729  };
730  csString str; //csString cannot be inside union
731 
733  {
734  type=PAWS_DATA_UNKNOWN;
735  }
737  {
738  type = other.type;
739  intval = other.intval;
740  str = other.str;
741  return *this;
742  }
743 
744  bool IsData()
745  {
746  return type != PAWS_DATA_UNKNOWN;
747  }
748 
749  const char* GetStr();
750  float GetFloat();
751  int GetInt();
752  unsigned int GetUInt();
753  bool GetBool();
754 };
755 
756 
758 {
759  virtual void OnUpdateData(const char* name,PAWSData &data) = 0;
760  virtual void NewSubscription(const char* name) = 0;
761  virtual ~iPAWSSubscriber() {};
762 };
763 
765 {
768 };
769 
772 #endif
773 
774 
775 
iSoundManager * GetSoundManager()
Gets the soundManager.
Definition: pawsmanager.h:422
void Publish(const csString &dataname, PAWSData &data)
Announce a change in a named element to all subscribers.
pawsMainWidget * GetMainWidget()
Returns the main widget.
Definition: pawsmanager.h:316
pawsWidget * resizingWidget
Holds the widget that is being resized.
Definition: pawsmanager.h:520
iObjectRegistry * objectReg
The object registry.
Definition: pawsmanager.h:598
int resizingFlags
The resize flags.
Definition: pawsmanager.h:523
csEventID KeyboardUp
Shortcut for event key up.
Definition: pawsmanager.h:691
iObjectRegistry * GetObjectRegistry()
Returns the object registry.
Definition: pawsmanager.h:119
pawsMouse * mouse
The mouse pointer.
Definition: pawsmanager.h:624
The main base widget that all other widgets should inherit from.
Definition: pawswidget.h:116
pawsWidget * GetCurrentFocusedWidget()
Returns the widget that is focused.
Definition: pawsmanager.h:234
pawsMainWidget * mainWidget
The main handler widget.
Definition: pawsmanager.h:615
pawsWidget * GetModalWidget()
Returns modal widget.
Definition: pawsmanager.h:246
csRef< iTextureHandle > guiTexture
Render texture for gui rendering.
Definition: pawsmanager.h:642
csRef< iPawsImage > resizeImg
Resized image.
Definition: pawsmanager.h:627
bool GetFocusOverridesControls()
Returns true if the current focused widget needs to override all controls.
Definition: pawsmanager.h:240
void CreateWarningBox(const char *message, pawsWidget *notify=NULL, bool modal=true)
Creates a warning box with the supplied text.
void RemoveObjectView(pawsWidget *widget)
Removes an object view from the array.
Definition: pawsmanager.h:228
A specific MathEnvironment to be used in a MathScript.
Definition: mathscript.h:188
PAWSSubscriptionsHash subscriptions
Table of subscriptions.
Definition: pawsmanager.h:675
bool LoadSkinDefinition(const char *zip)
Loads a skin and loades unregistered resources.
float floatval
Definition: pawsmanager.h:727
bool HandleEvent(iEvent &event)
Process mouse and keyboard events.
pawsWidget * FindWidget(const char *name, bool complain=true)
Locate a widget by name.
csRef< iEventNameRegistry > nameRegistry
For event parsing.
Definition: pawsmanager.h:612
pawsPrefManager * GetPrefs()
Returns the prefrence manager.
Definition: pawsmanager.h:281
Main PlaneShift Window manager.
Definition: pawsmanager.h:82
bool UsingR2T() const
Definition: pawsmanager.h:141
iPAWSSubscriber * subscriber
Definition: pawsmanager.h:767
pawsMouse * GetMouse()
Returns the mouse.
Definition: pawsmanager.h:287
void MovingWidget(pawsWidget *moving)
Let the window manager know that a widget is being moved.
virtual ~PawsManager()
virtual ~iPAWSSubscriber()
Definition: pawsmanager.h:761
PAWSDATATYPE
Data types for pub/sub.
Definition: pawsmanager.h:706
void SetDragDropWidget(pawsWidget *dragDropWidget)
Sets the widget that is being drag&#39;n&#39;dropped over screen with the mouse.
The mouse pointer.
Definition: pawsmouse.h:41
pawsWidget * currentFocusedWidget
The last widget that the mouse clicked on. ( Hence the focused one ).
Definition: pawsmanager.h:496
csRef< iVFS > vfs
Pointer to the Crystal Space iVFS file system.
Definition: pawsmanager.h:633
csEventID MouseUp
Shortcut for event mouse up.
Definition: pawsmanager.h:687
PAWSData lastKnownValue
Definition: pawsmanager.h:766
pawsWidget * GetDragDropWidget()
Gets the widget that is being drag&#39;n&#39;dropped over screen with the mouse.
float GetFontFactor()
Gets the factor the font should be adjusted by for proper fontsize based on resolution.
Definition: pawsmanager.h:350
pawsStyles * styles
PAWS style definitions.
Definition: pawsmanager.h:672
void UseR2T(bool r2t)
Definition: pawsmanager.h:136
bool HandleDoubleClick(csMouseEventData &data)
Process mouse double click events.
static csString temp_buffer
Definition: pawsmanager.h:720
void ResizingWidget(pawsWidget *widget, int flags)
Let the manager know that a widget is being resized.
int TooltipsColors[3]
Array of tooltip colors.
Definition: pawsmanager.h:379
int getTooltipsColors(int element)
returns one element of the TooltipsColors-array
Definition: pawsmanager.h:408
csTicks timeOver
The time mouse has been over the last widget.
Definition: pawsmanager.h:508
Class pawsStyles keeps definitions of PAWS styles - a PAWS style is collection of XML attributes and ...
Definition: pawsstyles.h:67
bool LoadObjectViews()
bool LoadWidget(const char *widgetFile)
Loads a widget definition file.
pawsTextureManager * textureManager
The texture manager.
Definition: pawsmanager.h:621
void CreateYesNoBox(const char *message, pawsWidget *notify=NULL, bool modal=true, bool translate=true)
Creates a YesNo box with the supplied text.
bool HandleKeyDown(iEvent &event)
Process key down events.
pawsWidget * LoadWidgetFromString(const char *widgetDefinition)
Loads a widget definition from a string.
bool hadKeyDown
Flag for key down function.
Definition: pawsmanager.h:639
bool ToolTipEnable
Sets if the tooltip should be enable.
Definition: pawsmanager.h:380
csString Translate(const csString &orig)
A shortcut - translation without need to call GetLocalization().
csArray< iPAWSSubscriber * > ListSubscribers(const char *dataname)
Return a list of all subscribers.
bool ToolTipEnableBgColor
Sets if the tooltip should have a bgcolor.
Definition: pawsmanager.h:381
bool focusOverridesControls
Does the currentFocusedWidget take focus from the control system?
Definition: pawsmanager.h:499
iPawsImage * GetResizeImage()
Returns the resize button image.
Definition: pawsmanager.h:293
bool render2texture
Whether to use r2t for the gui.
Definition: pawsmanager.h:645
void setToolTipEnableBgColor(bool state)
changes tooltips backround enabled/disabled
Definition: pawsmanager.h:403
void SetCurrentFocusedWidget(pawsWidget *widget)
Give this widget focus.
csPDelArray< pawsWidgetFactory > factories
An array of pointers to available factories.
Definition: pawsmanager.h:630
void OnWidgetDeleted(pawsWidget *widget)
pawsWidget destructor calls this so PawsManager can NULLify all its links to the widget.
csRef< iGraphics3D > graphics3D
Pointer to the Crystal Space iGraphics3D renderer used to display 3D graphics.
Definition: pawsmanager.h:608
PAWSData & operator=(PAWSData &other)
Definition: pawsmanager.h:736
void setToolTipEnable(bool state)
changes tooltips enabled/disabled
Definition: pawsmanager.h:393
pawsPrefManager * prefs
The preference/default manager.
Definition: pawsmanager.h:493
float fontFactor
The font resizing factor for all widgets.
Definition: pawsmanager.h:656
psLocalization * GetLocalization()
Returns the psLocalization object:
Definition: pawsmanager.h:322
csString str
Definition: pawsmanager.h:730
csString & getVFSPathToSkin()
Definition: pawsmanager.h:468
csHash< PAWSSubscription *, csString > PAWSSubscriptionsHash
Definition: pawsmanager.h:67
pawsWidget * modalWidget
Current modal widget.
Definition: pawsmanager.h:517
pawsWidget * mouseoverWidget
The last widget that the mouse moved over. ( For alpha fade effects ).
Definition: pawsmanager.h:502
psLocalization * localization
Localized file object registry.
Definition: pawsmanager.h:490
bool ApplyStyle(const char *name, iDocumentNode *target)
Applies PAWS style to XML node.
The main or desktop widget.
pawsTextureManager * GetTextureManager()
Returns the texture manager.
Definition: pawsmanager.h:131
pawsWidget * lastfadeWidget
The actual widget that was last faded.
Definition: pawsmanager.h:505
csPtr< iDocumentNode > ParseWidgetFile(const char *widgetFile)
Parses given file and returns the <widget_description> tag of it.
Localization class for languages.
Definition: localization.h:45
csEventID MouseDoubleClick
Shortcut for event mouse double click.
Definition: pawsmanager.h:685
bool HandleMouseDown(csMouseEventData &data)
Process mouse down events.
csRef< iGraphics2D > graphics2D
Pointer to the Crystal Space iGraphics2D renderer used to display 2D graphics.
Definition: pawsmanager.h:603
psPoint MouseLocation(iEvent &ev)
unsigned int uintval
Definition: pawsmanager.h:726
int intval
Definition: pawsmanager.h:725
MathEnvironment & ExtraScriptVars()
Definition: pawsmanager.h:463
void SetMainWidget(pawsMainWidget *widg)
Establish main widget.
bool RemoveWidget(const char *widgetName, bool complain)
Remove the named widget from the mainwidget.
bool boolval
Definition: pawsmanager.h:728
PAWSDATATYPE type
Definition: pawsmanager.h:722
iGraphics2D * GetGraphics2D()
Returns the 2D renderer.
Definition: pawsmanager.h:107
iGraphics3D * GetGraphics3D()
Returns the 3D renderer.
Definition: pawsmanager.h:113
pawsWidget * movingWidget
Current widget that is being moved.
Definition: pawsmanager.h:514
void AddObjectView(pawsWidget *widget)
Adds an object view to the array.
Definition: pawsmanager.h:220
csEventID KeyboardDown
Shortcut for event key down.
Definition: pawsmanager.h:689
csEventID MouseDown
Shortcut for event mouse down.
Definition: pawsmanager.h:683
bool LoadTooltips(const char *fileName)
Loads the Tooltips config-file.
Holds/Loads the prefs from a pref file.
void Draw()
Draw the main widget and the mouse last.
bool IsData()
Definition: pawsmanager.h:744
pawsWidget * dragDropWidget
The widget that is drag&#39;n&#39;dropped across the screen by the mouse.
Definition: pawsmanager.h:653
void Draw3D()
Draw 3D parts of the widgets.
void UnSubscribe(iPAWSSubscriber *listener)
Unsubscribe the given subscriber.
MathEnvironment extraScriptVars
Definition: pawsmanager.h:482
void OnWidgetHidden(pawsWidget *widget)
Remove focus and mouseover effect from widget if widget is hidden.
void setTooltipsColors(int element, int param)
transfers a value to the TooltipsColors-array
Definition: pawsmanager.h:413
void RegisterFactories()
Helper function to load standard factories.
bool HandleMouseMove(csMouseEventData &data)
Process mouse movement events.
csString getToolTipSkinPath()
returns the full path to the tooltips.xml in skin.zip
pawsWidget * CreateWidget(const char *factoryName)
Create a new widget.
csString vfsPathToSkin
VFS Mount directory mapping to the specified skin zip file.
Definition: pawsmanager.h:487
bool LoadChildWidgets(const char *widgetFile, csArray< pawsWidget * > &loadedWidgets)
Loads widgets from a definition file without assigning a parent.
void SetModalWidget(pawsWidget *widget)
Make this widget modal.
csRef< iDocumentSystem > xml
Pointer to the Crystal Space iDocumentSystem.
Definition: pawsmanager.h:636
bool HandleMouseUp(csMouseEventData &data)
Process mouse up events.
csRef< iSoundManager > soundManager
planeshift&#39;s sound manager
Definition: pawsmanager.h:662
csArray< pawsWidget * > objectViews
Array of paws object view widgets;.
Definition: pawsmanager.h:618
int tipDelay
The time mouse has been over a widget before showing the tooltip.
Definition: pawsmanager.h:511
bool getToolTipEnable()
returns tooltips enabled/disabled
Definition: pawsmanager.h:388
void Subscribe(const char *dataname, iPAWSSubscriber *listener)
Subscribe to a named piece of data, so updates are received automatically.
void RegisterWidgetFactory(pawsWidgetFactory *factory)
Add a new factory to the list that the manager knows about.
csEventID MouseMove
Shortcut for event mouse move.
Definition: pawsmanager.h:681
bool getToolTipEnableBgColor()
returns tooltips brackground color
Definition: pawsmanager.h:398
PawsManager(iObjectRegistry *objectReg, const char *skin, const char *skinBase=NULL)
iEventNameRegistry * GetEventNameRegistry()
Get the event name registry.
Definition: pawsmanager.h:125