1 /**
2  * File name: RkPainterImpl.cpp
3  * Project: Redkite (A small GUI toolkit)
4  *
5  * Copyright (C) 2019 Iurie Nistor <http://geontime.com>
6  *
7  * This file is part of Redkite.
8  *
9  * Redkite is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #include "RkPainterImpl.h"
25 #include "RkCairoGraphicsBackend.h"
26 #include "RkLog.h"
27 
RkPainterImpl(RkPainter * interface,RkCanvas * canvas)28 RkPainter::RkPainterImpl::RkPainterImpl(RkPainter* interface, RkCanvas* canvas)
29         : inf_ptr{interface}
30 #ifdef RK_GRAPHICS_CAIRO_BACKEND
31         , backendGraphics{std::make_unique<RkCairoGraphicsBackend>(canvas)}
32 #else
33 #error No graphics backend defined
34 #endif
35 {
36         RK_UNUSED(inf_ptr);
37         backendGraphics->setPen(painterPen);
38         backendGraphics->setFont(painterFont);
39 }
40 
~RkPainterImpl()41 RkPainter::RkPainterImpl::~RkPainterImpl()
42 {
43 }
44 
drawText(const std::string & text,int x,int y)45 void RkPainter::RkPainterImpl::drawText(const std::string &text, int x, int y)
46 {
47         backendGraphics->drawText(text, x, y);
48 }
49 
drawImage(const std::string & file,int x,int y)50 void RkPainter::RkPainterImpl::drawImage(const std::string &file, int x, int y)
51 {
52         backendGraphics->drawImage(file, x, y);
53 }
54 
drawImage(const RkImage & image,int x,int y)55 void RkPainter::RkPainterImpl::drawImage(const RkImage &image, int x, int y)
56 {
57         backendGraphics->drawImage(image, x, y);
58 }
59 
drawEllipse(const RkPoint & p,int width,int height)60 void RkPainter::RkPainterImpl::drawEllipse(const RkPoint& p, int width, int height)
61 {
62         backendGraphics->drawEllipse(p, width, height);
63 }
64 
drawLine(const RkPoint & p1,const RkPoint & p2)65 void RkPainter::RkPainterImpl::drawLine(const RkPoint &p1, const RkPoint &p2)
66 {
67         backendGraphics->drawLine(p1, p2);
68 }
69 
drawRect(const RkRect & rect)70 void RkPainter::RkPainterImpl::drawRect(const RkRect &rect)
71 {
72         backendGraphics->drawRect(rect);
73 }
74 
drawPolyline(const std::vector<RkPoint> & points)75 void RkPainter::RkPainterImpl::drawPolyline(const std::vector<RkPoint> &points)
76 {
77         backendGraphics->drawPolyLine(points);
78 }
79 
fillRect(const RkRect & rect,const RkColor & color)80 void RkPainter::RkPainterImpl::fillRect(const RkRect &rect, const RkColor &color)
81 {
82         backendGraphics->fillRect(rect, color);
83 }
84 
pen() const85 const RkPen& RkPainter::RkPainterImpl::pen() const
86 {
87         return painterPen;
88 }
89 
setPen(const RkPen & pen)90 void RkPainter::RkPainterImpl::setPen(const RkPen &pen)
91 {
92         backendGraphics->setPen(pen);
93         painterPen = pen;
94 }
95 
font() const96 const RkFont& RkPainter::RkPainterImpl::font() const
97 {
98         return painterFont;
99 }
100 
setFont(const RkFont & font)101 void RkPainter::RkPainterImpl::setFont(const RkFont &font)
102 {
103         painterFont = font;
104         backendGraphics->setFont(painterFont);
105 }
106 
translate(const RkPoint & offset)107 void RkPainter::RkPainterImpl::translate(const RkPoint &offset)
108 {
109         backendGraphics->translate(offset);
110 }
111 
rotate(rk_real angle)112 void RkPainter::RkPainterImpl::rotate(rk_real angle)
113 {
114         backendGraphics->rotate(angle);
115 }
116 
getTextWidth(const std::string & text) const117 int RkPainter::RkPainterImpl::getTextWidth(const std::string &text) const
118 {
119         return backendGraphics->getTextWidth(text);
120 }
121 
applyAlpha(int alpha)122 void RkPainter::RkPainterImpl::applyAlpha(int alpha)
123 {
124         backendGraphics->applyAlpha(alpha);
125 }
126