CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

graph2d.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2001 by Jorrit Tyberghein
00003     Copyright (C) 1998-2000 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_IVIDEO_GRAPH2D_H__
00021 #define __CS_IVIDEO_GRAPH2D_H__
00022 
00031 #include <stdarg.h>
00032 #include "csutil/scf.h"
00033 #include "csgfx/rgbpixel.h"
00034 #include "ivideo/texture.h"
00035 #include "iengine/texture.h"
00036 #include "ivideo/cursor.h"
00037 
00038 class csRect;
00039 struct iImage;
00040 struct iFontServer;
00041 struct iFont;
00042 struct iNativeWindow;
00043 struct iGraphics2D;
00044 
00046 enum
00047 {
00052   CS_WRITE_BASELINE    = (1 << 0),
00056   CS_WRITE_NOANTIALIAS = (1 << 1)
00057 };
00058 
00060 struct csPixelCoord
00061 {
00063   int x;
00065   int y;
00066 };
00067 
00071 struct csPixelFormat
00072 {
00078   uint32 RedMask, GreenMask, BlueMask, AlphaMask;
00083   int RedShift, GreenShift, BlueShift, AlphaShift;
00085   int RedBits, GreenBits, BlueBits, AlphaBits;
00086 
00093   int PalEntries;
00094 
00104   int PixelBytes;
00105 
00110   void complete ()
00111   {
00112 #define COMPUTE(comp)                                                   \
00113     {                                                                   \
00114       unsigned long i, tmp = comp##Mask;                                \
00115       for (i = 0; tmp && !(tmp & 1); tmp >>= 1, i++) {}                 \
00116       comp##Shift = i;                                                  \
00117       for (i = 0; tmp & 1; tmp >>= 1, i++) {}                           \
00118       comp##Bits = i;                                                   \
00119     }
00120     COMPUTE (Red);
00121     COMPUTE (Green);
00122     COMPUTE (Blue);
00123     COMPUTE (Alpha);
00124 #undef COMPUTE
00125   }
00126 };
00127 
00129 struct csImageArea
00130 {
00131   int x, y, w, h;
00132   char *data;
00133 
00134   inline csImageArea (int sx, int sy, int sw, int sh)
00135   { x = sx; y = sy; w = sw; h = sh; data = 0; }
00136 };
00137 
00138 SCF_VERSION (iOffscreenCanvasCallback, 1, 0, 0);
00139 
00145 struct iOffscreenCanvasCallback : public iBase
00146 {
00148   virtual void FinishDraw (iGraphics2D* canvas) = 0;
00150   virtual void SetRGB (iGraphics2D* canvas, int idx, int r, int g, int b) = 0;
00151 };
00152 
00153 SCF_VERSION (iGraphics2D, 2, 6, 0);
00154 
00182 struct iGraphics2D : public iBase
00183 {
00185   virtual bool Open () = 0;
00186 
00188   virtual void Close () = 0;
00189 
00191   virtual int GetWidth () = 0;
00192 
00194   virtual int GetHeight () = 0;
00195 
00197   virtual int GetPage () = 0;
00198 
00200   virtual bool DoubleBuffer (bool Enable) = 0;
00201 
00203   virtual bool GetDoubleBufferState () = 0;
00204 
00206   virtual csPixelFormat const* GetPixelFormat () = 0;
00207 
00213   virtual int GetPixelBytes () = 0;
00214 
00222   virtual int GetPalEntryCount () = 0;
00223 
00225   virtual csRGBpixel *GetPalette () = 0;
00226 
00231   virtual void SetRGB (int i, int r, int g, int b) = 0;
00240   virtual int FindRGB (int r, int g, int b, int a = 255) = 0;
00241 
00245   virtual void GetRGB (int color, int& r, int& g, int& b) = 0;
00249   virtual void GetRGB (int color, int& r, int& g, int& b, int& a) = 0;
00250   
00256   virtual void SetClipRect (int nMinX, int nMinY, int nMaxX, int nMaxY) = 0;
00257 
00259   virtual void GetClipRect(int& nMinX, int& nMinY, int& nMaxX, int& nMaxY) = 0;
00260 
00265   virtual bool BeginDraw () = 0;
00266 
00268   virtual void FinishDraw () = 0;
00269 
00275   virtual void Print (csRect const* pArea) = 0;
00276 
00278   virtual void Clear (int color) = 0;
00279 
00281   virtual void ClearAll (int color) = 0;
00282 
00284   virtual void DrawLine(float x1, float y1, float x2, float y2, int color) = 0;
00285 
00287   virtual void DrawBox (int x, int y, int w, int h, int color) = 0;
00288 
00293   virtual bool ClipLine (float& x1, float& y1, float& x2, float& y2,
00294     int xmin, int ymin, int xmax, int ymax) = 0;
00295 
00297   virtual void DrawPixel (int x, int y, int color) = 0;
00298 
00300   virtual void DrawPixels(csPixelCoord const* pixels, int num_pixels,
00301      int color) = 0;
00302 
00304   virtual void Blit (int x, int y, int width, int height,
00305     unsigned char const* data) = 0;
00306 
00308   virtual unsigned char *GetPixelAt (int x, int y) = 0;
00309 
00311   virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB) = 0;
00313   virtual void GetPixel (int x, int y, uint8 &oR, uint8 &oG, uint8 &oB, uint8 &oA) = 0;
00314 
00320   virtual csImageArea *SaveArea (int x, int y, int w, int h) = 0;
00321 
00323   virtual void RestoreArea (csImageArea *Area, bool Free) = 0;
00324 
00326   virtual void FreeArea (csImageArea *Area) = 0;
00327 
00336   virtual void Write (iFont *font, int x, int y, int fg, int bg,
00337     const char *str, uint flags = 0) = 0;
00338 
00346   CS_DEPRECATED_METHOD virtual void WriteBaseline (iFont *font, 
00347     int x, int y, int fg, int bg, const char *str) = 0;
00348 
00350   virtual void AllowResize (bool iAllow) = 0;
00351 
00353   virtual bool Resize (int w, int h) = 0;
00354 
00356   virtual iFontServer *GetFontServer () = 0;
00357 
00365   virtual bool PerformExtension (char const* command, ...) = 0;
00366 
00372   virtual bool PerformExtensionV (char const* command, va_list) = 0;
00373 
00375   virtual csPtr<iImage> ScreenShot () = 0;
00376 
00381   virtual iNativeWindow* GetNativeWindow () = 0;
00382 
00384   virtual bool GetFullScreen () = 0;
00385 
00389   virtual void SetFullScreen (bool b) = 0;
00390 
00392   virtual bool SetMousePosition (int x, int y) = 0;
00393 
00402   virtual bool SetMouseCursor (csMouseCursorID iShape) = 0;
00403 
00411   virtual bool SetMouseCursor (iImage *image, const csRGBcolor* keycolor = 0, 
00412                                int hotspot_x = 0, int hotspot_y = 0,
00413                                csRGBcolor fg = csRGBcolor(255,255,255),
00414                                csRGBcolor bg = csRGBcolor(0,0,0)) = 0;
00415 
00421   virtual bool SetGamma (float gamma) = 0;
00422 
00426   virtual float GetGamma () const = 0;
00427 
00436   virtual csPtr<iGraphics2D> CreateOffscreenCanvas (
00437         void* memory, int width, int height, int depth,
00438         iOffscreenCanvasCallback* ofscb) = 0;
00439 };
00440 
00443 #endif // __CS_IVIDEO_GRAPH2D_H__
00444 

Generated for Crystal Space by doxygen 1.3.9.1