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 "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 00140 struct csModalInfo 00141 { 00143 csComponent* component; 00145 csComponent* old_focus; 00147 iBase* userdata; 00148 }; 00152 csArray<csModalInfo*> ModalInfo; 00153 00154 public: 00156 iObjectRegistry* object_reg; 00158 csRef<iVirtualClock> vc; 00160 csRef<iEventQueue> event_queue; 00162 csRef<iPluginManager> plugin_mgr; 00164 csRef<iVFS> VFS; 00166 csConfigAccess config; 00168 csRef<iFontServer> FontServer; 00170 csRef<iImageIO> ImageLoader; 00172 csRef<iKeyboardDriver> KeyboardDriver; 00174 csRef<iMouseDriver> MouseDriver; 00176 int Pal [cs_Color_Last]; 00178 csComponent *MouseOwner; 00180 csComponent *KeyboardOwner; 00182 csComponent *FocusOwner; 00184 csComponent *LastMouseContainer; 00186 csSkin *skin; 00188 bool WindowListChanged; 00190 bool InsertMode; 00192 int ScreenWidth, ScreenHeight; 00194 csRef<iFont> DefaultFont; 00196 int DefaultFontSize; 00197 00199 csApp (iObjectRegistry *object_reg, csSkin &Skin); 00201 virtual ~csApp (); 00202 00204 virtual bool Initialize (); 00205 00207 void SetSkin (csSkin *Skin, bool DeleteOld = true); 00208 00210 virtual void StartFrame (); 00212 virtual void FinishFrame (); 00213 00215 void FlushEvents (); 00216 00218 iEvent *CreateEvent () 00219 { return csRef<iEvent>(EventOutlet->CreateEvent ()); } 00220 00222 void Post (iEvent *Event) 00223 { EventOutlet->Post (Event); } 00224 00226 void ShutDown (); 00227 00229 virtual void Idle (); 00230 00232 virtual void Draw (); 00233 00235 virtual void GetFont (iFont *&oFont); 00236 00238 void SetBackgroundStyle (csAppBackgroundStyle iBackgroundStyle); 00239 00241 void Printf (int mode, char const* format, ...) CS_GNUC_PRINTF (3, 4); 00242 00244 void PrintfV (int mode, char const* format, va_list) CS_GNUC_PRINTF (3, 0); 00245 00247 bool LoadTexture (const char *iTexName, const char *iTexParams, 00248 int iFlags); 00249 00251 virtual void PrepareTextures (); 00252 00254 csWSTexVector *GetTextures () 00255 { return &Textures; } 00256 00258 iTextureHandle *GetTexture (const char *Name) 00259 { 00260 csWSTexture *tex = GetTextures ()->FindTexture (Name); 00261 return tex ? tex->GetHandle () : (iTextureHandle*)0; 00262 } 00263 00265 csMouse &GetMouse () { return *Mouse; } 00266 00268 void SetMouseCursor (csMouseCursorID ID) { MouseCursorID = ID; } 00269 00271 csMouseCursorID GetMouseCursor () { return MouseCursorID; } 00272 00274 csComponent *CaptureMouse (csComponent *who) 00275 { csComponent *c = MouseOwner; MouseOwner = who; return c; } 00276 00278 csComponent *CaptureKeyboard (csComponent *who) 00279 { csComponent *c = KeyboardOwner; KeyboardOwner = who; return c; } 00280 00282 csComponent *CaptureFocus (csComponent *who) 00283 { csComponent *c = FocusOwner; FocusOwner = who; return c; } 00284 00286 bool GetKeyState (int iKey); 00287 00289 csTicks GetCurrentTime () 00290 { return CurrentTime; } 00291 00293 void WindowList (); 00294 00296 void SetWindowListSize (int iWidth, int iHeight) 00297 { WindowListWidth = iWidth; WindowListHeight = iHeight; } 00298 00300 virtual void Insert (csComponent *comp); 00301 00303 virtual void Delete (csComponent *comp); 00304 00310 bool StartModal (csComponent* comp, iBase* userdata); 00311 00315 void StopModal (int iCode = cscmdCancel); 00316 00321 csComponent* GetTopModalComponent (); 00322 00327 iBase* GetTopModalUserdata (); 00328 00330 void Dismiss (int iCode = cscmdCancel); 00331 00333 virtual bool PreHandleEvent (iEvent &Event); 00334 00336 virtual bool HandleEvent (iEvent &Event); 00337 00339 virtual bool PostHandleEvent (iEvent &Event); 00340 00342 virtual void NotifyDelete (csComponent *iComp); 00343 00345 virtual csSkin *GetSkin (); 00346 00348 void HintAdd (const char *iText, csComponent *iComp) 00349 { hints->Add (iText, iComp); } 00350 00352 void HintRemove (csComponent *iComp); 00353 00355 csHintManager &GetHintManager () 00356 { return *hints; } 00357 00359 csPtr<iFont> LoadFont (const char *iFontName, int fontSize = 10) 00360 { return FontServer->LoadFont (iFontName, fontSize); } 00361 00362 /* 00363 * The following methods are simple redirectors to csGraphicsPipeline 00364 * object (which is private property of csApp class). 00365 */ 00366 00368 int FindColor (int r, int g, int b); 00369 00371 int pplColor (int color) 00372 { return color & 0x80000000 ? (color & 0x7fffffff) << PhysColorShift : Pal [color]; } 00373 00375 void pplBox (int x, int y, int w, int h, int color) 00376 { GfxPpl.Box (x, y, w, h, pplColor (color)); } 00377 00379 void pplLine (float x1, float y1, float x2, float y2, int color) 00380 { GfxPpl.Line (x1, y1, x2, y2, pplColor (color)); } 00381 00383 void pplPixel (int x, int y, int color) 00384 { GfxPpl.Pixel (x, y, pplColor (color)); } 00385 00387 void pplText (int x, int y, int fg, int bg, iFont *Font, const char *s) 00388 { GfxPpl.Text (x, y, pplColor (fg), bg != -1 ? pplColor (bg) : bg, Font, s); } 00389 00391 void pplPixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha) 00392 { GfxPpl.Pixmap (s2d, x, y, w, h, Alpha); } 00394 void pplTiledPixmap (csPixmap *s2d, int x, int y, int w, int h, 00395 int orgx, int orgy, uint8 Alpha) 00396 { GfxPpl.TiledPixmap (s2d, x, y, w, h, orgx, orgy, Alpha); } 00397 00399 void pplTexture (iTextureHandle *hTex, int sx, int sy, int sw, int sh, 00400 int tx, int ty, int tw, int th, uint8 Alpha = 0) 00401 { GfxPpl.Texture (hTex, sx, sy, sw, sh, tx, ty, tw, th, Alpha); } 00402 00404 void pplSaveArea (csImageArea *&Area, int x, int y, int w, int h) 00405 { GfxPpl.SaveArea (&Area, x, y, w, h); } 00407 void pplRestoreArea (csImageArea *Area, bool Free = false) 00408 { GfxPpl.RestoreArea (Area, Free); } 00410 void pplFreeArea (csImageArea *Area) 00411 { GfxPpl.FreeArea (Area); } 00412 00414 void pplClear (int color) 00415 { GfxPpl.Clear (pplColor (color)); } 00416 00418 void pplSetClipRect (int xmin, int ymin, int xmax, int ymax) 00419 { GfxPpl.SetClipRect (xmin, ymin, xmax, ymax); } 00420 00422 void pplSetClipRect (csRect &clip) 00423 { GfxPpl.SetClipRect (clip.xmin, clip.ymin, clip.xmax, clip.ymax); } 00424 00426 void pplRestoreClipRect () 00427 { GfxPpl.RestoreClipRect (); } 00428 00430 bool ClipLine (float &x1, float &y1, float &x2, float &y2, 00431 int ClipX1, int ClipY1, int ClipX2, int ClipY2) 00432 { return GfxPpl.ClipLine (x1, y1, x2, y2, ClipX1, ClipY1, ClipX2, ClipY2); } 00433 00435 bool SwitchMouseCursor (csMouseCursorID Shape) 00436 { return GfxPpl.SwitchMouseCursor (Shape); } 00437 00439 void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB) 00440 { GfxPpl.GetPixel (x, y, oR, oG, oB); } 00441 00442 //--- 3D drawing ---// 00443 00445 void pplPolygon3D (G3DPolygonDPFX &poly, uint mode) 00446 { GfxPpl.Polygon3D (poly, mode); } 00447 00449 void pplClearZbuffer (int x1, int y1, int x2, int y2) 00450 { GfxPpl.ClearZbuffer (x1, y1, x2, y2); } 00451 00453 void pplClearZbuffer () 00454 { GfxPpl.ClearZbuffer (); } 00455 00457 void SetZbufferMode (unsigned mode) 00458 { GfxPpl.SetZbufferMode (mode); } 00459 00461 void pplBeginDraw (unsigned mode) 00462 { GfxPpl.BeginDraw (mode); } 00463 00465 void pplInvalidate (csRect &rect) 00466 { GfxPpl.Invalidate (rect); } 00467 00477 void pplDontCacheFrame () 00478 { GfxPpl.DontCacheFrame = true; } 00479 00484 iGraphics2D *GetG2D () 00485 { return GfxPpl.G2D; } 00486 00491 iGraphics3D *GetG3D () 00492 { return GfxPpl.G3D; } 00493 00494 protected: 00496 void InitializeSkin (); 00498 void SetupPalette (); 00499 }; 00500 00503 #endif // __CS_CSAPP_H__
Generated for Crystal Space by doxygen 1.2.18