00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __CSAPP_H__
00022 #define __CSAPP_H__
00023
00024 #include <stdarg.h>
00025
00026 #define CSWS_INTERNAL
00027 #include "csws.h"
00028 #include "cscomp.h"
00029 #include "cswstex.h"
00030 #include "cshints.h"
00031 #include "csmouse.h"
00032 #include "csgfxppl.h"
00033 #include "csutil/cseventq.h"
00034 #include "csutil/csstrvec.h"
00035 #include "csutil/cfgacc.h"
00036 #include "iutil/eventh.h"
00037 #include "iutil/comp.h"
00038 #include "iutil/event.h"
00039
00040 class csSkin;
00041 struct iImageIO;
00042 struct iKeyboardDriver;
00043 struct iMouseDriver;
00044 struct iObjectRegistry;
00045 struct iPluginManager;
00046 struct iVirtualClock;
00047 struct iEventQueue;
00048
00052 enum csAppBackgroundStyle
00053 {
00055 csabsNothing = 0,
00057 csabsSolid
00058 };
00059
00071 class csApp : public csComponent
00072 {
00073 protected:
00074 friend class csMouse;
00075
00077 csGraphicsPipeline GfxPpl;
00079 csMouse *Mouse;
00081 csWSTexVector Textures;
00083 csHintManager *hints;
00085 int WindowListWidth, WindowListHeight;
00087 csMouseCursorID MouseCursorID, OldMouseCursorID;
00089 int DismissCode;
00091 int PhysColorShift;
00093 csTicks CurrentTime;
00095 iEventOutlet *EventOutlet;
00097 csAppBackgroundStyle BackgroundStyle;
00099 bool InFrame;
00100
00102 class csAppPlugin : public iComponent
00103 {
00104 public:
00105 SCF_DECLARE_IBASE;
00107 csApp *app;
00108
00110 csAppPlugin (csApp *iParent);
00111
00113 virtual bool Initialize (iObjectRegistry *object_reg);
00115 virtual bool HandleEvent (iEvent &Event);
00116
00117 struct eiEventHandler : public iEventHandler
00118 {
00119 SCF_DECLARE_EMBEDDED_IBASE(csAppPlugin);
00120 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00121 } scfiEventHandler;
00122 friend struct eiEventHandler;
00123 } *scfiPlugin;
00124 friend class csAppPlugin;
00125
00127 struct csModalInfo
00128 {
00129 csComponent* component;
00130 csComponent* old_focus;
00131 iBase* userdata;
00132 };
00136 csVector ModalInfo;
00137
00138 public:
00140 iObjectRegistry* object_reg;
00142 iVirtualClock* vc;
00144 iEventQueue* event_queue;
00146 iPluginManager* plugin_mgr;
00148 iVFS *VFS;
00150 csConfigAccess config;
00152 iFontServer *FontServer;
00154 iImageIO *ImageLoader;
00156 iKeyboardDriver* KeyboardDriver;
00158 iMouseDriver* MouseDriver;
00160 int Pal [cs_Color_Last];
00162 csComponent *MouseOwner;
00164 csComponent *KeyboardOwner;
00166 csComponent *FocusOwner;
00168 csComponent *LastMouseContainer;
00170 csSkin *skin;
00172 bool WindowListChanged;
00174 bool InsertMode;
00176 int ScreenWidth, ScreenHeight;
00178 iFont *DefaultFont;
00180 int DefaultFontSize;
00181
00183 csApp (iObjectRegistry *object_reg, csSkin &Skin);
00185 virtual ~csApp ();
00186
00188 virtual bool Initialize ();
00189
00191 void SetSkin (csSkin *Skin, bool DeleteOld = true);
00192
00194 virtual void StartFrame ();
00196 virtual void FinishFrame ();
00197
00199 void FlushEvents ();
00200
00202 iEvent *CreateEvent ()
00203 { return EventOutlet->CreateEvent (); }
00204
00206 void Post (iEvent *Event)
00207 { EventOutlet->Post (Event); }
00208
00210 void ShutDown ();
00211
00213 virtual void Idle ();
00214
00216 virtual void Draw ();
00217
00219 virtual void GetFont (iFont *&oFont, int &oFontSize);
00220
00222 void SetBackgroundStyle (csAppBackgroundStyle iBackgroundStyle);
00223
00225 void Printf (int mode, char const* format, ...);
00226
00228 void PrintfV (int mode, char const* format, va_list);
00229
00231 bool LoadTexture (const char *iTexName, const char *iTexParams,
00232 int iFlags);
00233
00235 virtual void PrepareTextures ();
00236
00238 csWSTexVector *GetTextures ()
00239 { return &Textures; }
00240
00242 iTextureHandle *GetTexture (const char *Name)
00243 {
00244 csWSTexture *tex = GetTextures ()->FindTexture (Name);
00245 return tex ? tex->GetHandle () : (iTextureHandle*)NULL;
00246 }
00247
00249 csMouse &GetMouse () { return *Mouse; }
00250
00252 void SetMouseCursor (csMouseCursorID ID) { MouseCursorID = ID; }
00253
00255 csMouseCursorID GetMouseCursor () { return MouseCursorID; }
00256
00258 csComponent *CaptureMouse (csComponent *who)
00259 { csComponent *c = MouseOwner; MouseOwner = who; return c; }
00260
00262 csComponent *CaptureKeyboard (csComponent *who)
00263 { csComponent *c = KeyboardOwner; KeyboardOwner = who; return c; }
00264
00266 csComponent *CaptureFocus (csComponent *who)
00267 { csComponent *c = FocusOwner; FocusOwner = who; return c; }
00268
00270 bool GetKeyState (int iKey);
00271
00273 csTicks GetCurrentTime ()
00274 { return CurrentTime; }
00275
00277 void WindowList ();
00278
00280 void SetWindowListSize (int iWidth, int iHeight)
00281 { WindowListWidth = iWidth; WindowListHeight = iHeight; }
00282
00284 virtual void Insert (csComponent *comp);
00285
00287 virtual void Delete (csComponent *comp);
00288
00294 bool StartModal (csComponent* comp, iBase* userdata);
00295
00299 void StopModal (int iCode = cscmdCancel);
00300
00305 csComponent* GetTopModalComponent ();
00306
00311 iBase* GetTopModalUserdata ();
00312
00314 void Dismiss (int iCode = cscmdCancel);
00315
00317 virtual bool PreHandleEvent (iEvent &Event);
00318
00320 virtual bool HandleEvent (iEvent &Event);
00321
00323 virtual bool PostHandleEvent (iEvent &Event);
00324
00326 virtual void NotifyDelete (csComponent *iComp);
00327
00329 virtual csSkin *GetSkin ();
00330
00332 void HintAdd (const char *iText, csComponent *iComp)
00333 { hints->Add (iText, iComp); }
00334
00336 void HintRemove (csComponent *iComp);
00337
00339 csHintManager &GetHintManager ()
00340 { return *hints; }
00341
00343 iFont *LoadFont (const char *iFontName)
00344 { return FontServer->LoadFont (iFontName); }
00345
00346
00347
00348
00349
00350
00352 int FindColor (int r, int g, int b);
00353
00355 int pplColor (int color)
00356 { return color & 0x80000000 ? (color & 0x7fffffff) << PhysColorShift : Pal [color]; }
00357
00359 void pplBox (int x, int y, int w, int h, int color)
00360 { GfxPpl.Box (x, y, w, h, pplColor (color)); }
00361
00363 void pplLine (float x1, float y1, float x2, float y2, int color)
00364 { GfxPpl.Line (x1, y1, x2, y2, pplColor (color)); }
00365
00367 void pplPixel (int x, int y, int color)
00368 { GfxPpl.Pixel (x, y, pplColor (color)); }
00369
00371 void pplText (int x, int y, int fg, int bg, iFont *Font, int FontSize, const char *s)
00372 { GfxPpl.Text (x, y, pplColor (fg), bg != -1 ? pplColor (bg) : bg, Font, FontSize, s); }
00373
00375 void pplPixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha)
00376 { GfxPpl.Pixmap (s2d, x, y, w, h, Alpha); }
00378 void pplTiledPixmap (csPixmap *s2d, int x, int y, int w, int h,
00379 int orgx, int orgy, uint8 Alpha)
00380 { GfxPpl.TiledPixmap (s2d, x, y, w, h, orgx, orgy, Alpha); }
00381
00383 void pplTexture (iTextureHandle *hTex, int sx, int sy, int sw, int sh,
00384 int tx, int ty, int tw, int th, uint8 Alpha = 0)
00385 { GfxPpl.Texture (hTex, sx, sy, sw, sh, tx, ty, tw, th, Alpha); }
00386
00388 void pplSaveArea (csImageArea *&Area, int x, int y, int w, int h)
00389 { GfxPpl.SaveArea (&Area, x, y, w, h); }
00391 void pplRestoreArea (csImageArea *Area, bool Free = false)
00392 { GfxPpl.RestoreArea (Area, Free); }
00394 void pplFreeArea (csImageArea *Area)
00395 { GfxPpl.FreeArea (Area); }
00396
00398 void pplClear (int color)
00399 { GfxPpl.Clear (pplColor (color)); }
00400
00402 void pplSetClipRect (int xmin, int ymin, int xmax, int ymax)
00403 { GfxPpl.SetClipRect (xmin, ymin, xmax, ymax); }
00404
00406 void pplSetClipRect (csRect &clip)
00407 { GfxPpl.SetClipRect (clip.xmin, clip.ymin, clip.xmax, clip.ymax); }
00408
00410 void pplRestoreClipRect ()
00411 { GfxPpl.RestoreClipRect (); }
00412
00414 bool ClipLine (float &x1, float &y1, float &x2, float &y2,
00415 int ClipX1, int ClipY1, int ClipX2, int ClipY2)
00416 { return GfxPpl.ClipLine (x1, y1, x2, y2, ClipX1, ClipY1, ClipX2, ClipY2); }
00417
00419 bool SwitchMouseCursor (csMouseCursorID Shape)
00420 { return GfxPpl.SwitchMouseCursor (Shape); }
00421
00423 void GetPixel (int x, int y, UByte &oR, UByte &oG, UByte &oB)
00424 { GfxPpl.GetPixel (x, y, oR, oG, oB); }
00425
00426
00427
00429 void pplPolygon3D (G3DPolygonDPFX &poly, UInt mode)
00430 { GfxPpl.Polygon3D (poly, mode); }
00431
00433 void pplClearZbuffer (int x1, int y1, int x2, int y2)
00434 { GfxPpl.ClearZbuffer (x1, y1, x2, y2); }
00435
00437 void pplClearZbuffer ()
00438 { GfxPpl.ClearZbuffer (); }
00439
00441 void SetZbufferMode (unsigned mode)
00442 { GfxPpl.SetZbufferMode (mode); }
00443
00445 void pplBeginDraw (unsigned mode)
00446 { GfxPpl.BeginDraw (mode); }
00447
00449 void pplInvalidate (csRect &rect)
00450 { GfxPpl.Invalidate (rect); }
00451
00461 void pplDontCacheFrame ()
00462 { GfxPpl.DontCacheFrame = true; }
00463
00468 iGraphics2D *GetG2D ()
00469 { return GfxPpl.G2D; }
00470
00475 iGraphics3D *GetG3D ()
00476 { return GfxPpl.G3D; }
00477
00478 protected:
00480 void InitializeSkin ();
00482 void SetupPalette ();
00483 };
00484
00485 #endif // __CSAPP_H__