Main Page   Class Hierarchy   Compound List   File List   Compound Members  

awsprefs.h

00001  #ifndef __AWS_PREFERENCES_H__
00002  #define __AWS_PREFERENCES_H__
00003 /**************************************************************************
00004     Copyright (C) 2000-2001 by Christopher Nelson 
00005     
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010   
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015   
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the Free
00018     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 *****************************************************************************/
00020 #include "aws/iaws.h"
00021 #include "csgeom/csrect.h"
00022 #include "csgeom/cspoint.h"
00023 #include "csutil/csdllist.h"
00024 #include "csutil/csvector.h"
00025 
00026 #include "aws/awstex.h"
00027 
00028 struct iString;
00029 
00030 /****
00031 
00032  This is the pseudo-symbol table for the definitions keeper.  Windows and their sub-keys can be looked up from here.
00033 There are a few different types of values possible for keys:  Strings, Integers, and Rects.  They can be looked up
00034 using appropriate search methods in the main preferences.  Skins and Windows are containers which hold the keys, and
00035 the prefs manager contains those skin and window defintions.  
00036  
00037  Windows can be filled in because components provide a factory service by registering, and then know how to get their
00038 settings from the window definition.
00039                                
00040  ****/
00041 
00043 
00044 const unsigned char KEY_INT  = 0;
00045 const unsigned char KEY_STR  = 1;
00046 const unsigned char KEY_RECT = 2;
00047 const unsigned char KEY_WIN  = 3;
00048 const unsigned char KEY_SKIN = 4;
00049 const unsigned char KEY_COMPONENT = 5;
00050 const unsigned char KEY_RGB  = 6;
00051 const unsigned char KEY_POINT= 7;
00052 const unsigned char KEY_CONNECTION = 8;
00053 const unsigned char KEY_CONNECTIONMAP = 9;
00054 
00055 
00057 class awsKey
00058 {
00060   unsigned long name; 
00061   //iString *name;
00062 
00063 public:
00065   awsKey(iString *n);
00066 
00068   virtual ~awsKey()         {};
00069   
00071   virtual unsigned char Type()=0;
00072 
00074   unsigned long Name() { return name; }
00075   
00076 };
00077 
00078 class awsIntKey : public awsKey
00079 {
00081   int val;
00082 
00083 public:
00085   awsIntKey(iString *name, int v):awsKey(name), val(v) {};
00086 
00088   virtual ~awsIntKey() {};
00089 
00091   virtual unsigned char Type() 
00092   { return KEY_INT; }
00093 
00095   int Value() { return val; }
00096 };
00097 
00098 class awsStringKey : public awsKey
00099 {
00101   iString *val;
00102 
00103 public:
00105   awsStringKey(iString *name, iString *v):awsKey(name), val(v) {};
00106 
00108   virtual ~awsStringKey() {};
00109 
00111   virtual unsigned char Type() 
00112   { return KEY_STR; }
00113 
00115   iString *Value() { return val; }
00116 };
00117 
00118 class awsRectKey : public awsKey
00119 {
00121   csRect val;
00122 
00123 public:
00125   awsRectKey(iString *name, csRect v):awsKey(name), val(v) {};
00126 
00128   virtual ~awsRectKey() {};
00129 
00131   virtual unsigned char Type() 
00132   { return KEY_RECT; }
00133 
00135   csRect Value() { return val; }
00136 };
00137 
00138 class awsRGBKey : public awsKey
00139 {
00140 public:
00141 
00143   struct RGB {
00144         unsigned char red, green, blue;
00145   } rgb;
00146   
00148   awsRGBKey(iString *name, unsigned char r, unsigned char g, unsigned char b):awsKey(name)
00149   { rgb.red=r; rgb.green=g; rgb.blue=b; }
00150 
00152   virtual ~awsRGBKey() {};
00153 
00155   virtual unsigned char Type() 
00156   { return KEY_RGB; }
00157 
00159   awsRGBKey::RGB& Value() { return rgb; }
00160 };
00161 
00162 class awsPointKey : public awsKey
00163 {
00165   csPoint val;
00166 
00167 public:
00169   awsPointKey(iString *name, csPoint v):awsKey(name), val(v) {};
00170 
00172   virtual ~awsPointKey() {};
00173 
00175   virtual unsigned char Type() 
00176   { return KEY_POINT; }
00177 
00179   csPoint Value() { return val; }
00180 };
00181 
00182 class awsConnectionKey : public awsKey
00183 {
00185   iAwsSink *sink;
00187   unsigned long trigger;
00189   unsigned long signal;
00190   
00191 public:
00193   awsConnectionKey(iString *name, iAwsSink *s, unsigned long t, unsigned long sig):
00194       awsKey(name), sink(s), trigger(t), signal(sig) {};
00195 
00197   virtual ~awsConnectionKey() {};
00198 
00200   virtual unsigned char Type() 
00201   { return KEY_CONNECTION; }
00202 
00204   iAwsSink *Sink() { return sink; }
00205   
00207   unsigned long Trigger() { return trigger; }
00208 
00210   unsigned long Signal()  { return signal;  }
00211 };
00212 
00213 
00215 
00216 class awsKeyContainer 
00217 {
00219   csBasicVector children;
00220 
00221 public:
00222   awsKeyContainer() {};
00223   virtual ~awsKeyContainer() {};
00224 
00225 public:
00227   awsKey *Find(iString *name);
00228 
00230   awsKey *Find(unsigned long id);
00231    
00232   csBasicVector &Children()
00233   { return children; }
00234  
00236   void Add(awsKey *key) 
00237   { children.Push(key); }
00238 
00240   void Remove(iString *name)
00241   { children.Delete(children.Find(Find(name))); }
00242 
00244   void Remove(awsKey *key)
00245   { children.Delete(children.Find(key)); }
00246 
00248   void Consume(awsKeyContainer *c);
00249 };
00250 
00251 class awsSkinNode : public awsKey, awsKeyContainer
00252 {
00253 public:  
00254     awsSkinNode(iString *name):awsKey(name) {};
00255     virtual ~awsSkinNode() {};
00256 
00257     int Length()
00258     { return Children().Length(); }
00259 
00260     awsKey *GetAt(int i)
00261     { return (awsKey *)Children()[i]; }
00262     
00264     virtual unsigned char Type() 
00265     { return KEY_SKIN; }
00266 };
00267 
00268 class awsComponentNode : public awsKey, awsKeyContainer
00269 {
00271   iString *comp_type;
00272 
00273 public:  
00274   awsComponentNode(iString *name, iString *component_type):awsKey(name), comp_type(component_type) {};
00275   virtual ~awsComponentNode() {};
00276     
00278   virtual unsigned char Type() 
00279   { return KEY_COMPONENT; }
00280     
00282   iString *ComponentTypeName()
00283   { return comp_type; }
00284     
00286   int GetLength()
00287   { return Children().Length(); }
00288   
00290   awsKey *GetItemAt(int i)
00291   { return (awsKey *)Children()[i];  }
00292 };
00293 
00294 class awsConnectionNode : public awsKey, awsKeyContainer
00295 {
00296   
00297 public:  
00298   awsConnectionNode();
00299   virtual ~awsConnectionNode();
00300     
00302   virtual unsigned char Type() 
00303   { return KEY_CONNECTIONMAP; }
00304       
00306   int GetLength()
00307   { return Children().Length(); }
00308   
00310   awsKey *GetItemAt(int i)
00311   { return (awsKey *)Children()[i];  }
00312 };
00313 
00314 
00315 
00317 
00318 
00319 enum AWS_COLORS { AC_HIGHLIGHT, AC_HIGHLIGHT2, AC_SHADOW, AC_SHADOW2, AC_FILL, AC_DARKFILL, 
00320                   AC_TEXTFORE, AC_TEXTBACK, AC_TEXTDISABLED, 
00321                   AC_BUTTONTEXT, AC_TRANSPARENT, 
00322                   AC_BLACK, AC_WHITE, AC_RED, AC_GREEN, AC_BLUE,
00323                   AC_COLOR_COUNT };
00324 
00325 class awsPrefManager : public iAwsPrefManager
00326 {
00328   csDLinkList win_defs;
00329 
00331   csDLinkList skin_defs;
00332 
00334   unsigned int n_win_defs;
00335 
00337   unsigned int n_skin_defs;
00338 
00340   awsSkinNode *def_skin;
00341   
00343   int sys_colors[AC_COLOR_COUNT];
00344 
00346   awsTextureManager *awstxtmgr;
00347 
00349   iFontServer *fontsvr;
00350 
00352   iFont *default_font;
00353 
00355   iAws  *wmgr;
00356 
00358   csBasicVector constants;
00359 
00361   struct constant_entry
00362   {
00364     unsigned int name;
00365 
00367     int value;
00368   };
00369 
00370 public:
00371     SCF_DECLARE_IBASE;
00372 
00373     awsPrefManager(iBase *iParent);
00374     virtual ~awsPrefManager();
00375 
00377     virtual void Load(const char *def_file);
00378 
00380     virtual unsigned long NameToId(char *name);
00381     
00383     virtual bool SelectDefaultSkin(char *skin_name);
00384 
00386     virtual bool LookupIntKey(char *name, int &val); 
00387 
00389     virtual bool LookupIntKey(unsigned long id, int &val); 
00390 
00392     virtual bool LookupStringKey(char *name, iString *&val); 
00393 
00395     virtual bool LookupStringKey(unsigned long id, iString *&val); 
00396 
00398     virtual bool LookupRectKey(char *name, csRect &rect); 
00399 
00401     virtual bool LookupRectKey(unsigned long id, csRect &rect); 
00402     
00404     virtual bool LookupRGBKey(char *name, unsigned char &red, unsigned char &green, unsigned char &blue);
00405     
00407     virtual bool LookupRGBKey(unsigned long id, unsigned char &red, unsigned char &green, unsigned char &blue);
00408 
00410     virtual bool LookupPointKey(char *name, csPoint &point); 
00411 
00413     virtual bool LookupPointKey(unsigned long id, csPoint &point); 
00414             
00416     virtual bool GetInt(awsComponentNode *node, char *name, int &val);
00417 
00419     virtual bool GetRect(awsComponentNode *node, char *name, csRect &rect);
00420 
00422     virtual bool GetString(awsComponentNode *node, char *name, iString *&val);
00423     
00425     virtual awsComponentNode *FindWindowDef(char *name);
00426 
00427 public:
00429     void AddWindowDef(awsComponentNode *win)
00430     { win_defs.AddItem(win); n_win_defs++; }
00431 
00433     void AddSkinDef(awsSkinNode *skin)
00434     { skin_defs.AddItem(skin); n_skin_defs++; }
00435 
00436 public:
00438     virtual void SetColor(int index, int color); 
00439     
00441     virtual int  GetColor(int index);
00442 
00444     virtual iFont *GetDefaultFont();
00445 
00447     virtual iFont *GetFont(char *filename);
00448     
00450     virtual iTextureHandle *GetTexture(char *name, char *filename=NULL);
00451 
00454     virtual void SetTextureManager(iTextureManager *txtmgr);
00455 
00457     virtual void SetFontServer(iFontServer *fntsvr);
00458 
00460     virtual void SetWindowMgr(iAws *_wmgr);
00461         
00467     virtual void SetupPalette();
00468 
00471     virtual void Setup(iObjectRegistry *obj_reg);
00472 
00474     virtual void RegisterConstant(char *name, int value);
00475 
00477     virtual bool ConstantExists(char *name);
00478 
00480     virtual int  GetConstantValue(char *name);
00481     
00482 };
00483  
00484 #endif
00485 

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000