VNMediaClientNET
Graphics.h
1 /*
2  * Graphics.h
3  *
4  */
5 #pragma once
6 #ifndef GRAPHICS_H_
7 #define GRAPHICS_H_
8 
9 #include <vector>
10 #include <string>
11 #include <stddef.h>
12 #include "Point.h"
13 #include "Rectangle.h"
14 
15 struct Color {
16  union
17  {
18  unsigned int rgba;
19  struct
20  {
21  unsigned char r;
22  unsigned char g;
23  unsigned char b;
24  unsigned char a;
25  };
26  unsigned char v[4];
27  };
28  Color( unsigned int rgba = 0 )
29  : rgba( rgba )
30  { }
31  Color( unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255 )
32  : r(red), g(green), b(blue), a(alpha)
33  { }
34  void swapRB()
35  {
36  unsigned char t = r;
37  r = b;
38  b = t;
39  }
40 };
41 
42 
43 class Image
44 {
45 public:
46  virtual ~Image() { }
47  virtual int getWidth() const = 0;
48  virtual int getHeight() const = 0;
49 
50  virtual bool setColorCorrection( int Brightness, int Contrast )
51  {
52  brightness_ = Brightness;
53  contrast_ = Contrast;
54  return true;
55  }
56 
57  //static Image* createImageFromPNGData( const unsigned char* png );
58  static Image* createImageFromRGBA( size_t w, size_t h, const unsigned char* data );
59 
60  int brightness() const { return brightness_; }
61  int contrast() const { return contrast_; }
62 private:
63  int brightness_;
64  int contrast_;
65 };
66 
67 class Graphics
68 {
69 public:
70  enum FONT_STYLE { Regular = 0, Bold = 1, Italic = 2, BoldItalic = 3 };
71  enum HORZ_ALIGN { Left, Center, Right };
72  enum VERT_ALIGN { Top, Middle, BaseLine, Bottom };
74  {
75  Transform2Matrix( float a, float b, float c, float d, float x, float y )
76  : a(a), b(b), c(c), d(d), x(x), y(y)
77  {}
78 
79  union {
80  struct {
81  float a, b; // a b 0
82  float c, d; // c d 0
83  float x, y; // x y 1
84  };
85  float m[6];
86  };
87  };
88 
89 public:
90  virtual ~Graphics() { }
91  virtual bool drawImage(const Image* img, int x, int y, int width, int height) = 0;
92  virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
93  virtual void setColor(Color c) = 0;
94  virtual void drawRect(int x, int y, int width, int height) = 0;
95  virtual void fillRect(int x, int y, int width, int height) = 0;
96  virtual void drawEllipse(int x, int y, int width, int height) = 0;
97  virtual void fillEllipse(int x, int y, int width, int height) = 0;
98  virtual void drawPolyline( const std::vector<int>& xCoords, const std::vector<int>& yCoords, int count ) = 0;
99  virtual void drawPolyline( const std::vector<Point2>& points ) = 0;
100  virtual void fillPolygon( const std::vector<int>& xCoords, const std::vector<int>& yCoords, int count ) = 0;
101  virtual void fillPolygon( const std::vector<Point2>& points ) = 0;
102 
103  virtual float getStrokeWidth() const = 0;
104  virtual void setStrokeWidth( float strokeWidth ) = 0;
105 
106  virtual void setFont( const char* fontName, float fontSize, FONT_STYLE fontStyle ) = 0;
107  virtual float fontAscent() const = 0;
108  virtual float fontDescent() const = 0;
109  virtual Point2 measureText( const std::string& text ) = 0;
110  virtual Rectangle2 drawString( const std::string& text, float x, float y, HORZ_ALIGN horzAlign = Left, VERT_ALIGN vertAlign = BaseLine ) = 0;
111 
112  virtual void pushState() = 0;
113  virtual void popState() = 0;
114  virtual void setTransform2Identity() = 0;
115  virtual void setTransform2( Transform2Matrix matrix ) = 0;
116  virtual Transform2Matrix getTransform2() = 0;
117  virtual void multiplyTransform2( Transform2Matrix matrix ) = 0;
118  virtual void scaleTransform2( float sx, float sy ) = 0;
119  virtual void rotateTransform2( float angle ) = 0; // angle in degrees
120  virtual void translateTransform2( float dx, float dy ) = 0;
121 };
122 
124 {
125 public:
126  enum SHAPE { Arrow, Finger, Move, Moving };
127  virtual void setShape( SHAPE Shape ) = 0;
128  virtual ~CursorCtrl() {}
129 };
130 
131 
132 #endif
Rectangle2
Definition: Rectangle.h:18
CursorCtrl
Definition: Graphics.h:124
Graphics
Definition: Graphics.h:68
Image
Definition: Graphics.h:44
Point2
Definition: Point.h:16
Graphics::Transform2Matrix
Definition: Graphics.h:74
Color
Definition: Graphics.h:15