Mercurial > dillo_port1.3
annotate test/dw_links.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 | |
30 using namespace dw; | |
31 using namespace dw::core; | |
32 using namespace dw::core::style; | |
33 using namespace dw::fltk; | |
34 | |
1375 | 35 class LinkTestReceiver: public Layout::LinkReceiver |
347 | 36 { |
1314 | 37 bool enter (Widget *widget, int link, int img, int x, int y); |
38 bool press (Widget *widget, int link, int img, int x, int y, | |
39 EventButton *event); | |
40 bool release (Widget *widget, int link, int img, int x, int y, | |
41 EventButton *event); | |
42 bool click (Widget *widget, int link, int img, | |
43 int x, int y, EventButton *event); | |
347 | 44 }; |
45 | |
1314 | 46 bool LinkTestReceiver::enter (Widget *widget, int link, int img, int x, int y) |
347 | 47 { |
48 printf ("enter: %d\n", link); | |
49 return true; | |
50 } | |
51 | |
1314 | 52 bool LinkTestReceiver::press (Widget *widget, int link, int img, int x, int y, |
347 | 53 EventButton *event) |
54 { | |
55 printf ("press: %d\n", link); | |
56 return true; | |
57 } | |
58 | |
1314 | 59 bool LinkTestReceiver::release (Widget *widget, int link, int img, int x,int y, |
347 | 60 EventButton *event) |
61 { | |
62 printf ("release: %d\n", link); | |
63 return true; | |
64 } | |
65 | |
1314 | 66 bool LinkTestReceiver::click (Widget *widget, int link, int img, int x, int y, |
347 | 67 EventButton *event) |
68 { | |
69 printf ("click: %d\n", link); | |
70 return true; | |
71 } | |
72 | |
73 int main(int argc, char **argv) | |
74 { | |
75 LinkTestReceiver linkTestReceiver; | |
76 FltkPlatform *platform = new FltkPlatform (); | |
77 Layout *layout = new Layout (platform); | |
78 | |
1832 | 79 Fl_Window *window = new Fl_Window(200, 300, "Dw Links"); |
2012
bfb8bc9ddf62
Avoid lots of flicker while resizing the window
Jorge Arellano Cid <jcid@dillo.org>
parents:
1832
diff
changeset
|
80 window->box(FL_NO_BOX); |
347 | 81 window->begin(); |
82 | |
83 FltkViewport *viewport = new FltkViewport (0, 0, 200, 300); | |
84 layout->attachView (viewport); | |
85 | |
86 StyleAttrs styleAttrs; | |
87 styleAttrs.initValues (); | |
88 styleAttrs.margin.setVal (5); | |
89 | |
90 FontAttrs fontAttrs; | |
91 fontAttrs.name = "Bitstream Charter"; | |
92 fontAttrs.size = 14; | |
93 fontAttrs.weight = 400; | |
94 fontAttrs.style = FONT_STYLE_NORMAL; | |
1462
8de487d495f7
initialize fontAttrs.letterSpacing in test programs
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1375
diff
changeset
|
95 fontAttrs.letterSpacing = 0; |
1832 | 96 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs); |
347 | 97 |
677
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
98 styleAttrs.color = Color::create (layout, 0x000000); |
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
99 styleAttrs.backgroundColor = Color::create (layout, 0xffffff); |
347 | 100 |
101 Style *widgetStyle = Style::create (layout, &styleAttrs); | |
102 | |
103 Textblock *textblock = new Textblock (false); | |
104 textblock->setStyle (widgetStyle); | |
105 layout->setWidget (textblock); | |
106 | |
1375 | 107 layout->connectLink (&linkTestReceiver); |
347 | 108 |
109 widgetStyle->unref(); | |
110 | |
111 styleAttrs.margin.setVal (0); | |
112 styleAttrs.backgroundColor = NULL; | |
113 styleAttrs.cursor = CURSOR_TEXT; | |
114 | |
115 Style *wordStyle = Style::create (layout, &styleAttrs); | |
116 | |
677
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
117 styleAttrs.color = Color::create (layout, 0x0000ff); |
347 | 118 styleAttrs.textDecoration = TEXT_DECORATION_UNDERLINE; |
119 styleAttrs.cursor = CURSOR_POINTER; | |
1326 | 120 |
347 | 121 for(int i = 1; i <= 10; i++) { |
122 char buf[4]; | |
123 sprintf(buf, "%d.", i); | |
124 | |
125 const char *words1[] = { | |
126 "This", "is", "the", buf, "paragraph.", | |
127 "Here", "comes", "some", "more", "text", | |
128 "to", "demonstrate", "word", "wrapping.", | |
129 NULL }; | |
130 const char *words2[] = { | |
131 "Click", "here", "for", "more..", NULL }; | |
132 | |
133 for(int j = 0; words1[j]; j++) { | |
134 textblock->addText(words1[j], wordStyle); | |
135 textblock->addSpace(wordStyle); | |
136 } | |
1326 | 137 |
347 | 138 styleAttrs.x_link = i; |
139 Style *linkStyle = Style::create (layout, &styleAttrs); | |
1326 | 140 |
347 | 141 for(int j = 0; words2[j]; j++) { |
142 textblock->addText(words2[j], linkStyle); | |
143 textblock->addSpace(wordStyle); | |
144 } | |
1326 | 145 |
347 | 146 linkStyle->unref (); |
147 | |
148 textblock->addParbreak(10, wordStyle); | |
149 } | |
150 | |
151 wordStyle->unref(); | |
152 | |
153 textblock->flush (); | |
154 | |
155 window->resizable(viewport); | |
156 window->show(); | |
1832 | 157 int errorCode = Fl::run(); |
347 | 158 |
159 delete layout; | |
160 | |
161 return errorCode; | |
162 } |