1 /*
2  * This file is part of NumptyPhysics
3  * Copyright (C) 2008 Tim Edmonds
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 3 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  */
16 
17 #ifndef CANVAS_H
18 #define CANVAS_H
19 
20 #include "Common.h"
21 class Path;
22 
23 class Canvas
24 {
25 public:
26   Canvas( int w, int h );
27   virtual ~Canvas();
28   int width() const;
29   int height() const;
30   int  makeColour( int c ) const;
31   int  makeColour( int r, int g, int b ) const;
32   void resetClip();
33   void setClip( int x, int y, int w, int h );
34   void setBackground( int c );
35   void setBackground( Canvas* bg );
36   void clear();
37   void clear( const Rect& r );
38   void fade( const Rect& r );
39   Canvas* scale( int factor ) const;
40   void scale( int w, int h );
41   void drawImage( Canvas *canvas, int x, int y );
42   void drawPixel( int x, int y, int c );
43   int  readPixel( int x, int y ) const;
44   void drawLine( int x1, int y1, int x2, int y2, int c );
45   void drawPath( const Path& path, int color, bool thick=false );
46   void drawRect( int x, int y, int w, int h, int c, bool fill=true );
47   void drawRect( const Rect& r, int c, bool fill=true );
48   int writeBMP( const char* filename ) const;
49 protected:
50   typedef void* State;
51   Canvas( State state=NULL );
52   State   m_state;
53   int     m_bgColour;
54   Canvas* m_bgImage;
55   Rect    m_clip;
56 };
57 
58 class Window : public Canvas
59 {
60  public:
61   Window( int w, int h, const char* title=NULL, const char* winclass=NULL );
62   void update( const Rect& r );
63   void raise();
64   void setSubName( const char *sub );
65 };
66 
67 
68 class Image : public Canvas
69 {
70  public:
71   Image( const char* file, bool alpha=false );
72 };
73 
74 
75 #endif //CANVAS_H
76