1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
|
/*
Crystal Space Windowing System: Windowing System Application class interface
Copyright (C) 2001 by Jorrit Tyberghein
Copyright (C) 1998,1999 by Andrew Zabolotny <bit@eltech.ru>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CSAPP_H__
#define __CSAPP_H__
#include <stdarg.h>
#define CSWS_INTERNAL
#include "csws.h"
#include "cscomp.h"
#include "cswstex.h"
#include "cshints.h"
#include "csmouse.h"
#include "csgfxppl.h"
#include "csutil/cseventq.h"
#include "csutil/csstrvec.h"
#include "csutil/cfgacc.h"
#include "iutil/eventh.h"
#include "iutil/comp.h"
#include "iutil/event.h"
class csSkin;
struct iImageIO;
struct iKeyboardDriver;
struct iMouseDriver;
struct iObjectRegistry;
struct iPluginManager;
struct iVirtualClock;
struct iEventQueue;
/**
* Application's background styles
*/
enum csAppBackgroundStyle
{
/// Nothing: use only if desktop is not visible to avoid extra drawing
csabsNothing = 0,
/// Solid background of palette[0] color
csabsSolid
};
/**
* This class is a top-level CrystalSpace Windowing Toolkit object.
*<p>
* Generally there should be only one object of this class.
* Usually it is the root of entire window hierarchy.
* This class also owns the application-global mouse object,
* event queue object, graphics pipeline and some others.
*<p>
* The Crystal Space application is a regular plugin from the
* system driver's point of view.
*/
class csApp : public csComponent
{
protected:
friend class csMouse;
/// The graphics pipeline
csGraphicsPipeline GfxPpl;
/// The mouse pointer
csMouse *Mouse;
/// The list of windowing system textures
csWSTexVector Textures;
/// The hints manager
csHintManager *hints;
/// Window list width and height
int WindowListWidth, WindowListHeight;
/// Current & old mouse pointer ID
csMouseCursorID MouseCursorID, OldMouseCursorID;
/// The code that dialog passed to Dismiss ()
int DismissCode;
/// This is equal to 8 if any of physical r,g,b masks is 0xff000000
int PhysColorShift;
/// The time at the start of current frame
csTicks CurrentTime;
/// The system event outlet
iEventOutlet *EventOutlet;
/// Application background style
csAppBackgroundStyle BackgroundStyle;
/// Are we inbetween StartFrame() and FinishFrame()?
bool InFrame;
/// The iComponent interface
class csAppPlugin : public iComponent
{
public:
SCF_DECLARE_IBASE;
/// The parent application
csApp *app;
/// Initialize
csAppPlugin (csApp *iParent);
/// Initialize the application plugin
virtual bool Initialize (iObjectRegistry *object_reg);
/// Handle a event and return true if processed
virtual bool HandleEvent (iEvent &Event);
struct eiEventHandler : public iEventHandler
{
SCF_DECLARE_EMBEDDED_IBASE(csAppPlugin);
virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
} scfiEventHandler;
friend struct eiEventHandler;
} *scfiPlugin;
friend class csAppPlugin;
/// A structure for keeping modal information on a stack.
struct csModalInfo
{
csComponent* component; // Component that is modal
csComponent* old_focus; // Old focus before this component was modal
iBase* userdata; // Userdata
};
/**
* This is a stack of csModalInfo instances to keep track of modality.
*/
csVector ModalInfo;
public:
/// The object registry.
iObjectRegistry* object_reg;
/// The virtual clock.
iVirtualClock* vc;
/// The event queue.
iEventQueue* event_queue;
/// The plugin manager.
iPluginManager* plugin_mgr;
/// The virtual file system
iVFS *VFS;
/// The system configuration
csConfigAccess config;
/// The font server
iFontServer *FontServer;
/// The image loader
iImageIO *ImageLoader;
/// Keyboard driver
iKeyboardDriver* KeyboardDriver;
/// Mouse driver
iMouseDriver* MouseDriver;
/// Application's adaptive palette
int Pal [cs_Color_Last];
/// The component that captured the mouse
csComponent *MouseOwner;
/// The component that captured the keyboard
csComponent *KeyboardOwner;
/// The component that captured all focused events (mouse & keyboard)
csComponent *FocusOwner;
/// The component that the mouse was last over
csComponent *LastMouseContainer;
/// The global skin repository
csSkin *skin;
/// This is set to TRUE each time top-level window list changes
bool WindowListChanged;
/// Global "Insert" key state
bool InsertMode;
/// Screen width and height (application can be actually smaller)
int ScreenWidth, ScreenHeight;
/// Default font
iFont *DefaultFont;
/// Default font size
int DefaultFontSize;
/// Initialize windowing system by giving a system driver and a skin
csApp (iObjectRegistry *object_reg, csSkin &Skin);
/// Deinitialize windowing system
virtual ~csApp ();
/// Set up application layout (read configs, create windows, menus etc)
virtual bool Initialize ();
/// Set the skin of the application
void SetSkin (csSkin *Skin, bool DeleteOld = true);
/// This is called once per frame by HandleEvent ()
virtual void StartFrame ();
/// This is called at the end of every frame
virtual void FinishFrame ();
/// Process all events in the queue and refresh the screen
void FlushEvents ();
/// Create a new event object: NEVER create event objects with `new'
iEvent *CreateEvent ()
{ return EventOutlet->CreateEvent (); }
/// Add a previously created event to event queue
void Post (iEvent *Event)
{ EventOutlet->Post (Event); }
/// Shut down the program
void ShutDown ();
/// The windowing system is idle: do some lazy work
virtual void Idle ();
/// Draw the application background
virtual void Draw ();
/// Return default font and font size
virtual void GetFont (iFont *&oFont, int &oFontSize);
/// Set application background style
void SetBackgroundStyle (csAppBackgroundStyle iBackgroundStyle);
/// Display a string on the console using almost usual printf() syntax
void Printf (int mode, char const* format, ...) CS_GNUC_PRINTF (3, 4);
/// Display a string on the console using almost usual printf() syntax
void PrintfV (int mode, char const* format, va_list) CS_GNUC_PRINTF (3, 0);
/// Add a single texture to application's texture list
bool LoadTexture (const char *iTexName, const char *iTexParams,
int iFlags);
/// Prepare textures for usage (register them with the graphics driver)
virtual void PrepareTextures ();
/// Return application's texture list
csWSTexVector *GetTextures ()
{ return &Textures; }
/// Find a texture by name
iTextureHandle *GetTexture (const char *Name)
{
csWSTexture *tex = GetTextures ()->FindTexture (Name);
return tex ? tex->GetHandle () : (iTextureHandle*)NULL;
}
/// Return application's global mouse object
csMouse &GetMouse () { return *Mouse; }
/// Set mouse cursor pointer
void SetMouseCursor (csMouseCursorID ID) { MouseCursorID = ID; }
/// Query mouse cursor pointer
csMouseCursorID GetMouseCursor () { return MouseCursorID; }
/// Capture all mouse events (or disable capture if NULL)
csComponent *CaptureMouse (csComponent *who)
{ csComponent *c = MouseOwner; MouseOwner = who; return c; }
/// Capture all keyboard events (or disable capture if NULL)
csComponent *CaptureKeyboard (csComponent *who)
{ csComponent *c = KeyboardOwner; KeyboardOwner = who; return c; }
/// Capture all focused events (or disable capture if NULL)
csComponent *CaptureFocus (csComponent *who)
{ csComponent *c = FocusOwner; FocusOwner = who; return c; }
/// Query the current state of a key
bool GetKeyState (int iKey);
/// Query current time
csTicks GetCurrentTime ()
{ return CurrentTime; }
/// Show window list
void WindowList ();
/// Set window list size
void SetWindowListSize (int iWidth, int iHeight)
{ WindowListWidth = iWidth; WindowListHeight = iHeight; }
/// Insert a child component
virtual void Insert (csComponent *comp);
/// Delete a child component
virtual void Delete (csComponent *comp);
/**
* Set modality state on a component. When the component is dismissed
* StopModal() will be called automatically. This function returns
* immediatelly. StartModal() can fail if the component is already modal.
*/
bool StartModal (csComponent* comp, iBase* userdata);
/**
* Stop top-level modality state.
*/
void StopModal (int iCode = cscmdCancel);
/**
* Get the top component which is currently modal.
* Or NULL if not in modality.
*/
csComponent* GetTopModalComponent ();
/**
* Get the userdata for the top modal component.
* Or NULL if not in modality.
*/
iBase* GetTopModalUserdata ();
/// Dismiss a dialog box with given return code
void Dismiss (int iCode = cscmdCancel);
/// Handle a event before all others
virtual bool PreHandleEvent (iEvent &Event);
/// Send event to all childs and return processed status
virtual bool HandleEvent (iEvent &Event);
/// Handle a event if nobody eaten it.
virtual bool PostHandleEvent (iEvent &Event);
/// Every time a component is deleted, this routine is called
virtual void NotifyDelete (csComponent *iComp);
/// Get the closest in window hierarchy skin object
virtual csSkin *GetSkin ();
/// Associate a hint with given component
void HintAdd (const char *iText, csComponent *iComp)
{ hints->Add (iText, iComp); }
/// Remove the hint associated with given component
void HintRemove (csComponent *iComp);
/// Get the hint manager object
csHintManager &GetHintManager ()
{ return *hints; }
/// Load a font and return its handle or NULL
iFont *LoadFont (const char *iFontName)
{ return FontServer->LoadFont (iFontName); }
/*
* The following methods are simple redirectors to csGraphicsPipeline
* object (which is private property of csApp class).
*/
/// Return a color identifier given R,G,B (each 0..255)
int FindColor (int r, int g, int b);
/// Convert a logical color into physical
int pplColor (int color)
{ return color & 0x80000000 ? (color & 0x7fffffff) << PhysColorShift : Pal [color]; }
/// Draw a box
void pplBox (int x, int y, int w, int h, int color)
{ GfxPpl.Box (x, y, w, h, pplColor (color)); }
/// Draw a line
void pplLine (float x1, float y1, float x2, float y2, int color)
{ GfxPpl.Line (x1, y1, x2, y2, pplColor (color)); }
/// Draw a pixel
void pplPixel (int x, int y, int color)
{ GfxPpl.Pixel (x, y, pplColor (color)); }
/// Draw a text string: if bg < 0 background is not drawn
void pplText (int x, int y, int fg, int bg, iFont *Font, int FontSize, const char *s)
{ GfxPpl.Text (x, y, pplColor (fg), bg != -1 ? pplColor (bg) : bg, Font, FontSize, s); }
/// Draw a (scaled) pixmap
void pplPixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha)
{ GfxPpl.Pixmap (s2d, x, y, w, h, Alpha); }
/// Draw a (unscaled but tiled) pixmap
void pplTiledPixmap (csPixmap *s2d, int x, int y, int w, int h,
int orgx, int orgy, uint8 Alpha)
{ GfxPpl.TiledPixmap (s2d, x, y, w, h, orgx, orgy, Alpha); }
/// Draw a (part) of texture (possibly scaled) in given screen rectangle
void pplTexture (iTextureHandle *hTex, int sx, int sy, int sw, int sh,
int tx, int ty, int tw, int th, uint8 Alpha = 0)
{ GfxPpl.Texture (hTex, sx, sy, sw, sh, tx, ty, tw, th, Alpha); }
/// Save a part of screen
void pplSaveArea (csImageArea *&Area, int x, int y, int w, int h)
{ GfxPpl.SaveArea (&Area, x, y, w, h); }
/// Restore a part of screen
void pplRestoreArea (csImageArea *Area, bool Free = false)
{ GfxPpl.RestoreArea (Area, Free); }
/// Free buffer used to keep an area of screen
void pplFreeArea (csImageArea *Area)
{ GfxPpl.FreeArea (Area); }
/// Clear page with specified color
void pplClear (int color)
{ GfxPpl.Clear (pplColor (color)); }
/// Set clipping rectangle: SHOULD CALL pplRestoreClipRect() AFTER DRAWING!
void pplSetClipRect (int xmin, int ymin, int xmax, int ymax)
{ GfxPpl.SetClipRect (xmin, ymin, xmax, ymax); }
/// Same, but with csRect argument
void pplSetClipRect (csRect &clip)
{ GfxPpl.SetClipRect (clip.xmin, clip.ymin, clip.xmax, clip.ymax); }
/// Restore clipping rectangle to (0, 0, ScreenW, ScreenH);
void pplRestoreClipRect ()
{ GfxPpl.RestoreClipRect (); }
/// Clip a line against a rectangle and return true if its clipped out
bool ClipLine (float &x1, float &y1, float &x2, float &y2,
int ClipX1, int ClipY1, int ClipX2, int ClipY2)
{ return GfxPpl.ClipLine (x1, y1, x2, y2, ClipX1, ClipY1, ClipX2, ClipY2); }
/// Change system mouse cursor and return success status
bool SwitchMouseCursor (csMouseCursorID Shape)
{ return GfxPpl.SwitchMouseCursor (Shape); }
/// Get R,G,B at given screen location
void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB)
{ GfxPpl.GetPixel (x, y, oR, oG, oB); }
//--- 3D drawing ---//
/// Draw a 3D polygon
void pplPolygon3D (G3DPolygonDPFX &poly, uint mode)
{ GfxPpl.Polygon3D (poly, mode); }
/// Clear the Z-buffer in the given area
void pplClearZbuffer (int x1, int y1, int x2, int y2)
{ GfxPpl.ClearZbuffer (x1, y1, x2, y2); }
/// Clear the entire Z-buffer (takes effect before next 3D draw operation)
void pplClearZbuffer ()
{ GfxPpl.ClearZbuffer (); }
/// Set the respective Z-buffer mode (one of CS_ZBUF_XXX constants)
void SetZbufferMode (unsigned mode)
{ GfxPpl.SetZbufferMode (mode); }
/// Begin drawing: users of CSWS should NEVER invoke G2D/G3D->BeginDraw!
void pplBeginDraw (unsigned mode)
{ GfxPpl.BeginDraw (mode); }
/// Force blitting of the respective rectangle at the end of frame
void pplInvalidate (csRect &rect)
{ GfxPpl.Invalidate (rect); }
/**
* Tell the graphics pipeline that you are going to update
* the entire screen during NEXT frame. This will force graphics
* pipeline to NOT cache the image of the current frame so that it
* can be propagated to next frame (if during next frame you are
* going to repaint just a part of screen, propagating image
* changes through multiple video pages is a MUST, otherwise
* you will get flickering images).
*/
void pplDontCacheFrame ()
{ GfxPpl.DontCacheFrame = true; }
/**
* Get the pointer to 2D graphics driver for direct manipulations.
* WARNING! Don't abuse of this function!
*/
iGraphics2D *GetG2D ()
{ return GfxPpl.G2D; }
/**
* Get the pointer to 2D graphics driver for direct manipulations.
* WARNING! Don't abuse of this function!
*/
iGraphics3D *GetG3D ()
{ return GfxPpl.G3D; }
protected:
/// Initialize all skin slices with textures and colors etc
void InitializeSkin ();
/// setup palette
void SetupPalette ();
};
#endif // __CSAPP_H__
|