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