Mercurial > dillo_port1.3
annotate test/dw_images_scaled2.cc @ 2012:bfb8bc9ddf62
Avoid lots of flicker while resizing the window
(when "buffered_drawing" is set to 0 or 1)
author | Jorge Arellano Cid <jcid@dillo.org> |
---|---|
date | Fri, 13 May 2011 14:14:43 -0400 |
parents | 553e63661ec1 |
children | 8cf59505bd0a |
rev | line source |
---|---|
347 | 1 /* |
2 * Dillo Widget | |
3 * | |
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 3 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
972
d7dbd3dcfa38
Updated the GPL copyright note in the source files
Detlef Riekenberg <wine.dev@web.de>
parents:
677
diff
changeset
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
347 | 18 */ |
19 | |
20 | |
21 | |
1832 | 22 #include <FL/Fl.H> |
23 #include <FL/Fl_Window.H> | |
347 | 24 |
25 #include "../dw/core.hh" | |
26 #include "../dw/fltkcore.hh" | |
27 #include "../dw/fltkviewport.hh" | |
28 #include "../dw/textblock.hh" | |
29 #include "../dw/image.hh" | |
30 | |
31 using namespace dw; | |
32 using namespace dw::core; | |
33 using namespace dw::core::style; | |
34 using namespace dw::fltk; | |
35 | |
36 static Layout *layout; | |
37 static Image *image1, *image2; | |
38 static core::Imgbuf *imgbuf = NULL; | |
39 static int imgRow = 0; | |
40 | |
41 static void imageInitTimeout (void *data) | |
42 { | |
43 imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200); | |
44 image1->setBuffer (imgbuf); | |
45 image2->setBuffer (imgbuf); | |
46 } | |
47 | |
48 static void imageDrawTimeout (void *data) | |
49 { | |
50 if (imgbuf) { | |
51 for (int i = 0; i < 1; i++) { | |
52 byte buf[3 * 400]; | |
53 for(int x = 0; x < 400; x++) { | |
54 buf[3 * x + 0] = x * 255 / 399; | |
55 buf[3 * x + 1] = (399 - x) * 255 / 399; | |
56 buf[3 * x + 2] = imgRow * 255 / 199; | |
57 } | |
1326 | 58 |
347 | 59 imgbuf->copyRow (imgRow, buf); |
1326 | 60 image1->drawRow (imgRow); |
61 image2->drawRow (imgRow); | |
347 | 62 imgRow++; |
63 } | |
64 } | |
1326 | 65 |
347 | 66 if(imgRow < 200) |
1832 | 67 Fl::repeat_timeout (0.5, imageDrawTimeout, NULL); |
347 | 68 } |
69 | |
70 int main(int argc, char **argv) | |
71 { | |
72 FltkPlatform *platform = new FltkPlatform (); | |
73 layout = new Layout (platform); | |
74 | |
1832 | 75 Fl_Window *window = new Fl_Window(410, 210, "Dw Scaled Image 2"); |
2012
bfb8bc9ddf62
Avoid lots of flicker while resizing the window
Jorge Arellano Cid <jcid@dillo.org>
parents:
1832
diff
changeset
|
76 window->box(FL_NO_BOX); |
347 | 77 window->begin(); |
78 | |
79 FltkViewport *viewport = new FltkViewport (0, 0, 410, 210); | |
80 layout->attachView (viewport); | |
81 | |
82 StyleAttrs styleAttrs; | |
83 styleAttrs.initValues (); | |
84 styleAttrs.margin.setVal (5); | |
85 | |
86 FontAttrs fontAttrs; | |
87 fontAttrs.name = "Bitstream Charter"; | |
88 fontAttrs.size = 14; | |
89 fontAttrs.weight = 400; | |
90 fontAttrs.style = FONT_STYLE_NORMAL; | |
1462
8de487d495f7
initialize fontAttrs.letterSpacing in test programs
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1326
diff
changeset
|
91 fontAttrs.letterSpacing = 0; |
1832 | 92 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs); |
347 | 93 |
677
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
94 styleAttrs.color = Color::create (layout, 0x000000); |
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
95 styleAttrs.backgroundColor = Color::create (layout, 0xffffff); |
347 | 96 |
97 Style *widgetStyle = Style::create (layout, &styleAttrs); | |
98 | |
99 Textblock *textblock = new Textblock (false); | |
100 textblock->setStyle (widgetStyle); | |
101 layout->setWidget (textblock); | |
102 | |
103 widgetStyle->unref(); | |
104 | |
105 styleAttrs.margin.setVal (0); | |
106 styleAttrs.borderWidth.setVal (0); | |
107 styleAttrs.padding.setVal (0); | |
108 styleAttrs.backgroundColor = NULL; | |
109 | |
110 Style *wordStyle = Style::create (layout, &styleAttrs); | |
111 | |
112 styleAttrs.borderWidth.setVal (1); | |
677
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
113 styleAttrs.setBorderColor (Color::create (layout, 0x000080)); |
347 | 114 styleAttrs.setBorderStyle (BORDER_SOLID); |
115 styleAttrs.padding.setVal (1); | |
116 styleAttrs.backgroundColor = NULL; | |
117 styleAttrs.width = createPerLength (0.5); | |
118 styleAttrs.height = createPerLength (0.5); | |
119 | |
120 Style *imageStyle1 = Style::create (layout, &styleAttrs); | |
121 image1 = new dw::Image ("A longer ALT Text to demonstrate clipping."); | |
122 textblock->addWidget (image1, imageStyle1); | |
123 imageStyle1->unref(); | |
124 | |
125 textblock->addParbreak (10, wordStyle); | |
126 | |
127 styleAttrs.width = LENGTH_AUTO; | |
128 styleAttrs.height = LENGTH_AUTO; | |
129 | |
130 Style *imageStyle2 = Style::create (layout, &styleAttrs); | |
131 image2 = new dw::Image ("A longer ALT Text to demonstrate clipping."); | |
132 textblock->addWidget (image2, imageStyle2); | |
133 imageStyle2->unref(); | |
134 | |
135 wordStyle->unref (); | |
136 textblock->flush (); | |
137 | |
138 window->resizable(viewport); | |
139 window->show(); | |
140 | |
1832 | 141 Fl::add_timeout (3.0, imageInitTimeout, NULL); |
142 Fl::add_timeout (0.1, imageDrawTimeout, NULL); | |
347 | 143 |
1832 | 144 int errorCode = Fl::run(); |
347 | 145 |
146 delete layout; | |
147 | |
148 return errorCode; | |
149 } |