Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
graph2d.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 1998-2001 by Jorrit Tyberghein 00003 Written by Andrew Zabolotny <bit@eltech.ru> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSPLUGINCOMMON_CANVAS_GRAPH2D_H__ 00021 #define __CS_CSPLUGINCOMMON_CANVAS_GRAPH2D_H__ 00022 00026 #include "csextern.h" 00027 00028 #include "csutil/cfgacc.h" 00029 #include "csutil/scf.h" 00030 #include "csutil/scf_implementation.h" 00031 #include "csutil/weakref.h" 00032 00033 #include "iutil/comp.h" 00034 #include "iutil/dbghelp.h" 00035 #include "iutil/eventh.h" 00036 #include "iutil/plugin.h" 00037 #include "iutil/pluginconfig.h" 00038 #include "ivideo/fontserv.h" 00039 #include "ivideo/graph2d.h" 00040 #include "ivideo/natwin.h" 00041 00046 struct iObjectRegistry; 00047 struct iPluginManager; 00048 00049 class csFontCache; 00050 00058 class CS_CRYSTALSPACE_EXPORT csGraphics2D : 00059 public scfImplementation6<csGraphics2D, 00060 iGraphics2D, 00061 iComponent, 00062 iNativeWindow, 00063 iNativeWindowManager, 00064 iPluginConfig, 00065 iDebugHelper> 00066 { 00067 public: 00069 csConfigAccess config; 00070 00072 int ClipX1, ClipX2, ClipY1, ClipY2; 00073 00075 csPixelFormat pfmt; 00076 00078 unsigned char *Memory; 00079 00081 bool is_open; 00082 00084 int *LineAddress; 00085 00087 iObjectRegistry* object_reg; 00089 csWeakRef<iPluginManager> plugin_mgr; 00090 00095 csRef<iOffscreenCanvasCallback> ofscb; 00096 00098 csWeakRef<iFontServer> FontServer; 00100 csFontCache* fontCache; 00101 00103 char* win_title; 00104 00106 int Width, Height, Depth; 00112 int DisplayNumber; 00114 bool FullScreen; 00116 bool AllowResizing; 00118 csRGBpixel *Palette; 00120 bool PaletteAlloc[256]; 00125 int FrameBufferLocked; 00129 virtual void ChangeDepth (int d); 00130 00131 protected: 00133 int refreshRate; 00135 bool vsync; 00136 00137 void CreateDefaultFontCache (); 00138 private: 00140 int FindRGBPalette (int r, int g, int b); 00145 bool Initialize (iObjectRegistry* r, int width, int height, 00146 int depth, void* memory, iOffscreenCanvasCallback* ofscb); 00147 00148 public: 00150 csGraphics2D (iBase*); 00152 virtual ~csGraphics2D (); 00153 00155 virtual bool Initialize (iObjectRegistry*); 00157 virtual bool HandleEvent (iEvent&); 00158 00160 virtual bool Open (); 00162 virtual void Close (); 00163 00165 virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax); 00167 virtual void GetClipRect (int &xmin, int &ymin, int &xmax, int &ymax); 00168 00173 virtual bool BeginDraw (); 00175 virtual void FinishDraw (); 00176 00178 virtual void Print (csRect const* /*area*/ = 0) { } 00179 00181 virtual int GetPage (); 00183 virtual bool DoubleBuffer (bool Enable); 00185 virtual bool GetDoubleBufferState (); 00186 00188 virtual void Clear (int color); 00190 virtual void ClearAll (int color); 00191 00197 00198 void (*_DrawPixel) (csGraphics2D *This, int x, int y, int color); 00200 virtual void DrawPixel (int x, int y, int color) 00201 { _DrawPixel (this, x, y, color); } 00202 virtual void DrawPixels (csPixelCoord const* pixels, int num_pixels, 00203 int color); 00205 virtual void Blit (int x, int y, int width, int height, 00206 unsigned char const* data); 00207 00209 virtual void DrawLine (float x1, float y1, float x2, float y2, int color); 00211 virtual void DrawBox (int x, int y, int w, int h, int color); 00213 virtual void SetRGB (int i, int r, int g, int b); 00214 virtual int FindRGB (int r, int g, int b, int a = 255) 00215 { 00216 if (r < 0) r = 0; else if (r > 255) r = 255; 00217 if (g < 0) g = 0; else if (g > 255) g = 255; 00218 if (b < 0) b = 0; else if (b > 255) b = 255; 00219 if (a < 0) a = 0; else if (a > 255) a = 255; 00220 if (Depth == 8) 00221 return FindRGBPalette (r, g, b); 00222 return 00223 ((r >> (8 - pfmt.RedBits)) << pfmt.RedShift) | 00224 ((g >> (8 - pfmt.GreenBits)) << pfmt.GreenShift) | 00225 ((b >> (8 - pfmt.BlueBits)) << pfmt.BlueShift) | 00226 ((255 - a) << 24); 00227 /* Alpha is "inverted" so '-1' can be decomposed to a 00228 transparent color. (But alpha not be inverted, '-1' 00229 would be "opaque white". However, -1 is the color 00230 index for "transparent text background". */ 00231 } 00232 virtual void GetRGB (int color, int& r, int& g, int& b); 00233 virtual void GetRGB (int color, int& r, int& g, int& b, int& a); 00235 virtual void Write (iFont *font , int x, int y, int fg, int bg, 00236 const char *text, uint flags = 0); 00237 virtual void WriteBaseline (iFont *font , int x, int y, int fg, int bg, 00238 const char *text); 00240 unsigned char* (*_GetPixelAt) (csGraphics2D *This, int x, int y); 00242 virtual unsigned char *GetPixelAt (int x, int y) 00243 { return _GetPixelAt (this, x, y); } 00244 00252 virtual int GetPalEntryCount () 00253 { return pfmt.PalEntries; } 00254 00260 virtual int GetPixelBytes () 00261 { return pfmt.PixelBytes; } 00262 00266 virtual csPixelFormat const* GetPixelFormat () 00267 { return &pfmt; } 00268 00274 virtual csImageArea *SaveArea (int x, int y, int w, int h); 00276 virtual void RestoreArea (csImageArea *Area, bool Free = true); 00278 virtual void FreeArea (csImageArea *Area); 00279 00280 virtual bool SetGamma (float /*gamma*/) { return false; } 00281 virtual float GetGamma () const { return 1.0; } 00282 00283 virtual csPtr<iGraphics2D> CreateOffscreenCanvas ( 00284 void* memory, int width, int height, int depth, 00285 iOffscreenCanvasCallback* ofscb); 00286 00287 private: 00289 bool CLIPt (float denom, float num, float& tE, float& tL); 00290 public: 00291 00296 virtual bool ClipLine (float &x1, float &y1, float &x2, float &y2, 00297 int xmin, int ymin, int xmax, int ymax); 00298 00300 virtual iFontServer *GetFontServer () 00301 { return FontServer; } 00302 00304 virtual int GetWidth () 00305 { return Width; } 00307 virtual int GetHeight () 00308 { return Height; } 00309 00311 virtual csRGBpixel *GetPalette () 00312 { return pfmt.PalEntries ? Palette : 0; } 00313 00315 virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB); 00317 virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB, uint8 &oA); 00318 00323 virtual bool PerformExtension (char const* command, ...); 00324 00329 virtual bool PerformExtensionV (char const* command, va_list); 00330 00332 virtual csPtr<iImage> ScreenShot (); 00333 00335 virtual void AllowResize (bool /*iAllow*/) { }; 00336 00338 virtual bool Resize (int w, int h); 00339 00341 virtual iNativeWindow* GetNativeWindow (); 00342 00344 virtual bool GetFullScreen () 00345 { return FullScreen; } 00346 00350 virtual void SetFullScreen (bool b); 00351 00353 virtual bool SetMousePosition (int x, int y); 00354 00364 virtual bool SetMouseCursor (csMouseCursorID iShape); 00365 00373 virtual bool SetMouseCursor (iImage *image, const csRGBcolor* keycolor = 0, 00374 int hotspot_x = 0, int hotspot_y = 0, 00375 csRGBcolor fg = csRGBcolor(255,255,255), 00376 csRGBcolor bg = csRGBcolor(0,0,0)); 00377 00378 struct EventHandler : public scfImplementation1<EventHandler, iEventHandler> 00379 { 00380 private: 00381 csGraphics2D* parent; 00382 public: 00383 EventHandler (csGraphics2D* parent) : scfImplementationType (this), 00384 parent(parent) {} 00385 virtual bool HandleEvent (iEvent& e) { return parent->HandleEvent(e); } 00386 } * scfiEventHandler; 00387 00388 protected: 00395 00396 static void DrawPixel8 (csGraphics2D *This, int x, int y, int color); 00398 static unsigned char *GetPixelAt8 (csGraphics2D *This, int x, int y); 00399 00401 static void DrawPixel16 (csGraphics2D *This, int x, int y, int color); 00403 static unsigned char *GetPixelAt16 (csGraphics2D *This, int x, int y); 00404 00406 static void DrawPixel32 (csGraphics2D *This, int x, int y, int color); 00408 static unsigned char *GetPixelAt32 (csGraphics2D *This, int x, int y); 00409 00412 // Virtual Alert function so it can be overridden by subclasses 00413 // of csGraphics2D. 00414 virtual void AlertV (int type, const char* title, const char* okMsg, 00415 const char* msg, va_list args); 00416 virtual void Alert (int type, const char* title, const char* okMsg, 00417 const char* msg, ...); 00422 // Virtual SetTitle function so it can be overridden by subclasses 00423 // of csGraphics2D. 00424 virtual void SetTitle (const char* title); 00429 virtual bool GetOptionDescription (int idx, csOptionDescription*); 00430 virtual bool SetOption (int id, csVariant* value); 00431 virtual bool GetOption (int id, csVariant* value); 00436 virtual bool DebugCommand (const char* cmd); 00437 virtual int GetSupportedTests () const { return 0; } 00438 virtual csPtr<iString> UnitTest () { return 0; } 00439 virtual csPtr<iString> StateTest () { return 0; } 00440 virtual csTicks Benchmark (int /*num_iterations*/) { return 0; } 00441 virtual csPtr<iString> Dump () { return 0; } 00442 virtual void Dump (iGraphics3D* /*g3d*/) { } 00444 }; 00445 00448 #endif // __CS_CSPLUGINCOMMON_CANVAS_GRAPH2D_H__
Generated for Crystal Space by doxygen 1.4.4