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 bool is_open; 00076 00078 iObjectRegistry* object_reg; 00080 csWeakRef<iPluginManager> plugin_mgr; 00081 00083 csWeakRef<iFontServer> FontServer; 00085 csFontCache* fontCache; 00086 00088 csString win_title; 00089 00091 int fbWidth, fbHeight, Depth; 00092 00093 int vpLeft, vpTop, vpWidth, vpHeight; 00094 00100 int DisplayNumber; 00102 bool FullScreen; 00104 bool AllowResizing; 00109 int FrameBufferLocked; 00113 virtual void ChangeDepth (int d); 00117 virtual const char *GetName() const; 00118 00120 enum HWMouseMode 00121 { 00123 hwmcOff, 00125 hwmcOn, 00127 hwmcRGBAOnly 00128 }; 00129 HWMouseMode hwMouse; 00130 protected: 00132 int refreshRate; 00134 bool vsync; 00136 bool fitToWorkingArea; 00137 00138 csString name; 00139 csRef<iEventHandler> weakEventHandler; 00140 00144 virtual bool GetWorkspaceDimensions (int& width, int& height); 00149 virtual bool AddWindowFrameDimensions (int& width, int& height); 00150 public: 00152 csGraphics2D (iBase*); 00153 00155 virtual ~csGraphics2D (); 00156 00158 virtual bool Initialize (iObjectRegistry*); 00160 virtual bool HandleEvent (iEvent&); 00161 00163 virtual bool Open (); 00165 virtual void Close (); 00166 00168 virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax); 00170 virtual void GetClipRect (int &xmin, int &ymin, int &xmax, int &ymax); 00171 00176 virtual bool BeginDraw (); 00178 virtual void FinishDraw (); 00179 00181 virtual void Print (csRect const* /*area*/ = 0) { } 00182 00184 virtual void Clear (int color); 00186 virtual void ClearAll (int color); 00187 00188 virtual int FindRGB (int r, int g, int b, int a = 255) 00189 { 00190 if (r < 0) r = 0; else if (r > 255) r = 255; 00191 if (g < 0) g = 0; else if (g > 255) g = 255; 00192 if (b < 0) b = 0; else if (b > 255) b = 255; 00193 if (a < 0) a = 0; else if (a > 255) a = 255; 00194 return ((255 - a) << 24) | (r << 16) | (g << 8) | b; 00195 /* Alpha is "inverted" so '-1' can be decomposed to a 00196 transparent color. (But alpha not be inverted, '-1' 00197 would be "opaque white". However, -1 is the color 00198 index for "transparent text background". */ 00199 } 00200 virtual void GetRGB (int color, int& r, int& g, int& b) 00201 { 00202 r = (color >> 16) & 0xff; 00203 g = (color >> 8) & 0xff; 00204 b = color & 0xff; 00205 } 00206 virtual void GetRGB (int color, int& r, int& g, int& b, int& a) 00207 { 00208 a = 255 - (color >> 24); 00209 GetRGB (color, r, g, b); 00210 } 00211 00213 00214 virtual void Write (iFont *font , int x, int y, int fg, int bg, 00215 const char *text, uint flags = 0); 00216 virtual void Write (iFont *font , int x, int y, int fg, int bg, 00217 const wchar_t* text, uint flags = 0); 00219 00220 virtual bool SetGamma (float /*gamma*/) { return false; } 00221 virtual float GetGamma () const { return 1.0; } 00222 00223 private: 00225 bool CLIPt (float denom, float num, float& tE, float& tL); 00226 public: 00227 00232 virtual bool ClipLine (float &x1, float &y1, float &x2, float &y2, 00233 int xmin, int ymin, int xmax, int ymax); 00234 00236 virtual iFontServer *GetFontServer () 00237 { return FontServer; } 00238 00239 virtual int GetWidth () { return vpWidth; } 00240 virtual int GetHeight () { return vpHeight; } 00241 int GetColorDepth () { return Depth; } 00242 00247 virtual bool PerformExtension (char const* command, ...); 00248 00253 virtual bool PerformExtensionV (char const* command, va_list); 00254 00256 virtual void AllowResize (bool /*iAllow*/) { }; 00257 00259 virtual bool Resize (int w, int h); 00260 00262 virtual iNativeWindow* GetNativeWindow (); 00263 00265 virtual bool GetFullScreen () 00266 { return FullScreen; } 00267 00271 virtual void SetFullScreen (bool b); 00272 00274 virtual bool SetMousePosition (int x, int y); 00275 00285 virtual bool SetMouseCursor (csMouseCursorID iShape); 00286 00294 virtual bool SetMouseCursor (iImage *image, const csRGBcolor* keycolor = 0, 00295 int hotspot_x = 0, int hotspot_y = 0, 00296 csRGBcolor fg = csRGBcolor(255,255,255), 00297 csRGBcolor bg = csRGBcolor(0,0,0)); 00298 00299 void SetViewport (int left, int top, int width, int height); 00300 void GetViewport (int& left, int& top, int& width, int& height) 00301 { left = vpLeft; top = vpTop; width = vpWidth; height = vpHeight; } 00302 00303 void GetFramebufferDimensions (int& width, int& height) 00304 { width = fbWidth; height = fbHeight; } 00305 00306 const char* GetHWRenderer () 00307 { return 0; } 00308 const char* GetHWGLVersion () 00309 { return 0; } 00310 const char* GetHWVendor () 00311 { return 0; } 00312 00313 CS_EVENTHANDLER_NAMES("crystalspace.graphics2d.common") 00314 CS_EVENTHANDLER_NIL_CONSTRAINTS 00315 00316 protected: 00319 // Virtual Alert function so it can be overridden by subclasses 00320 // of csGraphics2D. 00321 virtual void AlertV (int type, const char* title, const char* okMsg, 00322 const char* msg, va_list args); 00323 virtual void Alert (int type, const char* title, const char* okMsg, 00324 const char* msg, ...); 00325 virtual void AlertV (int type, const wchar_t* title, const wchar_t* okMsg, 00326 const wchar_t* msg, va_list args); 00327 virtual void Alert (int type, const wchar_t* title, const wchar_t* okMsg, 00328 const wchar_t* msg, ...); 00333 // Virtual SetTitle function so it can be overridden by subclasses 00334 // of csGraphics2D. 00335 virtual void SetTitle (const char* title); 00336 virtual void SetTitle (const wchar_t* title) 00337 { SetTitle (csString (title)); } 00338 00344 virtual void SetIcon (iImage *image); 00345 00346 virtual bool IsWindowTransparencyAvailable() { return false; } 00347 virtual bool SetWindowTransparent (bool transparent) { return false; } 00348 virtual bool GetWindowTransparent () { return false; } 00349 00350 virtual bool SetWindowDecoration (WindowDecoration decoration, bool flag) 00351 { return false; } 00352 virtual bool GetWindowDecoration (WindowDecoration decoration); 00353 00354 virtual bool FitSizeToWorkingArea (int& desiredWidth, 00355 int& desiredHeight); 00360 virtual bool GetOptionDescription (int idx, csOptionDescription*); 00361 virtual bool SetOption (int id, csVariant* value); 00362 virtual bool GetOption (int id, csVariant* value); 00367 virtual bool DebugCommand (const char* cmd); 00368 virtual int GetSupportedTests () const { return 0; } 00369 virtual csPtr<iString> UnitTest () { return 0; } 00370 virtual csPtr<iString> StateTest () { return 0; } 00371 virtual csTicks Benchmark (int /*num_iterations*/) { return 0; } 00372 virtual csPtr<iString> Dump () { return 0; } 00373 virtual void Dump (iGraphics3D* /*g3d*/) { } 00375 }; 00376 00377 #include "csutil/deprecated_warn_on.h" 00378 00381 #endif // __CS_CSPLUGINCOMMON_CANVAS_GRAPH2D_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1