File: Canvas.h

package info (click to toggle)
numptyphysics 0.2+svn157-0.3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 2,596 kB
  • ctags: 2,896
  • sloc: cpp: 18,280; sh: 810; makefile: 205
file content (77 lines) | stat: -rw-r--r-- 2,081 bytes parent folder | download | duplicates (3)
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
/*
 * 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"
class Path;

class Canvas
{
  typedef void* State;
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( State state=NULL );
  State   m_state;
  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();
  void setSubName( const char *sub );
 protected:
  std::string m_title;
};


class Image : public Canvas
{
 public:
  Image( const char* file, bool alpha=false );
};


#endif //CANVAS_H