2011-12-07 01:31:55 +01:00
|
|
|
/*
|
2017-01-13 11:47:07 +01:00
|
|
|
* Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
|
2011-12-07 01:31:55 +01:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PAINTER_H
|
|
|
|
#define PAINTER_H
|
|
|
|
|
2013-02-22 07:31:13 +01:00
|
|
|
#include <framework/graphics/declarations.h>
|
|
|
|
#include <framework/graphics/coordsbuffer.h>
|
|
|
|
#include <framework/graphics/paintershaderprogram.h>
|
|
|
|
#include <framework/graphics/texture.h>
|
2011-12-07 01:31:55 +01:00
|
|
|
|
|
|
|
class Painter
|
|
|
|
{
|
|
|
|
public:
|
2013-02-22 06:55:35 +01:00
|
|
|
enum BlendEquation {
|
|
|
|
BlendEquation_Add,
|
|
|
|
BlendEquation_Max
|
|
|
|
};
|
2011-12-07 01:31:55 +01:00
|
|
|
enum CompositionMode {
|
2011-12-19 04:24:35 +01:00
|
|
|
CompositionMode_Normal,
|
|
|
|
CompositionMode_Multiply,
|
2012-01-19 17:23:24 +01:00
|
|
|
CompositionMode_Add,
|
|
|
|
CompositionMode_Replace,
|
2012-11-29 02:47:26 +01:00
|
|
|
CompositionMode_DestBlending,
|
2013-02-20 23:12:52 +01:00
|
|
|
CompositionMode_Light
|
2011-12-07 01:31:55 +01:00
|
|
|
};
|
2012-04-19 01:03:43 +02:00
|
|
|
enum DrawMode {
|
|
|
|
Triangles = GL_TRIANGLES,
|
|
|
|
TriangleStrip = GL_TRIANGLE_STRIP
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Painter();
|
|
|
|
virtual ~Painter() { }
|
|
|
|
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void bind() { }
|
2012-04-19 01:03:43 +02:00
|
|
|
virtual void unbind() { }
|
2011-12-07 01:31:55 +01:00
|
|
|
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void saveState() = 0;
|
|
|
|
virtual void saveAndResetState() = 0;
|
|
|
|
virtual void restoreSavedState() = 0;
|
2012-06-06 16:10:35 +02:00
|
|
|
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void clear(const Color& color) = 0;
|
2011-12-07 01:31:55 +01:00
|
|
|
|
2012-04-19 01:03:43 +02:00
|
|
|
virtual void drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode = Triangles) = 0;
|
2015-06-03 14:56:43 +02:00
|
|
|
virtual void drawFillCoords(CoordsBuffer& coordsBuffer) = 0;
|
2012-04-19 01:03:43 +02:00
|
|
|
virtual void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture) = 0;
|
|
|
|
virtual void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) = 0;
|
2012-03-20 16:17:10 +01:00
|
|
|
void drawTexturedRect(const Rect& dest, const TexturePtr& texture) { drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize())); }
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void drawUpsideDownTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) = 0;
|
2012-04-19 01:03:43 +02:00
|
|
|
virtual void drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) = 0;
|
|
|
|
virtual void drawFilledRect(const Rect& dest) = 0;
|
2012-06-10 08:09:37 +02:00
|
|
|
virtual void drawFilledTriangle(const Point& a, const Point& b, const Point& c) = 0;
|
2012-04-19 01:03:43 +02:00
|
|
|
virtual void drawBoundingRect(const Rect& dest, int innerLineWidth = 1) = 0;
|
2011-12-07 01:31:55 +01:00
|
|
|
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void setTexture(Texture *texture) = 0;
|
|
|
|
virtual void setClipRect(const Rect& clipRect) = 0;
|
2012-04-19 01:03:43 +02:00
|
|
|
virtual void setColor(const Color& color) { m_color = color; }
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void setAlphaWriting(bool enable) = 0;
|
|
|
|
virtual void setBlendEquation(BlendEquation blendEquation) = 0;
|
2012-04-19 01:03:43 +02:00
|
|
|
virtual void setShaderProgram(PainterShaderProgram *shaderProgram) { m_shaderProgram = shaderProgram; }
|
|
|
|
void setShaderProgram(const PainterShaderProgramPtr& shaderProgram) { setShaderProgram(shaderProgram.get()); }
|
2011-12-07 01:31:55 +01:00
|
|
|
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void scale(float x, float y) = 0;
|
2013-01-19 16:44:27 +01:00
|
|
|
void scale(float factor) { scale(factor, factor); }
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void translate(float x, float y) = 0;
|
2013-01-19 16:44:27 +01:00
|
|
|
void translate(const Point& p) { translate(p.x, p.y); }
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void rotate(float angle) = 0;
|
|
|
|
virtual void rotate(float x, float y, float angle) = 0;
|
2013-01-19 16:44:27 +01:00
|
|
|
void rotate(const Point& p, float angle) { rotate(p.x, p.y, angle); }
|
2013-01-19 03:18:29 +01:00
|
|
|
|
2013-02-22 06:55:35 +01:00
|
|
|
virtual void setOpacity(float opacity) { m_opacity = opacity; }
|
|
|
|
virtual void setResolution(const Size& resolution) { m_resolution = resolution; }
|
2013-01-19 17:44:07 +01:00
|
|
|
|
2013-02-22 06:55:35 +01:00
|
|
|
Size getResolution() { return m_resolution; }
|
2012-04-19 01:03:43 +02:00
|
|
|
Color getColor() { return m_color; }
|
|
|
|
float getOpacity() { return m_opacity; }
|
2012-04-05 00:46:49 +02:00
|
|
|
Rect getClipRect() { return m_clipRect; }
|
2013-02-22 06:55:35 +01:00
|
|
|
CompositionMode getCompositionMode() { return m_compositionMode; }
|
|
|
|
|
|
|
|
virtual void setCompositionMode(CompositionMode compositionMode) = 0;
|
|
|
|
|
|
|
|
virtual void pushTransformMatrix() = 0;
|
|
|
|
virtual void popTransformMatrix() = 0;
|
2012-04-05 00:46:49 +02:00
|
|
|
|
2012-04-19 01:03:43 +02:00
|
|
|
void resetClipRect() { setClipRect(Rect()); }
|
2013-02-22 06:55:35 +01:00
|
|
|
void resetOpacity() { setOpacity(1.0f); }
|
2012-01-17 06:36:25 +01:00
|
|
|
void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); }
|
2013-02-22 06:55:35 +01:00
|
|
|
void resetColor() { setColor(Color::white); }
|
2012-04-19 01:03:43 +02:00
|
|
|
void resetShaderProgram() { setShaderProgram(nullptr); }
|
2012-01-10 23:13:40 +01:00
|
|
|
|
2012-06-14 20:26:55 +02:00
|
|
|
virtual bool hasShaders() = 0;
|
|
|
|
|
2012-04-19 01:03:43 +02:00
|
|
|
protected:
|
2013-02-22 06:55:35 +01:00
|
|
|
PainterShaderProgram *m_shaderProgram;
|
|
|
|
CompositionMode m_compositionMode;
|
2012-01-30 07:27:21 +01:00
|
|
|
Color m_color;
|
2013-02-22 06:55:35 +01:00
|
|
|
Size m_resolution;
|
2012-01-30 07:27:21 +01:00
|
|
|
float m_opacity;
|
2012-04-05 00:46:49 +02:00
|
|
|
Rect m_clipRect;
|
2011-12-07 01:31:55 +01:00
|
|
|
};
|
|
|
|
|
2012-04-19 01:03:43 +02:00
|
|
|
extern Painter *g_painter;
|
2011-12-07 01:31:55 +01:00
|
|
|
|
|
|
|
#endif
|