Simple Canvas
simplecanvas.h
1 
4 #ifndef SIMPLECANVAS_H
5 #define SIMPLECANVAS_H
6 
7 #include <string>
8 
9 class SimpleCanvas {
10  private:
11  // Helper method for Bresenham's line algorithm
12  void drawLineLow(int x0, int y0, int x1, int y1, uint8_t R, uint8_t G, uint8_t B);
13 
14  // Helper method for Bresenham's line algorithm
15  void drawLineHigh(int x0, int y0, int x1, int y1, uint8_t R, uint8_t G, uint8_t B);
16 
28  void drawChar(char c, int x0, int y0, int* dx, int* dy, std::string relpath);
29 
34  void createWrapper();
35 
36  void deallocate();
37 
38  uint8_t* dataInternal;
39 
40  public:
41  int width, height;
42  uint8_t*** data;
43 
49  SimpleCanvas(std::string fname);
50 
57  SimpleCanvas(int32_t width, int32_t height);
58 
62  ~SimpleCanvas();
63 
70  void read(std::string fname);
71 
80  void write(std::string fname);
81 
91  void setPixel(int x, int y, uint8_t R, uint8_t G, uint8_t B);
92 
104  void fillRect(int x0, int y0, int w, int h, uint8_t R, uint8_t G, uint8_t B);
105 
113  void clearRect(uint8_t R, uint8_t G, uint8_t B);
114 
127  void drawRect(int x0, int y0, int w, int h,
128  uint8_t R, uint8_t G, uint8_t B, uint8_t line_w);
129 
141  void drawLine(int x0, int y0, int x1, int y1, uint8_t R, uint8_t G, uint8_t B);
142 
143 
156  void drawLine(int x0, int y0, int x1, int y1, int thickness, uint8_t R, uint8_t G, uint8_t B);
157 
168  void fillCircle(int cx, int cy, double r, uint8_t R, uint8_t G, uint8_t B);
169 
177  void drawString(std::string s, int x0, int y0, std::string relpath);
178 };
179 
180 #endif
SimpleCanvas::drawString
void drawString(std::string s, int x0, int y0, std::string relpath)
Draw a character at a string at a position.
SimpleCanvas
A simple library for 2D drawing in C++, by Chris Tralie.
Definition: simplecanvas.h:9
SimpleCanvas::fillCircle
void fillCircle(int cx, int cy, double r, uint8_t R, uint8_t G, uint8_t B)
Fill in a solid disc of a particular color.
SimpleCanvas::fillRect
void fillRect(int x0, int y0, int w, int h, uint8_t R, uint8_t G, uint8_t B)
Fill a solid rectangle with a color.
SimpleCanvas::setPixel
void setPixel(int x, int y, uint8_t R, uint8_t G, uint8_t B)
Set the color of a particular pixel.
SimpleCanvas::read
void read(std::string fname)
Read in a ppm file. Use ffmpeg to convert the file to a temporary .ppm file if it has a non ppm exten...
SimpleCanvas::SimpleCanvas
SimpleCanvas(std::string fname)
Construct a new image object from a file.
SimpleCanvas::drawLine
void drawLine(int x0, int y0, int x1, int y1, uint8_t R, uint8_t G, uint8_t B)
Draw a thin line from one point to another.
SimpleCanvas::~SimpleCanvas
~SimpleCanvas()
Destroy the Simple Image object by de-allocating the pixel data.
SimpleCanvas::clearRect
void clearRect(uint8_t R, uint8_t G, uint8_t B)
Clear the entire canvas to be one color.
SimpleCanvas::drawRect
void drawRect(int x0, int y0, int w, int h, uint8_t R, uint8_t G, uint8_t B, uint8_t line_w)
Draw the outline of a rectangle with a particular color.
SimpleCanvas::write
void write(std::string fname)