Otclient  14/8/2020
painter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef PAINTER_H
24 #define PAINTER_H
25 
30 
31 class Painter
32 {
33 public:
37  };
45  };
46  enum DrawMode {
47  Triangles = GL_TRIANGLES,
48  TriangleStrip = GL_TRIANGLE_STRIP
49  };
50 
51 
52  Painter();
53  virtual ~Painter() { }
54 
55  virtual void bind() { }
56  virtual void unbind() { }
57 
58  virtual void saveState() = 0;
59  virtual void saveAndResetState() = 0;
60  virtual void restoreSavedState() = 0;
61 
62  virtual void clear(const Color& color) = 0;
63 
64  virtual void drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode = Triangles) = 0;
65  virtual void drawFillCoords(CoordsBuffer& coordsBuffer) = 0;
66  virtual void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture) = 0;
67  virtual void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) = 0;
68  void drawTexturedRect(const Rect& dest, const TexturePtr& texture) { drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize())); }
69  virtual void drawUpsideDownTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) = 0;
70  virtual void drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) = 0;
71  virtual void drawFilledRect(const Rect& dest) = 0;
72  virtual void drawFilledTriangle(const Point& a, const Point& b, const Point& c) = 0;
73  virtual void drawBoundingRect(const Rect& dest, int innerLineWidth = 1) = 0;
74 
75  virtual void setTexture(Texture *texture) = 0;
76  virtual void setClipRect(const Rect& clipRect) = 0;
77  virtual void setColor(const Color& color) { m_color = color; }
78  virtual void setAlphaWriting(bool enable) = 0;
79  virtual void setBlendEquation(BlendEquation blendEquation) = 0;
80  virtual void setShaderProgram(PainterShaderProgram *shaderProgram) { m_shaderProgram = shaderProgram; }
81  void setShaderProgram(const PainterShaderProgramPtr& shaderProgram) { setShaderProgram(shaderProgram.get()); }
82 
83  virtual void scale(float x, float y) = 0;
84  void scale(float factor) { scale(factor, factor); }
85  virtual void translate(float x, float y) = 0;
86  void translate(const Point& p) { translate(p.x, p.y); }
87  virtual void rotate(float angle) = 0;
88  virtual void rotate(float x, float y, float angle) = 0;
89  void rotate(const Point& p, float angle) { rotate(p.x, p.y, angle); }
90 
91  virtual void setOpacity(float opacity) { m_opacity = opacity; }
92  virtual void setResolution(const Size& resolution) { m_resolution = resolution; }
93 
95  Color getColor() { return m_color; }
96  float getOpacity() { return m_opacity; }
97  Rect getClipRect() { return m_clipRect; }
99 
100  virtual void setCompositionMode(CompositionMode compositionMode) = 0;
101 
102  virtual void pushTransformMatrix() = 0;
103  virtual void popTransformMatrix() = 0;
104 
106  void resetOpacity() { setOpacity(1.0f); }
110 
111  virtual bool hasShaders() = 0;
112 
113 protected:
118  float m_opacity;
120 };
121 
122 extern Painter *g_painter;
123 
124 #endif
Painter::setAlphaWriting
virtual void setAlphaWriting(bool enable)=0
Painter::setColor
virtual void setColor(const Color &color)
Definition: painter.h:77
Painter::Painter
Painter()
Definition: painter.cpp:30
Painter::restoreSavedState
virtual void restoreSavedState()=0
Painter::getColor
Color getColor()
Definition: painter.h:95
Painter::BlendEquation_Add
@ BlendEquation_Add
Definition: painter.h:35
Color
Definition: color.h:32
Painter::unbind
virtual void unbind()
Definition: painter.h:56
Painter::CompositionMode_Normal
@ CompositionMode_Normal
Definition: painter.h:39
Painter::bind
virtual void bind()
Definition: painter.h:55
Painter::setTexture
virtual void setTexture(Texture *texture)=0
Painter::rotate
virtual void rotate(float angle)=0
Painter::CompositionMode_Add
@ CompositionMode_Add
Definition: painter.h:41
TPoint::y
T y
Definition: point.h:83
paintershaderprogram.h
Painter::TriangleStrip
@ TriangleStrip
Definition: painter.h:48
Painter::saveAndResetState
virtual void saveAndResetState()=0
Painter::setCompositionMode
virtual void setCompositionMode(CompositionMode compositionMode)=0
TRect< int >
Texture::getSize
const Size & getSize()
Definition: texture.h:50
Painter::m_opacity
float m_opacity
Definition: painter.h:118
Painter::clear
virtual void clear(const Color &color)=0
Painter::getCompositionMode
CompositionMode getCompositionMode()
Definition: painter.h:98
Texture
Definition: texture.h:28
coordsbuffer.h
Painter::DrawMode
DrawMode
Definition: painter.h:46
g_painter
Painter * g_painter
Definition: painter.cpp:28
Painter::m_resolution
Size m_resolution
Definition: painter.h:117
Painter::setShaderProgram
void setShaderProgram(const PainterShaderProgramPtr &shaderProgram)
Definition: painter.h:81
Painter::CompositionMode_DestBlending
@ CompositionMode_DestBlending
Definition: painter.h:43
Point
TPoint< int > Point
Definition: point.h:86
Painter::popTransformMatrix
virtual void popTransformMatrix()=0
Painter::getResolution
Size getResolution()
Definition: painter.h:94
Painter::rotate
void rotate(const Point &p, float angle)
Definition: painter.h:89
Painter::setShaderProgram
virtual void setShaderProgram(PainterShaderProgram *shaderProgram)
Definition: painter.h:80
Painter::scale
void scale(float factor)
Definition: painter.h:84
Painter::CompositionMode_Light
@ CompositionMode_Light
Definition: painter.h:44
Painter::~Painter
virtual ~Painter()
Definition: painter.h:53
Painter::hasShaders
virtual bool hasShaders()=0
Painter::CompositionMode
CompositionMode
Definition: painter.h:38
Painter::m_color
Color m_color
Definition: painter.h:116
Painter::CompositionMode_Replace
@ CompositionMode_Replace
Definition: painter.h:42
Color::white
static const Color white
Definition: color.h:101
Painter::Triangles
@ Triangles
Definition: painter.h:47
Painter::translate
void translate(const Point &p)
Definition: painter.h:86
Painter::resetOpacity
void resetOpacity()
Definition: painter.h:106
Painter
Definition: painter.h:31
Painter::drawBoundingRect
virtual void drawBoundingRect(const Rect &dest, int innerLineWidth=1)=0
TPoint::x
T x
Definition: point.h:83
Painter::drawRepeatedTexturedRect
virtual void drawRepeatedTexturedRect(const Rect &dest, const TexturePtr &texture, const Rect &src)=0
Painter::BlendEquation
BlendEquation
Definition: painter.h:34
PainterShaderProgram
Definition: paintershaderprogram.h:30
Painter::translate
virtual void translate(float x, float y)=0
Painter::resetShaderProgram
void resetShaderProgram()
Definition: painter.h:109
Painter::pushTransformMatrix
virtual void pushTransformMatrix()=0
Rect
TRect< int > Rect
Definition: rect.h:319
Painter::setClipRect
virtual void setClipRect(const Rect &clipRect)=0
Painter::scale
virtual void scale(float x, float y)=0
Painter::resetColor
void resetColor()
Definition: painter.h:108
Painter::drawFillCoords
virtual void drawFillCoords(CoordsBuffer &coordsBuffer)=0
Painter::getOpacity
float getOpacity()
Definition: painter.h:96
declarations.h
texture.h
stdext::shared_object_ptr< Texture >
CoordsBuffer
Definition: coordsbuffer.h:29
Painter::getClipRect
Rect getClipRect()
Definition: painter.h:97
Painter::CompositionMode_Multiply
@ CompositionMode_Multiply
Definition: painter.h:40
Painter::BlendEquation_Max
@ BlendEquation_Max
Definition: painter.h:36
Painter::drawFilledTriangle
virtual void drawFilledTriangle(const Point &a, const Point &b, const Point &c)=0
Painter::setBlendEquation
virtual void setBlendEquation(BlendEquation blendEquation)=0
TPoint< int >
Painter::saveState
virtual void saveState()=0
Painter::drawUpsideDownTexturedRect
virtual void drawUpsideDownTexturedRect(const Rect &dest, const TexturePtr &texture, const Rect &src)=0
Painter::setResolution
virtual void setResolution(const Size &resolution)
Definition: painter.h:92
Painter::drawFilledRect
virtual void drawFilledRect(const Rect &dest)=0
Painter::resetClipRect
void resetClipRect()
Definition: painter.h:105
Painter::drawCoords
virtual void drawCoords(CoordsBuffer &coordsBuffer, DrawMode drawMode=Triangles)=0
TSize< int >
Painter::m_clipRect
Rect m_clipRect
Definition: painter.h:119
Painter::drawTextureCoords
virtual void drawTextureCoords(CoordsBuffer &coordsBuffer, const TexturePtr &texture)=0
Painter::m_compositionMode
CompositionMode m_compositionMode
Definition: painter.h:115
Painter::drawTexturedRect
void drawTexturedRect(const Rect &dest, const TexturePtr &texture)
Definition: painter.h:68
Painter::m_shaderProgram
PainterShaderProgram * m_shaderProgram
Definition: painter.h:114
stdext::shared_object_ptr::get
T * get() const
Definition: shared_object.h:82
Painter::setOpacity
virtual void setOpacity(float opacity)
Definition: painter.h:91
Painter::drawTexturedRect
virtual void drawTexturedRect(const Rect &dest, const TexturePtr &texture, const Rect &src)=0
Painter::resetCompositionMode
void resetCompositionMode()
Definition: painter.h:107