2
* Copyright (C) 2011 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Mirco Müller <mirco.mueller@canonical.com
20
#include "Nux/CairoWrapper.h"
21
#include "Nux/VLayout.h"
22
#include "Nux/WindowThread.h"
23
#include "NuxGraphics/GraphicsEngine.h"
24
#include "Nux/TimerProc.h"
26
nux::CairoWrapper* g_canvas = NULL;
27
nux::TimerFunctor* g_timer = NULL;
28
nux::TimerHandle g_handler = NULL;
31
DrawRoundedRectangle (cairo_t* cr,
39
double radius = cornerRadius / aspect;
41
// top-left, right of the corner
42
cairo_move_to (cr, x + radius, y);
44
// top-right, left of the corner
45
cairo_line_to (cr, x + width - radius, y);
47
// top-right, below the corner
52
-90.0f * G_PI / 180.0f,
53
0.0f * G_PI / 180.0f);
55
// bottom-right, above the corner
56
cairo_line_to (cr, x + width, y + height - radius);
58
// bottom-right, left of the corner
64
90.0f * G_PI / 180.0f);
66
// bottom-left, right of the corner
67
cairo_line_to (cr, x + radius, y + height);
69
// bottom-left, above the corner
74
90.0f * G_PI / 180.0f,
75
180.0f * G_PI / 180.0f);
77
// top-left, right of the corner
82
180.0f * G_PI / 180.0f,
83
270.0f * G_PI / 180.0f);
87
callback (nux::Geometry const& geom, cairo_t* cr)
89
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
92
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
94
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
95
cairo_scale (cr, 1.0, 1.0);
96
cairo_set_source_rgba (cr, 1.0, 0.5, 0.25, 1.0);
97
DrawRoundedRectangle (cr, 1.0, 5.0, 5.0, 10.0,
98
(double) geom.width - 10.0,
99
(double) geom.height - 10.0);
104
terminate (void* data)
106
nux::WindowThread* thread = NUX_STATIC_CAST (nux::WindowThread*, data);
107
thread->TerminateThread ();
113
nux::Geometry geom = {0, 0, 200, 150};
114
g_canvas = new nux::CairoWrapper (geom, sigc::ptr_fun (callback));
115
std::string filename = "/tmp/cairo-wrapper-example.png";
116
g_canvas->DumpToFile (filename);
119
void ThreadWidgetInit (nux::NThread* thread, void* initData)
121
g_timer = new nux::TimerFunctor ();
122
g_timer->OnTimerExpired.connect (sigc::ptr_fun (&example));
123
g_handler = nux::GetTimer().AddTimerHandler (1000,
125
nux::GetWindowThread ());
131
nux::NuxInitialize (0);
132
nux::WindowThread* wt = NULL;
134
wt = nux::CreateGUIThread (TEXT ("Cairo-Wrapper Example"),