CrystalSpace

Public API Reference

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 <[email protected]>
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);
00253   virtual void WriteBaseline (iFont *font , int x, int y, int fg, int bg,
00254     const char *text);
00256 
00257   unsigned char* (*_GetPixelAt) (csGraphics2D *This, int x, int y);
00259   virtual unsigned char *GetPixelAt (int x, int y)
00260   { return _GetPixelAt (this, x, y); }
00261 
00269   virtual int GetPalEntryCount ()
00270   { return pfmt.PalEntries; }
00271 
00277   virtual int GetPixelBytes ()
00278   { return pfmt.PixelBytes; }
00279 
00283   virtual csPixelFormat const* GetPixelFormat ()
00284   { return &pfmt; }
00285 
00291   virtual csImageArea *SaveArea (int x, int y, int w, int h);
00293   virtual void RestoreArea (csImageArea *Area, bool Free = true);
00295   virtual void FreeArea (csImageArea *Area);
00296 
00297   virtual bool SetGamma (float /*gamma*/) { return false; }
00298   virtual float GetGamma () const { return 1.0; }
00299 
00300   virtual csPtr<iGraphics2D> CreateOffscreenCanvas (
00301         void* memory, int width, int height, int depth,
00302         iOffscreenCanvasCallback* ofscb);
00303 
00304 private:
00306   bool CLIPt (float denom, float num, float& tE, float& tL);
00307 public:
00308 
00313   virtual bool ClipLine (float &x1, float &y1, float &x2, float &y2,
00314     int xmin, int ymin, int xmax, int ymax);
00315 
00317   virtual iFontServer *GetFontServer ()
00318   { return FontServer; }
00319 
00320   virtual int GetWidth ()
00321   { return vpSet ? vpWidth : Width; }
00322   virtual int GetHeight ()
00323   { return vpSet ? vpHeight : Height; }
00324 
00326   virtual csRGBpixel *GetPalette ()
00327   { return pfmt.PalEntries ? Palette : 0; }
00328 
00330   virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB);
00332   virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB, uint8 &oA);
00333 
00338   virtual bool PerformExtension (char const* command, ...);
00339 
00344   virtual bool PerformExtensionV (char const* command, va_list);
00345 
00347   virtual csPtr<iImage> ScreenShot ();
00348 
00350   virtual void AllowResize (bool /*iAllow*/) { };
00351 
00353   virtual bool Resize (int w, int h);
00354 
00356   virtual iNativeWindow* GetNativeWindow ();
00357 
00359   virtual bool GetFullScreen ()
00360   { return FullScreen; }
00361 
00365   virtual void SetFullScreen (bool b);
00366 
00368   virtual bool SetMousePosition (int x, int y);
00369 
00379   virtual bool SetMouseCursor (csMouseCursorID iShape);
00380 
00388   virtual bool SetMouseCursor (iImage *image, const csRGBcolor* keycolor = 0, 
00389                                int hotspot_x = 0, int hotspot_y = 0,
00390                                csRGBcolor fg = csRGBcolor(255,255,255),
00391                                csRGBcolor bg = csRGBcolor(0,0,0));
00392 
00393   CS_EVENTHANDLER_NAMES("crystalspace.graphics2d.common")
00394   CS_EVENTHANDLER_NIL_CONSTRAINTS
00395 
00396 protected:
00403 
00404   static void DrawPixel8 (csGraphics2D *This, int x, int y, int color);
00406   static unsigned char *GetPixelAt8 (csGraphics2D *This, int x, int y);
00407 
00409   static void DrawPixel16 (csGraphics2D *This, int x, int y, int color);
00411   static unsigned char *GetPixelAt16 (csGraphics2D *This, int x, int y);
00412 
00414   static void DrawPixel32 (csGraphics2D *This, int x, int y, int color);
00416   static unsigned char *GetPixelAt32 (csGraphics2D *This, int x, int y);
00417 
00420   // Virtual Alert function so it can be overridden by subclasses
00421   // of csGraphics2D.
00422   virtual void AlertV (int type, const char* title, const char* okMsg,
00423     const char* msg, va_list args);
00424   virtual void Alert (int type, const char* title, const char* okMsg,
00425       const char* msg, ...);
00426   virtual void AlertV (int type, const wchar_t* title, const wchar_t* okMsg,
00427     const wchar_t* msg, va_list args);
00428   virtual void Alert (int type, const wchar_t* title, const wchar_t* okMsg,
00429       const wchar_t* msg, ...);
00434   // Virtual SetTitle function so it can be overridden by subclasses
00435   // of csGraphics2D.
00436   virtual void SetTitle (const char* title);
00437   virtual void SetTitle (const wchar_t* title)
00438   { SetTitle (csString (title)); }
00443   virtual bool GetOptionDescription (int idx, csOptionDescription*);
00444   virtual bool SetOption (int id, csVariant* value);
00445   virtual bool GetOption (int id, csVariant* value);
00450   virtual bool DebugCommand (const char* cmd);
00451   virtual int GetSupportedTests () const { return 0; }
00452   virtual csPtr<iString> UnitTest () { return 0; }
00453   virtual csPtr<iString> StateTest ()  { return 0; }
00454   virtual csTicks Benchmark (int /*num_iterations*/) { return 0; }
00455   virtual csPtr<iString> Dump ()  { return 0; }
00456   virtual void Dump (iGraphics3D* /*g3d*/)  { }
00458 };
00459 
00460 #include "csutil/win32/msvc_deprecated_warn_on.h"
00461 
00464 #endif // __CS_CSPLUGINCOMMON_CANVAS_GRAPH2D_H__

Generated for Crystal Space by doxygen 1.4.7