CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound 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 <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);
00119 
00121     virtual bool Initialize (iObjectRegistry *object_reg);
00123     virtual bool HandleEvent (iEvent &Event);
00124 
00126     struct eiEventHandler : public iEventHandler
00127     {
00128       SCF_DECLARE_EMBEDDED_IBASE(csAppPlugin);
00129       virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00130     } scfiEventHandler;
00131     friend struct eiEventHandler;
00132   } *scfiPlugin;
00133   friend class csAppPlugin;
00134 
00136   struct csModalInfo
00137   {
00139     csComponent* component;     
00141     csComponent* old_focus;     
00143     iBase* userdata;            
00144   };
00148   csArray<csModalInfo*> ModalInfo;
00149 
00150 public:
00152   iObjectRegistry* object_reg;
00154   csRef<iVirtualClock> vc;
00156   csRef<iEventQueue> event_queue;
00158   csRef<iPluginManager> plugin_mgr;
00160   csRef<iVFS> VFS;
00162   csConfigAccess config;
00164   csRef<iFontServer> FontServer;
00166   csRef<iImageIO> ImageLoader;
00168   csRef<iKeyboardDriver> KeyboardDriver;
00170   csRef<iMouseDriver> MouseDriver;
00172   int Pal [cs_Color_Last];
00174   csComponent *MouseOwner;
00176   csComponent *KeyboardOwner;
00178   csComponent *FocusOwner;
00180   csComponent *LastMouseContainer;
00182   csSkin *skin;
00184   bool WindowListChanged;
00186   bool InsertMode;
00188   int ScreenWidth, ScreenHeight;
00190   csRef<iFont> DefaultFont;
00192   int DefaultFontSize;
00193 
00195   csApp (iObjectRegistry *object_reg, csSkin &Skin);
00197   virtual ~csApp ();
00198 
00200   virtual bool Initialize ();
00201 
00203   void SetSkin (csSkin *Skin, bool DeleteOld = true);
00204 
00206   virtual void StartFrame ();
00208   virtual void FinishFrame ();
00209 
00211   void FlushEvents ();
00212 
00214   iEvent *CreateEvent ()
00215   { return csRef<iEvent>(EventOutlet->CreateEvent ()); }
00216 
00218   void Post (iEvent *Event)
00219   { EventOutlet->Post (Event); }
00220 
00222   void ShutDown ();
00223 
00225   virtual void Idle ();
00226 
00228   virtual void Draw ();
00229 
00231   virtual void GetFont (iFont *&oFont, int &oFontSize);
00232 
00234   void SetBackgroundStyle (csAppBackgroundStyle iBackgroundStyle);
00235 
00237   void Printf (int mode, char const* format, ...) CS_GNUC_PRINTF (3, 4);
00238 
00240   void PrintfV (int mode, char const* format, va_list) CS_GNUC_PRINTF (3, 0);
00241 
00243   bool LoadTexture (const char *iTexName, const char *iTexParams,
00244     int iFlags);
00245 
00247   virtual void PrepareTextures ();
00248 
00250   csWSTexVector *GetTextures ()
00251   { return &Textures; }
00252 
00254   iTextureHandle *GetTexture (const char *Name)
00255   {
00256     csWSTexture *tex = GetTextures ()->FindTexture (Name);
00257     return tex ? tex->GetHandle () : (iTextureHandle*)0;
00258   }
00259 
00261   csMouse &GetMouse () { return *Mouse; }
00262 
00264   void SetMouseCursor (csMouseCursorID ID) { MouseCursorID = ID; }
00265 
00267   csMouseCursorID GetMouseCursor () { return MouseCursorID; }
00268 
00270   csComponent *CaptureMouse (csComponent *who)
00271   { csComponent *c = MouseOwner; MouseOwner = who; return c; }
00272 
00274   csComponent *CaptureKeyboard (csComponent *who)
00275   { csComponent *c = KeyboardOwner; KeyboardOwner = who; return c; }
00276 
00278   csComponent *CaptureFocus (csComponent *who)
00279   { csComponent *c = FocusOwner; FocusOwner = who; return c; }
00280 
00282   bool GetKeyState (int iKey);
00283 
00285   csTicks GetCurrentTime ()
00286   { return CurrentTime; }
00287 
00289   void WindowList ();
00290 
00292   void SetWindowListSize (int iWidth, int iHeight)
00293   { WindowListWidth = iWidth; WindowListHeight = iHeight; }
00294 
00296   virtual void Insert (csComponent *comp);
00297 
00299   virtual void Delete (csComponent *comp);
00300 
00306   bool StartModal (csComponent* comp, iBase* userdata);
00307 
00311   void StopModal (int iCode = cscmdCancel);
00312 
00317   csComponent* GetTopModalComponent ();
00318 
00323   iBase* GetTopModalUserdata ();
00324 
00326   void Dismiss (int iCode = cscmdCancel);
00327 
00329   virtual bool PreHandleEvent (iEvent &Event);
00330 
00332   virtual bool HandleEvent (iEvent &Event);
00333 
00335   virtual bool PostHandleEvent (iEvent &Event);
00336 
00338   virtual void NotifyDelete (csComponent *iComp);
00339 
00341   virtual csSkin *GetSkin ();
00342 
00344   void HintAdd (const char *iText, csComponent *iComp)
00345   { hints->Add (iText, iComp); }
00346 
00348   void HintRemove (csComponent *iComp);
00349 
00351   csHintManager &GetHintManager ()
00352   { return *hints; }
00353 
00355   csPtr<iFont> LoadFont (const char *iFontName)
00356   { return FontServer->LoadFont (iFontName); }
00357 
00358 /*
00359  * The following methods are simple redirectors to csGraphicsPipeline
00360  * object (which is private property of csApp class).
00361  */
00362 
00364   int FindColor (int r, int g, int b);
00365 
00367   int pplColor (int color)
00368   { return color & 0x80000000 ? (color & 0x7fffffff) << PhysColorShift : Pal [color]; }
00369 
00371   void pplBox (int x, int y, int w, int h, int color)
00372   { GfxPpl.Box (x, y, w, h, pplColor (color)); }
00373 
00375   void pplLine (float x1, float y1, float x2, float y2, int color)
00376   { GfxPpl.Line (x1, y1, x2, y2, pplColor (color)); }
00377 
00379   void pplPixel (int x, int y, int color)
00380   { GfxPpl.Pixel (x, y, pplColor (color)); }
00381 
00383   void pplText (int x, int y, int fg, int bg, iFont *Font, int FontSize, const char *s)
00384   { GfxPpl.Text (x, y, pplColor (fg), bg != -1 ? pplColor (bg) : bg, Font, FontSize, s); }
00385 
00387   void pplPixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha)
00388   { GfxPpl.Pixmap (s2d, x, y, w, h, Alpha); }
00390   void pplTiledPixmap (csPixmap *s2d, int x, int y, int w, int h,
00391     int orgx, int orgy, uint8 Alpha)
00392   { GfxPpl.TiledPixmap (s2d, x, y, w, h, orgx, orgy, Alpha); }
00393 
00395   void pplTexture (iTextureHandle *hTex, int sx, int sy, int sw, int sh,
00396     int tx, int ty, int tw, int th, uint8 Alpha = 0)
00397   { GfxPpl.Texture (hTex, sx, sy, sw, sh, tx, ty, tw, th, Alpha); }
00398 
00400   void pplSaveArea (csImageArea *&Area, int x, int y, int w, int h)
00401   { GfxPpl.SaveArea (&Area, x, y, w, h); }
00403   void pplRestoreArea (csImageArea *Area, bool Free = false)
00404   { GfxPpl.RestoreArea (Area, Free); }
00406   void pplFreeArea (csImageArea *Area)
00407   { GfxPpl.FreeArea (Area); }
00408 
00410   void pplClear (int color)
00411   { GfxPpl.Clear (pplColor (color)); }
00412 
00414   void pplSetClipRect (int xmin, int ymin, int xmax, int ymax)
00415   { GfxPpl.SetClipRect (xmin, ymin, xmax, ymax); }
00416 
00418   void pplSetClipRect (csRect &clip)
00419   { GfxPpl.SetClipRect (clip.xmin, clip.ymin, clip.xmax, clip.ymax); }
00420 
00422   void pplRestoreClipRect ()
00423   { GfxPpl.RestoreClipRect (); }
00424 
00426   bool ClipLine (float &x1, float &y1, float &x2, float &y2,
00427     int ClipX1, int ClipY1, int ClipX2, int ClipY2)
00428   { return GfxPpl.ClipLine (x1, y1, x2, y2, ClipX1, ClipY1, ClipX2, ClipY2); }
00429 
00431   bool SwitchMouseCursor (csMouseCursorID Shape)
00432   { return GfxPpl.SwitchMouseCursor (Shape); }
00433 
00435   void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB)
00436   { GfxPpl.GetPixel (x, y, oR, oG, oB); }
00437 
00438   //--- 3D drawing ---//
00439 
00441   void pplPolygon3D (G3DPolygonDPFX &poly, uint mode)
00442   { GfxPpl.Polygon3D (poly, mode); }
00443 
00445   void pplClearZbuffer (int x1, int y1, int x2, int y2)
00446   { GfxPpl.ClearZbuffer (x1, y1, x2, y2); }
00447 
00449   void pplClearZbuffer ()
00450   { GfxPpl.ClearZbuffer (); }
00451 
00453   void SetZbufferMode (unsigned mode)
00454   { GfxPpl.SetZbufferMode (mode); }
00455 
00457   void pplBeginDraw (unsigned mode)
00458   { GfxPpl.BeginDraw (mode); }
00459 
00461   void pplInvalidate (csRect &rect)
00462   { GfxPpl.Invalidate (rect); }
00463 
00473   void pplDontCacheFrame ()
00474   { GfxPpl.DontCacheFrame = true; }
00475 
00480   iGraphics2D *GetG2D ()
00481   { return GfxPpl.G2D; }
00482 
00487   iGraphics3D *GetG3D ()
00488   { return GfxPpl.G3D; }
00489 
00490 protected:
00492   void InitializeSkin ();
00494   void SetupPalette ();
00495 };
00496 
00499 #endif // __CS_CSAPP_H__

Generated for Crystal Space by doxygen 1.2.14