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/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 fbWidth, fbHeight, Depth; 00107 00108 int vpLeft, vpTop, vpWidth, vpHeight; 00109 00115 int DisplayNumber; 00117 bool FullScreen; 00119 bool AllowResizing; 00121 csRGBpixel *Palette; 00123 bool PaletteAlloc[256]; 00128 int FrameBufferLocked; 00132 virtual void ChangeDepth (int d); 00136 virtual const char *GetName() const; 00137 00138 protected: 00140 int refreshRate; 00142 bool vsync; 00143 00144 void CreateDefaultFontCache (); 00145 00146 csString name; 00147 csRef<iEventHandler> weakEventHandler; 00148 00149 private: 00151 int FindRGBPalette (int r, int g, int b); 00156 bool Initialize (iObjectRegistry* r, int width, int height, 00157 int depth, void* memory, iOffscreenCanvasCallback* ofscb); 00158 00159 public: 00161 csGraphics2D (iBase*); 00162 00164 virtual ~csGraphics2D (); 00165 00167 virtual bool Initialize (iObjectRegistry*); 00169 virtual bool HandleEvent (iEvent&); 00170 00172 virtual bool Open (); 00174 virtual void Close (); 00175 00177 virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax); 00179 virtual void GetClipRect (int &xmin, int &ymin, int &xmax, int &ymax); 00180 00185 virtual bool BeginDraw (); 00187 virtual void FinishDraw (); 00188 00190 virtual void Print (csRect const* /*area*/ = 0) { } 00191 00193 virtual int GetPage (); 00195 virtual bool DoubleBuffer (bool Enable); 00197 virtual bool GetDoubleBufferState (); 00198 00200 virtual void Clear (int color); 00202 virtual void ClearAll (int color); 00203 00209 00210 void (*_DrawPixel) (csGraphics2D *This, int x, int y, int color); 00212 virtual void DrawPixel (int x, int y, int color) 00213 { _DrawPixel (this, x, y, color); } 00214 virtual void DrawPixels (csPixelCoord const* pixels, int num_pixels, 00215 int color); 00217 virtual void Blit (int x, int y, int width, int height, 00218 unsigned char const* data); 00219 00221 virtual void DrawLine (float x1, float y1, float x2, float y2, int color); 00223 virtual void DrawBox (int x, int y, int w, int h, int color); 00225 virtual void SetRGB (int i, int r, int g, int b); 00226 virtual int FindRGB (int r, int g, int b, int a = 255) 00227 { 00228 if (r < 0) r = 0; else if (r > 255) r = 255; 00229 if (g < 0) g = 0; else if (g > 255) g = 255; 00230 if (b < 0) b = 0; else if (b > 255) b = 255; 00231 if (a < 0) a = 0; else if (a > 255) a = 255; 00232 if (Depth == 8) 00233 return FindRGBPalette (r, g, b); 00234 return 00235 ((r >> (8 - pfmt.RedBits)) << pfmt.RedShift) | 00236 ((g >> (8 - pfmt.GreenBits)) << pfmt.GreenShift) | 00237 ((b >> (8 - pfmt.BlueBits)) << pfmt.BlueShift) | 00238 ((255 - a) << 24); 00239 /* Alpha is "inverted" so '-1' can be decomposed to a 00240 transparent color. (But alpha not be inverted, '-1' 00241 would be "opaque white". However, -1 is the color 00242 index for "transparent text background". */ 00243 } 00244 virtual void GetRGB (int color, int& r, int& g, int& b); 00245 virtual void GetRGB (int color, int& r, int& g, int& b, int& a); 00247 00248 virtual void Write (iFont *font , int x, int y, int fg, int bg, 00249 const char *text, uint flags = 0); 00250 virtual void Write (iFont *font , int x, int y, int fg, int bg, 00251 const wchar_t* text, uint flags = 0); 00253 00254 unsigned char* (*_GetPixelAt) (csGraphics2D *This, int x, int y); 00256 virtual unsigned char *GetPixelAt (int x, int y) 00257 { return _GetPixelAt (this, vpLeft+x, vpTop+y); } 00258 00266 virtual int GetPalEntryCount () 00267 { return pfmt.PalEntries; } 00268 00274 virtual int GetPixelBytes () 00275 { return pfmt.PixelBytes; } 00276 00280 virtual csPixelFormat const* GetPixelFormat () 00281 { return &pfmt; } 00282 00288 virtual csImageArea *SaveArea (int x, int y, int w, int h); 00290 virtual void RestoreArea (csImageArea *Area, bool Free = true); 00292 virtual void FreeArea (csImageArea *Area); 00293 00294 virtual bool SetGamma (float /*gamma*/) { return false; } 00295 virtual float GetGamma () const { return 1.0; } 00296 00297 virtual csPtr<iGraphics2D> CreateOffscreenCanvas ( 00298 void* memory, int width, int height, int depth, 00299 iOffscreenCanvasCallback* ofscb); 00300 00301 private: 00303 bool CLIPt (float denom, float num, float& tE, float& tL); 00304 public: 00305 00310 virtual bool ClipLine (float &x1, float &y1, float &x2, float &y2, 00311 int xmin, int ymin, int xmax, int ymax); 00312 00314 virtual iFontServer *GetFontServer () 00315 { return FontServer; } 00316 00317 virtual int GetWidth () { return vpWidth; } 00318 virtual int GetHeight () { return vpHeight; } 00319 00321 virtual csRGBpixel *GetPalette () 00322 { return pfmt.PalEntries ? Palette : 0; } 00323 00325 virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB); 00327 virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB, uint8 &oA); 00328 00333 virtual bool PerformExtension (char const* command, ...); 00334 00339 virtual bool PerformExtensionV (char const* command, va_list); 00340 00342 virtual csPtr<iImage> ScreenShot (); 00343 00345 virtual void AllowResize (bool /*iAllow*/) { }; 00346 00348 virtual bool Resize (int w, int h); 00349 00351 virtual iNativeWindow* GetNativeWindow (); 00352 00354 virtual bool GetFullScreen () 00355 { return FullScreen; } 00356 00360 virtual void SetFullScreen (bool b); 00361 00363 virtual bool SetMousePosition (int x, int y); 00364 00374 virtual bool SetMouseCursor (csMouseCursorID iShape); 00375 00383 virtual bool SetMouseCursor (iImage *image, const csRGBcolor* keycolor = 0, 00384 int hotspot_x = 0, int hotspot_y = 0, 00385 csRGBcolor fg = csRGBcolor(255,255,255), 00386 csRGBcolor bg = csRGBcolor(0,0,0)); 00387 00388 void SetViewport (int left, int top, int width, int height); 00389 void GetViewport (int& left, int& top, int& width, int& height) 00390 { left = vpLeft; top = vpTop; width = vpWidth; height = vpHeight; } 00391 00392 void GetFramebufferDimensions (int& width, int& height) 00393 { width = fbWidth; height = fbHeight; } 00394 00395 CS_EVENTHANDLER_NAMES("crystalspace.graphics2d.common") 00396 CS_EVENTHANDLER_NIL_CONSTRAINTS 00397 00398 protected: 00405 00406 static void DrawPixel8 (csGraphics2D *This, int x, int y, int color); 00408 static unsigned char *GetPixelAt8 (csGraphics2D *This, int x, int y); 00409 00411 static void DrawPixel16 (csGraphics2D *This, int x, int y, int color); 00413 static unsigned char *GetPixelAt16 (csGraphics2D *This, int x, int y); 00414 00416 static void DrawPixel32 (csGraphics2D *This, int x, int y, int color); 00418 static unsigned char *GetPixelAt32 (csGraphics2D *This, int x, int y); 00419 00422 // Virtual Alert function so it can be overridden by subclasses 00423 // of csGraphics2D. 00424 virtual void AlertV (int type, const char* title, const char* okMsg, 00425 const char* msg, va_list args); 00426 virtual void Alert (int type, const char* title, const char* okMsg, 00427 const char* msg, ...); 00428 virtual void AlertV (int type, const wchar_t* title, const wchar_t* okMsg, 00429 const wchar_t* msg, va_list args); 00430 virtual void Alert (int type, const wchar_t* title, const wchar_t* okMsg, 00431 const wchar_t* msg, ...); 00436 // Virtual SetTitle function so it can be overridden by subclasses 00437 // of csGraphics2D. 00438 virtual void SetTitle (const char* title); 00439 virtual void SetTitle (const wchar_t* title) 00440 { SetTitle (csString (title)); } 00445 virtual bool GetOptionDescription (int idx, csOptionDescription*); 00446 virtual bool SetOption (int id, csVariant* value); 00447 virtual bool GetOption (int id, csVariant* value); 00452 virtual bool DebugCommand (const char* cmd); 00453 virtual int GetSupportedTests () const { return 0; } 00454 virtual csPtr<iString> UnitTest () { return 0; } 00455 virtual csPtr<iString> StateTest () { return 0; } 00456 virtual csTicks Benchmark (int /*num_iterations*/) { return 0; } 00457 virtual csPtr<iString> Dump () { return 0; } 00458 virtual void Dump (iGraphics3D* /*g3d*/) { } 00460 }; 00461 00462 #include "csutil/deprecated_warn_on.h" 00463 00466 #endif // __CS_CSPLUGINCOMMON_CANVAS_GRAPH2D_H__
Generated for Crystal Space 1.4.0 by doxygen 1.5.8