Mercurial > hg > orthanc-stone
annotate Framework/Widgets/TestCairoWidget.cpp @ 260:c887eddd48f1 am-2
merge
author | am@osimis.io |
---|---|
date | Tue, 17 Jul 2018 14:43:42 +0200 |
parents | fccffbf99ba1 |
children | f21ba2468570 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
134
4cff7b1ed31d
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 8 * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "TestCairoWidget.h" | |
23 | |
24 #include <stdio.h> | |
25 | |
26 | |
27 namespace OrthancStone | |
28 { | |
29 namespace Samples | |
30 { | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
31 void TestCairoWidget::UpdateContent() |
0 | 32 { |
33 value_ -= 0.01f; | |
34 if (value_ < 0) | |
35 { | |
36 value_ = 1; | |
37 } | |
38 | |
39 NotifyChange(); | |
40 } | |
41 | |
42 | |
43 bool TestCairoWidget::RenderCairo(CairoContext& context) | |
44 { | |
45 cairo_t* cr = context.GetObject(); | |
46 | |
47 cairo_set_source_rgb (cr, .3, 0, 0); | |
48 cairo_paint(cr); | |
49 | |
50 cairo_set_source_rgb(cr, 0, 1, 0); | |
51 cairo_rectangle(cr, width_ / 4, height_ / 4, width_ / 2, height_ / 2); | |
52 cairo_set_line_width(cr, 1.0); | |
53 cairo_fill(cr); | |
54 | |
55 cairo_set_source_rgb(cr, 0, 1, value_); | |
56 cairo_rectangle(cr, width_ / 2 - 50, height_ / 2 - 50, 100, 100); | |
57 cairo_fill(cr); | |
58 | |
59 return true; | |
60 } | |
61 | |
62 | |
63 void TestCairoWidget::RenderMouseOverCairo(CairoContext& context, | |
64 int x, | |
65 int y) | |
66 { | |
67 cairo_t* cr = context.GetObject(); | |
68 | |
69 cairo_set_source_rgb (cr, 1, 0, 0); | |
70 cairo_rectangle(cr, x - 5, y - 5, 10, 10); | |
71 cairo_set_line_width(cr, 1.0); | |
72 cairo_stroke(cr); | |
73 | |
74 char buf[64]; | |
75 sprintf(buf, "(%d,%d)", x, y); | |
76 UpdateStatusBar(buf); | |
77 } | |
78 | |
79 | |
80 TestCairoWidget::TestCairoWidget(bool animate) : | |
81 width_(0), | |
82 height_(0), | |
83 value_(1), | |
84 animate_(animate) | |
85 { | |
86 } | |
87 | |
88 | |
89 void TestCairoWidget::SetSize(unsigned int width, | |
90 unsigned int height) | |
91 { | |
92 CairoWidget::SetSize(width, height); | |
93 width_ = width; | |
94 height_ = height; | |
95 } | |
96 | |
97 | |
98 IMouseTracker* TestCairoWidget::CreateMouseTracker(MouseButton button, | |
99 int x, | |
100 int y, | |
101 KeyboardModifiers modifiers) | |
102 { | |
103 UpdateStatusBar("Click"); | |
104 return NULL; | |
105 } | |
106 | |
107 | |
108 void TestCairoWidget::MouseWheel(MouseWheelDirection direction, | |
109 int x, | |
110 int y, | |
111 KeyboardModifiers modifiers) | |
112 { | |
113 UpdateStatusBar(direction == MouseWheelDirection_Down ? "Wheel down" : "Wheel up"); | |
114 } | |
115 | |
116 | |
117 void TestCairoWidget::KeyPressed(char key, | |
118 KeyboardModifiers modifiers) | |
119 { | |
120 UpdateStatusBar("Key pressed: \"" + std::string(1, key) + "\""); | |
121 } | |
122 } | |
123 } |