-
Notifications
You must be signed in to change notification settings - Fork 0
/
cairo_box.cpp
96 lines (78 loc) · 2.55 KB
/
cairo_box.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
Copyright (C) 2015 Alluris GmbH & Co. KG <[email protected]>
class cairo_box: Draw with cairo into a Fl_Box.
This file is part of TTT_certify.
TTT_certify is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TTT_certify is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. See ../COPYING
If not, see <http://www.gnu.org/licenses/>.
*/
#include <cairo-svg.h>
#include <cairo-ps.h>
#include <cairo-pdf.h>
#include <FL/fl_draw.H>
#include "cairo_box.h"
#include <cmath>
cairo_box::cairo_box (int x, int y, int w, int h, const char *l) : Fl_Box (x, y, w, h, l)
{
surface = NULL;
cr = NULL;
}
cairo_surface_t* cairo_box::set_surface(int wo, int ho)
{
#ifdef WIN32
#warning win32 mode
/* Get a Cairo surface for the current DC */
HDC dc = fl_gc; /* Exported by fltk */
return cairo_win32_surface_create(dc);
#elif defined (__APPLE__)
#warning Apple Quartz mode
/* Get a Cairo surface for the current CG context */
CGContext *ctx = fl_gc;
return cairo_quartz_surface_create_for_cg_context(ctx, wo, ho);
#else
/* Get a Cairo surface for the current display */
return cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, wo, ho);
#endif
}
void cairo_box::draw(void)
{
// using fltk functions, set up white background with thin black frame
//fl_color(FL_WHITE);
//fl_rectf(x(), y(), w(), h());
draw_box();
// Rahmen außenrum?
#if 0
fl_color(FL_BLACK);
fl_rect(x(), y(), w(), h());
#endif
//fl_push_clip(100,100,100,100);
//fl_color(FL_BLACK);
//fl_line(1,1,parent()->w(),parent()->h());
// set up cairo structures
Fl_Widget *p = this;
while (p->parent ())
p = p->parent ();
//printf ("p=%p\n", p);
surface = set_surface(p->w(), p->h());
cr = cairo_create(surface);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); // set drawing color to black
cairo_new_path(cr);
//printf ("x()=%i, y()=%i, w()=%i, h()=%i\n", x(), y(), w(), h());
cairo_draw ();
// release the cairo context
cairo_destroy(cr);
cairo_surface_destroy(surface);
}
void cairo_box::resize (int X, int Y, int W, int H)
{
Fl_Box::resize (X, Y, W, H);
parent ()->redraw ();
}