CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

csapp.h

Go to the documentation of this file.
00001 /*
00002     Crystal Space Windowing System: Windowing System Application class interface
00003     Copyright (C) 2001 by Jorrit Tyberghein
00004     Copyright (C) 1998,1999 by Andrew Zabolotny <bit@eltech.ru>
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 
00021 #ifndef __CS_CSAPP_H__
00022 #define __CS_CSAPP_H__
00023 
00032 #include "csextern.h"
00033  
00034 #include <stdarg.h>
00035 
00036 #define CSWS_INTERNAL
00037 #include "csws.h"
00038 #include "cscomp.h"
00039 #include "cswstex.h"
00040 #include "cshints.h"
00041 #include "csmouse.h"
00042 #include "csgfxppl.h"
00043 #include "csutil/cseventq.h"
00044 #include "csutil/array.h"
00045 #include "csutil/cfgacc.h"
00046 #include "iutil/eventh.h"
00047 #include "iutil/comp.h"
00048 #include "iutil/event.h"
00049 
00050 class csSkin;
00051 struct iImageIO;
00052 struct iKeyboardDriver;
00053 struct iMouseDriver;
00054 struct iObjectRegistry;
00055 struct iPluginManager;
00056 struct iVirtualClock;
00057 struct iEventQueue;
00058 
00062 enum csAppBackgroundStyle
00063 {
00065   csabsNothing = 0,
00067   csabsSolid
00068 };
00069 
00081 class CS_CSWS_EXPORT csApp : public csComponent
00082 {
00083 protected:
00084   friend class csMouse;
00085 
00087   csGraphicsPipeline GfxPpl;
00089   csMouse *Mouse;
00091   csWSTexVector Textures;
00093   csHintManager *hints;
00095   int WindowListWidth, WindowListHeight;
00097   csMouseCursorID MouseCursorID, OldMouseCursorID;
00099   int DismissCode;
00101   int PhysColorShift;
00103   csTicks CurrentTime;
00105   iEventOutlet *EventOutlet;
00107   csAppBackgroundStyle BackgroundStyle;
00109   bool InFrame;
00110 
00112   class csAppPlugin : public iComponent
00113   {
00114   public:
00115     SCF_DECLARE_IBASE;
00117     csApp *app;
00118 
00120     csAppPlugin (csApp *iParent);
00122     virtual ~csAppPlugin();
00123 
00125     virtual bool Initialize (iObjectRegistry *object_reg);
00127     virtual bool HandleEvent (iEvent &Event);
00128 
00130     struct eiEventHandler : public iEventHandler
00131     {
00132       SCF_DECLARE_EMBEDDED_IBASE(csAppPlugin);
00133       virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00134     } scfiEventHandler;
00135     friend struct eiEventHandler;
00136   } *scfiPlugin;
00137   friend class csAppPlugin;
00138 
00142   struct csModalInfo
00143   {
00145     csComponent* component;     
00147     csComponent* old_focus;     
00149     iBase* userdata;            
00150   };
00154   csArray<csModalInfo*> ModalInfo;
00155 
00156 public:
00158   iObjectRegistry* object_reg;
00160   csRef<iVirtualClock> vc;
00162   csRef<iEventQueue> event_queue;
00164   csRef<iPluginManager> plugin_mgr;
00166   csRef<iVFS> VFS;
00168   csConfigAccess config;
00170   csRef<iFontServer> FontServer;
00172   csRef<iImageIO> ImageLoader;
00174   csRef<iKeyboardDriver> KeyboardDriver;
00176   csRef<iMouseDriver> MouseDriver;
00178   int Pal [cs_Color_Last];
00180   csComponent *MouseOwner;
00182   csComponent *KeyboardOwner;
00184   csComponent *FocusOwner;
00186   csComponent *LastMouseContainer;
00188   csSkin *skin;
00190   bool WindowListChanged;
00192   bool InsertMode;
00194   int ScreenWidth, ScreenHeight;
00196   csRef<iFont> DefaultFont;
00198   int DefaultFontSize;
00199 
00201   csApp (iObjectRegistry *object_reg, csSkin &Skin);
00203   virtual ~csApp ();
00204 
00206   virtual bool Initialize ();
00207 
00209   void SetSkin (csSkin *Skin, bool DeleteOld = true);
00210 
00212   virtual void StartFrame ();
00214   virtual void FinishFrame ();
00215 
00217   void FlushEvents ();
00218 
00220   iEvent *CreateEvent ()
00221   { return csRef<iEvent>(EventOutlet->CreateEvent ()); }
00222 
00224   void Post (iEvent *Event)
00225   { EventOutlet->Post (Event); }
00226 
00228   void ShutDown ();
00229 
00231   virtual void Idle ();
00232 
00234   virtual void Draw ();
00235 
00237   virtual void GetFont (iFont *&oFont);
00238 
00240   void SetBackgroundStyle (csAppBackgroundStyle iBackgroundStyle);
00241 
00243   void Printf (int mode, char const* format, ...) CS_GNUC_PRINTF (3, 4);
00244 
00246   void PrintfV (int mode, char const* format, va_list) CS_GNUC_PRINTF (3, 0);
00247 
00249   bool LoadTexture (const char *iTexName, const char *iTexParams,
00250     int iFlags);
00251 
00253   virtual void PrepareTextures ();
00254 
00256   csWSTexVector *GetTextures ()
00257   { return &Textures; }
00258 
00260   iTextureHandle *GetTexture (const char *Name)
00261   {
00262     csWSTexture *tex = GetTextures ()->FindTexture (Name);
00263     return tex ? tex->GetHandle () : (iTextureHandle*)0;
00264   }
00265 
00267   csMouse &GetMouse () { return *Mouse; }
00268 
00270   void SetMouseCursor (csMouseCursorID ID) { MouseCursorID = ID; }
00271 
00273   csMouseCursorID GetMouseCursor () { return MouseCursorID; }
00274 
00276   csComponent *CaptureMouse (csComponent *who)
00277   { csComponent *c = MouseOwner; MouseOwner = who; return c; }
00278 
00280   csComponent *CaptureKeyboard (csComponent *who)
00281   { csComponent *c = KeyboardOwner; KeyboardOwner = who; return c; }
00282 
00284   csComponent *CaptureFocus (csComponent *who)
00285   { csComponent *c = FocusOwner; FocusOwner = who; return c; }
00286 
00288   bool GetKeyState (int iKey);
00289 
00291   csTicks GetCurrentTime ()
00292   { return CurrentTime; }
00293 
00295   void WindowList ();
00296 
00298   void SetWindowListSize (int iWidth, int iHeight)
00299   { WindowListWidth = iWidth; WindowListHeight = iHeight; }
00300 
00302   virtual void Insert (csComponent *comp);
00303 
00305   virtual void Delete (csComponent *comp);
00306 
00312   bool StartModal (csComponent* comp, iBase* userdata);
00313 
00317   void StopModal (int iCode = cscmdCancel);
00318 
00323   csComponent* GetTopModalComponent ();
00324 
00329   iBase* GetTopModalUserdata ();
00330 
00332   void Dismiss (int iCode = cscmdCancel);
00333 
00335   virtual bool PreHandleEvent (iEvent &Event);
00336 
00338   virtual bool HandleEvent (iEvent &Event);
00339 
00341   virtual bool PostHandleEvent (iEvent &Event);
00342 
00344   virtual void NotifyDelete (csComponent *iComp);
00345 
00347   virtual csSkin *GetSkin ();
00348 
00350   void HintAdd (const char *iText, csComponent *iComp)
00351   { hints->Add (iText, iComp); }
00352 
00354   void HintRemove (csComponent *iComp);
00355 
00357   csHintManager &GetHintManager ()
00358   { return *hints; }
00359 
00361   csPtr<iFont> LoadFont (const char *iFontName, int fontSize = 10)
00362   { return FontServer->LoadFont (iFontName, fontSize); }
00363 
00364 /*
00365  * The following methods are simple redirectors to csGraphicsPipeline
00366  * object (which is private property of csApp class).
00367  */
00368 
00370   int FindColor (int r, int g, int b);
00371 
00373   int pplColor (int color)
00374   { return color & 0x80000000 ? (color & 0x7fffffff) << PhysColorShift : Pal [color]; }
00375 
00377   void pplBox (int x, int y, int w, int h, int color)
00378   { GfxPpl.Box (x, y, w, h, pplColor (color)); }
00379 
00381   void pplLine (float x1, float y1, float x2, float y2, int color)
00382   { GfxPpl.Line (x1, y1, x2, y2, pplColor (color)); }
00383 
00385   void pplPixel (int x, int y, int color)
00386   { GfxPpl.Pixel (x, y, pplColor (color)); }
00387 
00389   void pplText (int x, int y, int fg, int bg, iFont *Font, const char *s)
00390   { GfxPpl.Text (x, y, pplColor (fg), bg != -1 ? pplColor (bg) : bg, Font, s); }
00391 
00393   void pplPixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha)
00394   { GfxPpl.Pixmap (s2d, x, y, w, h, Alpha); }
00396   void pplTiledPixmap (csPixmap *s2d, int x, int y, int w, int h,
00397     int orgx, int orgy, uint8 Alpha)
00398   { GfxPpl.TiledPixmap (s2d, x, y, w, h, orgx, orgy, Alpha); }
00399 
00401   void pplTexture (iTextureHandle *hTex, int sx, int sy, int sw, int sh,
00402     int tx, int ty, int tw, int th, uint8 Alpha = 0)
00403   { GfxPpl.Texture (hTex, sx, sy, sw, sh, tx, ty, tw, th, Alpha); }
00404 
00406   void pplSaveArea (csImageArea *&Area, int x, int y, int w, int h)
00407   { GfxPpl.SaveArea (&Area, x, y, w, h); }
00409   void pplRestoreArea (csImageArea *Area, bool Free = false)
00410   { GfxPpl.RestoreArea (Area, Free); }
00412   void pplFreeArea (csImageArea *Area)
00413   { GfxPpl.FreeArea (Area); }
00414 
00416   void pplClear (int color)
00417   { GfxPpl.Clear (pplColor (color)); }
00418 
00420   void pplSetClipRect (int xmin, int ymin, int xmax, int ymax)
00421   { GfxPpl.SetClipRect (xmin, ymin, xmax, ymax); }
00422 
00424   void pplSetClipRect (csRect &clip)
00425   { GfxPpl.SetClipRect (clip.xmin, clip.ymin, clip.xmax, clip.ymax); }
00426 
00428   void pplRestoreClipRect ()
00429   { GfxPpl.RestoreClipRect (); }
00430 
00432   bool ClipLine (float &x1, float &y1, float &x2, float &y2,
00433     int ClipX1, int ClipY1, int ClipX2, int ClipY2)
00434   { return GfxPpl.ClipLine (x1, y1, x2, y2, ClipX1, ClipY1, ClipX2, ClipY2); }
00435 
00437   bool SwitchMouseCursor (csMouseCursorID Shape)
00438   { return GfxPpl.SwitchMouseCursor (Shape); }
00439 
00441   void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB)
00442   { GfxPpl.GetPixel (x, y, oR, oG, oB); }
00443 
00444   //--- 3D drawing ---//
00445 
00447   //@@@REIMPLEMENT THIS FOR NR
00448   /*void pplPolygon3D (G3DPolygonDPFX &poly, uint mode)
00449   { GfxPpl.Polygon3D (poly, mode); }*/
00450 
00452   void pplClearZbuffer (int x1, int y1, int x2, int y2)
00453   { GfxPpl.ClearZbuffer (x1, y1, x2, y2); }
00454 
00456   void pplClearZbuffer ()
00457   { GfxPpl.ClearZbuffer (); }
00458 
00460   void SetZbufferMode (unsigned mode)
00461   { GfxPpl.SetZbufferMode (mode); }
00462 
00464   void pplBeginDraw (unsigned mode)
00465   { GfxPpl.BeginDraw (mode); }
00466 
00468   void pplInvalidate (csRect &rect)
00469   { GfxPpl.Invalidate (rect); }
00470 
00480   void pplDontCacheFrame ()
00481   { GfxPpl.DontCacheFrame = true; }
00482 
00487   iGraphics2D *GetG2D ()
00488   { return GfxPpl.G2D; }
00489 
00494   iGraphics3D *GetG3D ()
00495   { return GfxPpl.G3D; }
00496 
00497 protected:
00499   void InitializeSkin ();
00501   void SetupPalette ();
00502 };
00503 
00506 #endif // __CS_CSAPP_H__

Generated for Crystal Space by doxygen 1.3.9.1