csplugincommon/canvas/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 00027 #include "csextern.h" 00028 00029 #include "csutil/cfgacc.h" 00030 #include "csutil/scf.h" 00031 #include "csutil/scf_implementation.h" 00032 #include "csutil/weakref.h" 00033 00034 #include "iutil/comp.h" 00035 #include "iutil/dbghelp.h" 00036 #include "iutil/eventh.h" 00037 #include "iutil/plugin.h" 00038 #include "iutil/pluginconfig.h" 00039 #include "iutil/string.h" 00040 #include "ivideo/fontserv.h" 00041 #include "ivideo/graph2d.h" 00042 #include "ivideo/natwin.h" 00043 00048 struct iObjectRegistry; 00049 struct iPluginManager; 00050 00051 class csFontCache; 00052 00053 #include "csutil/win32/msvc_deprecated_warn_off.h" 00054 00062 class CS_CRYSTALSPACE_EXPORT csGraphics2D : 00063 public scfImplementation7<csGraphics2D, 00064 iGraphics2D, iComponent, iNativeWindow, iNativeWindowManager, 00065 iPluginConfig, iDebugHelper, iEventHandler> 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 csString win_title; 00104 00106 int Width, Height, Depth; 00107 00108 int vpWidth, vpHeight; 00109 bool vpSet; 00110 00116 int DisplayNumber; 00118 bool FullScreen; 00120 bool AllowResizing; 00122 csRGBpixel *Palette; 00124 bool PaletteAlloc[256]; 00129 int FrameBufferLocked; 00133 virtual void ChangeDepth (int d); 00137 virtual const char *GetName() const; 00138 00139 protected: 00141 int refreshRate; 00143 bool vsync; 00144 00145 void CreateDefaultFontCache (); 00146 00147 csString name; 00148 csRef<iEventHandler> weakEventHandler; 00149 00150 private: 00152 int FindRGBPalette (int r, int g, int b); 00157 bool Initialize (iObjectRegistry* r, int width, int height, 00158 int depth, void* memory, iOffscreenCanvasCallback* ofscb); 00159 00160 public: 00162 csGraphics2D (iBase*); 00163 00165 virtual ~csGraphics2D (); 00166 00168 virtual bool Initialize (iObjectRegistry*); 00170 virtual bool HandleEvent (iEvent&); 00171 00173 virtual bool Open (); 00175 virtual void Close (); 00176 00178 virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax); 00180 virtual void GetClipRect (int &xmin, int &ymin, int &xmax, int &ymax); 00181 00186 virtual bool BeginDraw (); 00188 virtual void FinishDraw (); 00189 00191 virtual void Print (csRect const* /*area*/ = 0) { } 00192 00194 virtual int GetPage (); 00196 virtual bool DoubleBuffer (bool Enable); 00198 virtual bool GetDoubleBufferState (); 00199 00201 virtual void Clear (int color); 00203 virtual void ClearAll (int color); 00204 00210 00211 void (*_DrawPixel) (csGraphics2D *This, int x, int y, int color); 00213 virtual void DrawPixel (int x, int y, int color) 00214 { _DrawPixel (this, x, y, color); } 00215 virtual void DrawPixels (csPixelCoord const* pixels, int num_pixels, 00216 int color); 00218 virtual void Blit (int x, int y, int width, int height, 00219 unsigned char const* data); 00220 00222 virtual void DrawLine (float x1, float y1, float x2, float y2, int color); 00224 virtual void DrawBox (int x, int y, int w, int h, int color); 00226 virtual void SetRGB (int i, int r, int g, int b); 00227 virtual int FindRGB (int r, int g, int b, int a = 255) 00228 { 00229 if (r < 0) r = 0; else if (r > 255) r = 255; 00230 if (g < 0) g = 0; else if (g > 255) g = 255; 00231 if (b < 0) b = 0; else if (b > 255) b = 255; 00232 if (a < 0) a = 0; else if (a > 255) a = 255; 00233 if (Depth == 8) 00234 return FindRGBPalette (r, g, b); 00235 return 00236 ((r >> (8 - pfmt.RedBits)) << pfmt.RedShift) | 00237 ((g >> (8 - pfmt.GreenBits)) << pfmt.GreenShift) | 00238 ((b >> (8 - pfmt.BlueBits)) << pfmt.BlueShift) | 00239 ((255 - a) << 24); 00240 /* Alpha is "inverted" so '-1' can be decomposed to a 00241 transparent color. (But alpha not be inverted, '-1' 00242 would be "opaque white". However, -1 is the color 00243 index for "transparent text background". */ 00244 } 00245 virtual void GetRGB (int color, int& r, int& g, int& b); 00246 virtual void GetRGB (int color, int& r, int& g, int& b, int& a); 00248 00249 virtual void Write (iFont *font , int x, int y, int fg, int bg, 00250 const char *text, uint flags = 0); 00251 virtual void Write (iFont *font , int x, int y, int fg, int bg, 00252 const wchar_t* text, uint flags = 0); 00254 00255 unsigned char* (*_GetPixelAt) (csGraphics2D *This, int x, int y); 00257 virtual unsigned char *GetPixelAt (int x, int y) 00258 { return _GetPixelAt (this, x, y); } 00259 00267 virtual int GetPalEntryCount () 00268 { return pfmt.PalEntries; } 00269 00275 virtual int GetPixelBytes () 00276 { return pfmt.PixelBytes; } 00277 00281 virtual csPixelFormat const* GetPixelFormat () 00282 { return &pfmt; } 00283 00289 virtual csImageArea *SaveArea (int x, int y, int w, int h); 00291 virtual void RestoreArea (csImageArea *Area, bool Free = true); 00293 virtual void FreeArea (csImageArea *Area); 00294 00295 virtual bool SetGamma (float /*gamma*/) { return false; } 00296 virtual float GetGamma () const { return 1.0; } 00297 00298 virtual csPtr<iGraphics2D> CreateOffscreenCanvas ( 00299 void* memory, int width, int height, int depth, 00300 iOffscreenCanvasCallback* ofscb); 00301 00302 private: 00304 bool CLIPt (float denom, float num, float& tE, float& tL); 00305 public: 00306 00311 virtual bool ClipLine (float &x1, float &y1, float &x2, float &y2, 00312 int xmin, int ymin, int xmax, int ymax); 00313 00315 virtual iFontServer *GetFontServer () 00316 { return FontServer; } 00317 00318 virtual int GetWidth () 00319 { return vpSet ? vpWidth : Width; } 00320 virtual int GetHeight () 00321 { return vpSet ? vpHeight : Height; } 00322 00324 virtual csRGBpixel *GetPalette () 00325 { return pfmt.PalEntries ? Palette : 0; } 00326 00328 virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB); 00330 virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB, uint8 &oA); 00331 00336 virtual bool PerformExtension (char const* command, ...); 00337 00342 virtual bool PerformExtensionV (char const* command, va_list); 00343 00345 virtual csPtr<iImage> ScreenShot (); 00346 00348 virtual void AllowResize (bool /*iAllow*/) { }; 00349 00351 virtual bool Resize (int w, int h); 00352 00354 virtual iNativeWindow* GetNativeWindow (); 00355 00357 virtual bool GetFullScreen () 00358 { return FullScreen; } 00359 00363 virtual void SetFullScreen (bool b); 00364 00366 virtual bool SetMousePosition (int x, int y); 00367 00377 virtual bool SetMouseCursor (csMouseCursorID iShape); 00378 00386 virtual bool SetMouseCursor (iImage *image, const csRGBcolor* keycolor = 0, 00387 int hotspot_x = 0, int hotspot_y = 0, 00388 csRGBcolor fg = csRGBcolor(255,255,255), 00389 csRGBcolor bg = csRGBcolor(0,0,0)); 00390 00391 CS_EVENTHANDLER_NAMES("crystalspace.graphics2d.common") 00392 CS_EVENTHANDLER_NIL_CONSTRAINTS 00393 00394 protected: 00401 00402 static void DrawPixel8 (csGraphics2D *This, int x, int y, int color); 00404 static unsigned char *GetPixelAt8 (csGraphics2D *This, int x, int y); 00405 00407 static void DrawPixel16 (csGraphics2D *This, int x, int y, int color); 00409 static unsigned char *GetPixelAt16 (csGraphics2D *This, int x, int y); 00410 00412 static void DrawPixel32 (csGraphics2D *This, int x, int y, int color); 00414 static unsigned char *GetPixelAt32 (csGraphics2D *This, int x, int y); 00415 00418 // Virtual Alert function so it can be overridden by subclasses 00419 // of csGraphics2D. 00420 virtual void AlertV (int type, const char* title, const char* okMsg, 00421 const char* msg, va_list args); 00422 virtual void Alert (int type, const char* title, const char* okMsg, 00423 const char* msg, ...); 00424 virtual void AlertV (int type, const wchar_t* title, const wchar_t* okMsg, 00425 const wchar_t* msg, va_list args); 00426 virtual void Alert (int type, const wchar_t* title, const wchar_t* okMsg, 00427 const wchar_t* msg, ...); 00432 // Virtual SetTitle function so it can be overridden by subclasses 00433 // of csGraphics2D. 00434 virtual void SetTitle (const char* title); 00435 virtual void SetTitle (const wchar_t* title) 00436 { SetTitle (csString (title)); } 00441 virtual bool GetOptionDescription (int idx, csOptionDescription*); 00442 virtual bool SetOption (int id, csVariant* value); 00443 virtual bool GetOption (int id, csVariant* value); 00448 virtual bool DebugCommand (const char* cmd); 00449 virtual int GetSupportedTests () const { return 0; } 00450 virtual csPtr<iString> UnitTest () { return 0; } 00451 virtual csPtr<iString> StateTest () { return 0; } 00452 virtual csTicks Benchmark (int /*num_iterations*/) { return 0; } 00453 virtual csPtr<iString> Dump () { return 0; } 00454 virtual void Dump (iGraphics3D* /*g3d*/) { } 00456 }; 00457 00458 #include "csutil/win32/msvc_deprecated_warn_on.h" 00459 00462 #endif // __CS_CSPLUGINCOMMON_CANVAS_GRAPH2D_H__
Generated for Crystal Space 1.2.1 by doxygen 1.5.3