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 "canvascommon.h" 00030 00031 #include "csutil/cfgacc.h" 00032 #include "csutil/scf.h" 00033 #include "csutil/scf_implementation.h" 00034 #include "csutil/weakref.h" 00035 00036 #include "iutil/comp.h" 00037 #include "iutil/dbghelp.h" 00038 #include "iutil/eventh.h" 00039 #include "iutil/plugin.h" 00040 #include "iutil/pluginconfig.h" 00041 #include "iutil/string.h" 00042 #include "ivideo/fontserv.h" 00043 #include "ivideo/graph2d.h" 00044 #include "ivideo/natwin.h" 00045 00050 struct iObjectRegistry; 00051 struct iPluginManager; 00052 00053 class csFontCache; 00054 00055 #include "csutil/deprecated_warn_off.h" 00056 00057 namespace CS 00058 { 00059 namespace PluginCommon 00060 { 00064 class CS_CRYSTALSPACE_EXPORT Graphics2DCommon : 00065 public virtual iGraphics2D, 00066 public virtual iComponent, 00067 public virtual iEventHandler 00068 { 00069 public: 00071 int ClipX1, ClipX2, ClipY1, ClipY2; 00072 00074 bool is_open; 00076 csEventID evCanvasResize; 00077 00079 iObjectRegistry* object_reg; 00081 csWeakRef<iPluginManager> plugin_mgr; 00082 00084 csWeakRef<iFontServer> FontServer; 00086 csFontCache* fontCache; 00087 00088 int vpLeft, vpTop, vpWidth, vpHeight; 00089 bool viewportIsFullScreen; 00090 00095 int FrameBufferLocked; 00096 protected: 00097 csRef<iEventHandler> weakEventHandler; 00098 00099 virtual iGraphicsCanvas* GetCanvas() = 0; 00100 00102 void HandleResize (iEvent& Event); 00103 public: 00105 Graphics2DCommon (); 00106 00108 virtual ~Graphics2DCommon (); 00109 00111 virtual bool Initialize (iObjectRegistry*); 00113 virtual bool HandleEvent (iEvent&); 00114 00116 virtual bool Open (); 00118 virtual void Close (); 00119 00120 virtual int GetWidth () { return vpWidth; } 00121 virtual int GetHeight () { return vpHeight; } 00122 00124 virtual void SetClipRect (int xmin, int ymin, int xmax, int ymax); 00126 virtual void GetClipRect (int &xmin, int &ymin, int &xmax, int &ymax); 00127 00132 virtual bool BeginDraw (); 00134 virtual void FinishDraw (); 00135 00137 virtual void Clear (int color); 00139 virtual void ClearAll (int color); 00140 00141 virtual int FindRGB (int r, int g, int b, int a = 255) 00142 { 00143 if (r < 0) r = 0; else if (r > 255) r = 255; 00144 if (g < 0) g = 0; else if (g > 255) g = 255; 00145 if (b < 0) b = 0; else if (b > 255) b = 255; 00146 if (a < 0) a = 0; else if (a > 255) a = 255; 00147 return ((255 - a) << 24) | (r << 16) | (g << 8) | b; 00148 /* Alpha is "inverted" so '-1' can be decomposed to a 00149 transparent color. (But alpha not be inverted, '-1' 00150 would be "opaque white". However, -1 is the color 00151 index for "transparent text background". */ 00152 } 00153 virtual void GetRGB (int color, int& r, int& g, int& b) 00154 { 00155 r = (color >> 16) & 0xff; 00156 g = (color >> 8) & 0xff; 00157 b = color & 0xff; 00158 } 00159 virtual void GetRGB (int color, int& r, int& g, int& b, int& a) 00160 { 00161 a = (255 - (color >> 24)) & 0xff; 00162 GetRGB (color, r, g, b); 00163 } 00164 00166 00167 virtual void Write (iFont *font , int x, int y, int fg, int bg, 00168 const char *text, uint flags = 0); 00169 virtual void Write (iFont *font , int x, int y, int fg, int bg, 00170 const wchar_t* text, uint flags = 0); 00172 00173 private: 00175 bool CLIPt (float denom, float num, float& tE, float& tL); 00176 public: 00177 00182 virtual bool ClipLine (float &x1, float &y1, float &x2, float &y2, 00183 int xmin, int ymin, int xmax, int ymax); 00184 00186 virtual iFontServer *GetFontServer () 00187 { return FontServer; } 00188 00193 virtual bool PerformExtensionV (char const* command, va_list); 00194 00195 bool Resize (int w, int h); 00196 00197 void SetViewport (int left, int top, int width, int height); 00198 void GetViewport (int& left, int& top, int& width, int& height) 00199 { left = vpLeft; top = vpTop; width = vpWidth; height = vpHeight; } 00200 00201 const char* GetHWRenderer () 00202 { return 0; } 00203 const char* GetHWGLVersion () 00204 { return 0; } 00205 const char* GetHWVendor () 00206 { return 0; } 00207 00208 CS_EVENTHANDLER_NAMES("crystalspace.graphics2d.common") 00209 CS_EVENTHANDLER_NIL_CONSTRAINTS 00210 }; 00211 } // namespace PluginCommon 00212 } // namespace CS 00213 00221 class CS_CRYSTALSPACE_EXPORT csGraphics2D : 00222 public scfImplementation7<csGraphics2D, 00223 scfFakeInterface<iGraphics2D>, 00224 scfFakeInterface<iComponent>, 00225 scfFakeInterface<iNativeWindow>, 00226 scfFakeInterface<iNativeWindowManager>, 00227 scfFakeInterface<iPluginConfig>, 00228 iDebugHelper, 00229 scfFakeInterface<iEventHandler> >, 00230 public virtual CS::PluginCommon::Graphics2DCommon, 00231 public virtual CS::PluginCommon::CanvasCommonBase 00232 { 00233 protected: 00234 iGraphicsCanvas* GetCanvas() { return this; } 00235 public: 00237 csConfigAccess config; 00238 00240 csGraphics2D (iBase*); 00241 00243 virtual ~csGraphics2D (); 00244 00246 virtual bool Initialize (iObjectRegistry*); 00247 protected: 00250 virtual bool DebugCommand (const char* cmd); 00251 virtual int GetSupportedTests () const { return 0; } 00252 virtual csPtr<iString> UnitTest () { return 0; } 00253 virtual csPtr<iString> StateTest () { return 0; } 00254 virtual csTicks Benchmark (int /*num_iterations*/) { return 0; } 00255 virtual csPtr<iString> Dump () { return 0; } 00256 virtual void Dump (iGraphics3D* /*g3d*/) { } 00258 }; 00259 00260 #include "csutil/deprecated_warn_on.h" 00261 00264 #endif // __CS_CSPLUGINCOMMON_CANVAS_GRAPH2D_H__
Generated for Crystal Space 2.1 by doxygen 1.6.1
