CrystalSpace

Public API Reference

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

csws/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 <stdarg.h>
00033 
00034 #define CSWS_INTERNAL
00035 #include "csws.h"
00036 #include "cscomp.h"
00037 #include "cswstex.h"
00038 #include "cshints.h"
00039 #include "csmouse.h"
00040 #include "csgfxppl.h"
00041 #include "csutil/cseventq.h"
00042 #include "csutil/array.h"
00043 #include "csutil/cfgacc.h"
00044 #include "iutil/eventh.h"
00045 #include "iutil/comp.h"
00046 #include "iutil/event.h"
00047 
00048 class csSkin;
00049 struct iImageIO;
00050 struct iKeyboardDriver;
00051 struct iMouseDriver;
00052 struct iObjectRegistry;
00053 struct iPluginManager;
00054 struct iVirtualClock;
00055 struct iEventQueue;
00056 
00060 enum csAppBackgroundStyle
00061 {
00063   csabsNothing = 0,
00065   csabsSolid
00066 };
00067 
00079 class csApp : public csComponent
00080 {
00081 protected:
00082   friend class csMouse;
00083 
00085   csGraphicsPipeline GfxPpl;
00087   csMouse *Mouse;
00089   csWSTexVector Textures;
00091   csHintManager *hints;
00093   int WindowListWidth, WindowListHeight;
00095   csMouseCursorID MouseCursorID, OldMouseCursorID;
00097   int DismissCode;
00099   int PhysColorShift;
00101   csTicks CurrentTime;
00103   iEventOutlet *EventOutlet;
00105   csAppBackgroundStyle BackgroundStyle;
00107   bool InFrame;
00108 
00110   class csAppPlugin : public iComponent
00111   {
00112   public:
00113     SCF_DECLARE_IBASE;
00115     csApp *app;
00116 
00118     csAppPlugin (csApp *iParent);
00120     virtual ~csAppPlugin();
00121 
00123     virtual bool Initialize (iObjectRegistry *object_reg);
00125     virtual bool HandleEvent (iEvent &Event);
00126 
00128     struct eiEventHandler : public iEventHandler
00129     {
00130       SCF_DECLARE_EMBEDDED_IBASE(csAppPlugin);
00131       virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00132     } scfiEventHandler;
00133     friend struct eiEventHandler;
00134   } *scfiPlugin;
00135   friend class csAppPlugin;
00136 
00138   struct csModalInfo
00139   {
00141     csComponent* component;     
00143     csComponent* old_focus;     
00145     iBase* userdata;            
00146   };
00150   csArray<csModalInfo*> ModalInfo;
00151 
00152 public:
00154   iObjectRegistry* object_reg;
00156   csRef<iVirtualClock> vc;
00158   csRef<iEventQueue> event_queue;
00160   csRef<iPluginManager> plugin_mgr;
00162   csRef<iVFS> VFS;
00164   csConfigAccess config;
00166   csRef<iFontServer> FontServer;
00168   csRef<iImageIO> ImageLoader;
00170   csRef<iKeyboardDriver> KeyboardDriver;
00172   csRef<iMouseDriver> MouseDriver;
00174   int Pal [cs_Color_Last];
00176   csComponent *MouseOwner;
00178   csComponent *KeyboardOwner;
00180   csComponent *FocusOwner;
00182   csComponent *LastMouseContainer;
00184   csSkin *skin;
00186   bool WindowListChanged;
00188   bool InsertMode;
00190   int ScreenWidth, ScreenHeight;
00192   csRef<iFont> DefaultFont;
00194   int DefaultFontSize;
00195 
00197   csApp (iObjectRegistry *object_reg, csSkin &Skin);
00199   virtual ~csApp ();
00200 
00202   virtual bool Initialize ();
00203 
00205   void SetSkin (csSkin *Skin, bool DeleteOld = true);
00206 
00208   virtual void StartFrame ();
00210   virtual void FinishFrame ();
00211 
00213   void FlushEvents ();
00214 
00216   iEvent *CreateEvent ()
00217   { return csRef<iEvent>(EventOutlet->CreateEvent ()); }
00218 
00220   void Post (iEvent *Event)
00221   { EventOutlet->Post (Event); }
00222 
00224   void ShutDown ();
00225 
00227   virtual void Idle ();
00228 
00230   virtual void Draw ();
00231 
00233   virtual void GetFont (iFont *&oFont, int &oFontSize);
00234 
00236   void SetBackgroundStyle (csAppBackgroundStyle iBackgroundStyle);
00237 
00239   void Printf (int mode, char const* format, ...) CS_GNUC_PRINTF (3, 4);
00240 
00242   void PrintfV (int mode, char const* format, va_list) CS_GNUC_PRINTF (3, 0);
00243 
00245   bool LoadTexture (const char *iTexName, const char *iTexParams,
00246     int iFlags);
00247 
00249   virtual void PrepareTextures ();
00250 
00252   csWSTexVector *GetTextures ()
00253   { return &Textures; }
00254 
00256   iTextureHandle *GetTexture (const char *Name)
00257   {
00258     csWSTexture *tex = GetTextures ()->FindTexture (Name);
00259     return tex ? tex->GetHandle () : (iTextureHandle*)0;
00260   }
00261 
00263   csMouse &GetMouse () { return *Mouse; }
00264 
00266   void SetMouseCursor (csMouseCursorID ID) { MouseCursorID = ID; }
00267 
00269   csMouseCursorID GetMouseCursor () { return MouseCursorID; }
00270 
00272   csComponent *CaptureMouse (csComponent *who)
00273   { csComponent *c = MouseOwner; MouseOwner = who; return c; }
00274 
00276   csComponent *CaptureKeyboard (csComponent *who)
00277   { csComponent *c = KeyboardOwner; KeyboardOwner = who; return c; }
00278 
00280   csComponent *CaptureFocus (csComponent *who)
00281   { csComponent *c = FocusOwner; FocusOwner = who; return c; }
00282 
00284   bool GetKeyState (int iKey);
00285 
00287   csTicks GetCurrentTime ()
00288   { return CurrentTime; }
00289 
00291   void WindowList ();
00292 
00294   void SetWindowListSize (int iWidth, int iHeight)
00295   { WindowListWidth = iWidth; WindowListHeight = iHeight; }
00296 
00298   virtual void Insert (csComponent *comp);
00299 
00301   virtual void Delete (csComponent *comp);
00302 
00308   bool StartModal (csComponent* comp, iBase* userdata);
00309 
00313   void StopModal (int iCode = cscmdCancel);
00314 
00319   csComponent* GetTopModalComponent ();
00320 
00325   iBase* GetTopModalUserdata ();
00326 
00328   void Dismiss (int iCode = cscmdCancel);
00329 
00331   virtual bool PreHandleEvent (iEvent &Event);
00332 
00334   virtual bool HandleEvent (iEvent &Event);
00335 
00337   virtual bool PostHandleEvent (iEvent &Event);
00338 
00340   virtual void NotifyDelete (csComponent *iComp);
00341 
00343   virtual csSkin *GetSkin ();
00344 
00346   void HintAdd (const char *iText, csComponent *iComp)
00347   { hints->Add (iText, iComp); }
00348 
00350   void HintRemove (csComponent *iComp);
00351 
00353   csHintManager &GetHintManager ()
00354   { return *hints; }
00355 
00357   csPtr<iFont> LoadFont (const char *iFontName)
00358   { return FontServer->LoadFont (iFontName); }
00359 
00360 /*
00361  * The following methods are simple redirectors to csGraphicsPipeline
00362  * object (which is private property of csApp class).
00363  */
00364 
00366   int FindColor (int r, int g, int b);
00367 
00369   int pplColor (int color)
00370   { return color & 0x80000000 ? (color & 0x7fffffff) << PhysColorShift : Pal [color]; }
00371 
00373   void pplBox (int x, int y, int w, int h, int color)
00374   { GfxPpl.Box (x, y, w, h, pplColor (color)); }
00375 
00377   void pplLine (float x1, float y1, float x2, float y2, int color)
00378   { GfxPpl.Line (x1, y1, x2, y2, pplColor (color)); }
00379 
00381   void pplPixel (int x, int y, int color)
00382   { GfxPpl.Pixel (x, y, pplColor (color)); }
00383 
00385   void pplText (int x, int y, int fg, int bg, iFont *Font, int FontSize, const char *s)
00386   { GfxPpl.Text (x, y, pplColor (fg), bg != -1 ? pplColor (bg) : bg, Font, FontSize, s); }
00387 
00389   void pplPixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha)
00390   { GfxPpl.Pixmap (s2d, x, y, w, h, Alpha); }
00392   void pplTiledPixmap (csPixmap *s2d, int x, int y, int w, int h,
00393     int orgx, int orgy, uint8 Alpha)
00394   { GfxPpl.TiledPixmap (s2d, x, y, w, h, orgx, orgy, Alpha); }
00395 
00397   void pplTexture (iTextureHandle *hTex, int sx, int sy, int sw, int sh,
00398     int tx, int ty, int tw, int th, uint8 Alpha = 0)
00399   { GfxPpl.Texture (hTex, sx, sy, sw, sh, tx, ty, tw, th, Alpha); }
00400 
00402   void pplSaveArea (csImageArea *&Area, int x, int y, int w, int h)
00403   { GfxPpl.SaveArea (&Area, x, y, w, h); }
00405   void pplRestoreArea (csImageArea *Area, bool Free = false)
00406   { GfxPpl.RestoreArea (Area, Free); }
00408   void pplFreeArea (csImageArea *Area)
00409   { GfxPpl.FreeArea (Area); }
00410 
00412   void pplClear (int color)
00413   { GfxPpl.Clear (pplColor (color)); }
00414 
00416   void pplSetClipRect (int xmin, int ymin, int xmax, int ymax)
00417   { GfxPpl.SetClipRect (xmin, ymin, xmax, ymax); }
00418 
00420   void pplSetClipRect (csRect &clip)
00421   { GfxPpl.SetClipRect (clip.xmin, clip.ymin, clip.xmax, clip.ymax); }
00422 
00424   void pplRestoreClipRect ()
00425   { GfxPpl.RestoreClipRect (); }
00426 
00428   bool ClipLine (float &x1, float &y1, float &x2, float &y2,
00429     int ClipX1, int ClipY1, int ClipX2, int ClipY2)
00430   { return GfxPpl.ClipLine (x1, y1, x2, y2, ClipX1, ClipY1, ClipX2, ClipY2); }
00431 
00433   bool SwitchMouseCursor (csMouseCursorID Shape)
00434   { return GfxPpl.SwitchMouseCursor (Shape); }
00435 
00437   void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB)
00438   { GfxPpl.GetPixel (x, y, oR, oG, oB); }
00439 
00440   //--- 3D drawing ---//
00441 
00443   void pplPolygon3D (G3DPolygonDPFX &poly, uint mode)
00444   { GfxPpl.Polygon3D (poly, mode); }
00445 
00447   void pplClearZbuffer (int x1, int y1, int x2, int y2)
00448   { GfxPpl.ClearZbuffer (x1, y1, x2, y2); }
00449 
00451   void pplClearZbuffer ()
00452   { GfxPpl.ClearZbuffer (); }
00453 
00455   void SetZbufferMode (unsigned mode)
00456   { GfxPpl.SetZbufferMode (mode); }
00457 
00459   void pplBeginDraw (unsigned mode)
00460   { GfxPpl.BeginDraw (mode); }
00461 
00463   void pplInvalidate (csRect &rect)
00464   { GfxPpl.Invalidate (rect); }
00465 
00475   void pplDontCacheFrame ()
00476   { GfxPpl.DontCacheFrame = true; }
00477 
00482   iGraphics2D *GetG2D ()
00483   { return GfxPpl.G2D; }
00484 
00489   iGraphics3D *GetG3D ()
00490   { return GfxPpl.G3D; }
00491 
00492 protected:
00494   void InitializeSkin ();
00496   void SetupPalette ();
00497 };
00498 
00501 #endif // __CS_CSAPP_H__

Generated for Crystal Space by doxygen 1.2.18