Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GraphicContext.h

Go to the documentation of this file.
00001 /*
00002   Copyright (C) 2001-2004 Stephane Magnenat & Luc-Olivier de Charrière
00003   for any question or comment contact us at nct@ysagoon.com or nuage@ysagoon.com
00004 
00005   This program is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   This program 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
00013   GNU General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License
00016   along with this program; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018 */
00019 
00020 #ifndef __GRAPHICCONTEXT_H
00021 #define __GRAPHICCONTEXT_H
00022 
00023 #include "GAGSys.h"
00024 #include <map>
00025 #include <vector>
00026 
00031 namespace GAG
00032 {
00033     class Font;
00034     class Sprite;
00035     
00038     class DrawableSurface
00039     {
00040     public:
00042         enum Alpha
00043         {
00044             ALPHA_TRANSPARENT=0, 
00045             ALPHA_OPAQUE=255 
00046         };
00047     
00049         enum ResolutionFlags
00050         {
00051             DEFAULT=0, 
00052             DOUBLEBUF=1, 
00053             FULLSCREEN=2, 
00054             HWACCELERATED=4, 
00055             RESIZABLE=8 
00056         };
00057     
00058     public:
00060         virtual ~DrawableSurface(void) { }
00062         virtual bool setRes(int w, int h, int depth=32, Uint32 flags=DEFAULT)=0;
00064         virtual void setAlpha(bool usePerPixelAlpha=false, Uint8 alphaValue=ALPHA_OPAQUE)=0;
00066         virtual int getW(void)=0;
00068         virtual int getH(void)=0;
00070         virtual int getDepth(void)=0;
00072         virtual int getFlags(void)=0;
00074         virtual void setClipRect(int x, int y, int w, int h)=0;
00076         virtual void setClipRect(void)=0;
00078         virtual void loadImage(const char *name)=0;
00080         virtual void drawSprite(int x, int y, Sprite *sprite, int index=0)=0;
00082         virtual void drawPixel(int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a=ALPHA_OPAQUE)=0;
00084         virtual void drawRect(int x, int y, int w, int h, Uint8 r, Uint8 g, Uint8 b, Uint8 a=ALPHA_OPAQUE)=0;
00086         virtual void drawFilledRect(int x, int y, int w, int h, Uint8 r, Uint8 g, Uint8 b, Uint8 a=ALPHA_OPAQUE)=0;
00088         virtual void drawVertLine(int x, int y, int l, Uint8 r, Uint8 g, Uint8 b, Uint8 a=ALPHA_OPAQUE)=0;
00090         virtual void drawHorzLine(int x, int y, int l, Uint8 r, Uint8 g, Uint8 b, Uint8 a=ALPHA_OPAQUE)=0;
00092         virtual void drawLine(int x1, int y1, int x2, int y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a=ALPHA_OPAQUE)=0;
00094         virtual void drawCircle(int x, int y, int ray, Uint8 r, Uint8 g, Uint8 b, Uint8 a=ALPHA_OPAQUE)=0;
00096         virtual void drawString(int x, int y, const Font *font, int i)=0;
00098         virtual void drawString(int x, int y, const Font *font, const char *msg)=0;
00100         virtual void drawString(int x, int y, int w, const Font *font, const char *msg)=0;
00102         virtual void drawSurface(int x, int y, DrawableSurface *surface)=0;
00104         virtual void updateRects(SDL_Rect *rects, int size)=0;
00106         virtual void updateRect(int x, int y, int w, int h)=0;
00108         virtual void *getPixelPointer(void) = 0;
00109     };
00110     
00113     class GraphicContext:public virtual DrawableSurface
00114     {
00115     private:
00116         SDL_Rect **modes; 
00117         
00118     protected:
00119         int minW; 
00120         int minH; 
00121     
00122     public:
00124         GraphicContext();
00126         virtual ~GraphicContext(void);
00127     
00129         virtual bool setRes(int w, int h, int depth=32, Uint32 flags=DEFAULT)=0;
00131         virtual void setMinRes(int w=0, int h=0);
00133         virtual void beginVideoModeListing(void);
00135         virtual bool getNextVideoMode(int *w, int *h);
00137         virtual void setCaption(const char *title, const char *icon)=0;
00138     
00140         virtual Sprite *loadSprite(const char *filename);
00141     
00143         virtual Font *loadFont(const char *filename, unsigned size)=0;
00144     
00146         virtual DrawableSurface *createDrawableSurface(const char *name=NULL)=0;
00147     
00149         virtual void nextFrame(void)=0;
00151         virtual void printScreen(const char *filename)=0;
00152     
00154         static GraphicContext *createGraphicContext();
00155     };
00156     
00159     class Font
00160     {
00161     public:
00163         enum Shape
00164         {
00165             STYLE_NORMAL = 0x00, 
00166             STYLE_BOLD = 0x01, 
00167             STYLE_ITALIC = 0x02, 
00168             STYLE_UNDERLINE = 0x04, 
00169         };
00170     
00171     public:
00173         virtual ~Font() { }
00174     
00175         // width and height
00177         virtual int getStringWidth(const char *string) const=0;
00179         virtual int getStringWidth(const char *string, int len) const;
00181         virtual int getStringWidth(const int i) const;
00183         virtual int getStringHeight(const char *string) const=0;
00185         virtual int getStringHeight(const char *string, int len) const;
00187         virtual int getStringHeight(const int i) const;
00189         virtual bool printable(char c) const=0;
00190     
00191         // Style and color
00193         virtual void setColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a = DrawableSurface::ALPHA_OPAQUE) { }
00195         virtual void pushColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a = DrawableSurface::ALPHA_OPAQUE) { }
00197         virtual void popColor(void) { }
00199         virtual void getColor(Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const { }
00200     
00202         virtual void setStyle(unsigned style) { }
00204         virtual void pushStyle(unsigned style) { }
00206         virtual void popStyle(void) { }
00208         virtual unsigned getStyle(void) const { return 0; }
00209     };
00210     
00213     union Color32
00214     {
00215         Uint32 id; 
00216         struct
00217         {
00218             Uint8 r, g, b, a; 
00219         } channel; 
00220     
00222         Color32() { channel.r=channel.g=channel.b=0; channel.a=DrawableSurface::ALPHA_OPAQUE; }
00224         Color32(Uint8 r, Uint8 g, Uint8 b, Uint8 a=DrawableSurface::ALPHA_OPAQUE) { channel.r=r; channel.g=g; channel.b=b; channel.a=a; }
00226         Color32(Uint32 v) { id=v; }
00228         bool operator<(const Color32 &o) const { return id<o.id; }
00229     };
00230     
00233     class Sprite
00234     {
00235     protected:
00237         struct Surface
00238         {
00239             SDL_Surface *s; 
00240     
00242             Surface(SDL_Surface *source);
00244             ~Surface();
00245         };
00246     
00248         struct RotatedImage
00249         {
00250             SDL_Surface *orig; 
00251             typedef std::map<Color32, Surface *> RotationMap; 
00252             RotationMap rotationMap; 
00253     
00255             RotatedImage(SDL_Surface *s) { orig=s; }
00257             ~RotatedImage();
00258         };
00259     
00260         std::vector <Surface *> images; 
00261         std::vector <RotatedImage *> rotated; 
00262         Color32 actColor; 
00263     
00264         friend class GraphicContext;
00266         void loadFrame(SDL_RWops *frameStream, SDL_RWops *rotatedStream);
00268         Surface *surfaceFromSDL(SDL_Surface *s);
00269     
00270     public:
00272         Sprite() { }
00274         virtual ~Sprite();
00275     
00277         virtual void drawSDL(SDL_Surface *dest, const SDL_Rect *clip, int x, int y, int index);
00278         
00280         virtual void setBaseColor(Uint8 r, Uint8 g, Uint8 b) { actColor=Color32(r, g, b); }
00281     
00283         virtual int getW(int index);
00285         virtual int getH(int index);
00286     };
00287 }
00288 
00289 #endif

Generated on Mon Oct 24 17:38:25 2005 for Teem by  doxygen 1.4.2