Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
dw_images_simple.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 * Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22
23#include <FL/Fl.H>
24#include <FL/Fl_Window.H>
25
26#include "dw/core.hh"
27#include "dw/fltkcore.hh"
28#include "dw/fltkviewport.hh"
29#include "dw/textblock.hh"
30#include "dw/image.hh"
31
32using namespace dw;
33using namespace dw::core;
34using namespace dw::core::style;
35using namespace dw::fltk;
36
37static Layout *layout;
38static Image *image;
39static core::Imgbuf *imgbuf = NULL;
40static int imgRow = 0;
41
42static void imageInitTimeout (void *data)
43{
44 const bool resize = true;
45 //imgbuf = layout->createImgbuf (Imgbuf::RGBA, 400, 200);
46 imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200, 1);
47 image->setBuffer (imgbuf, resize);
48}
49
50/*
51static void imageDrawTimeout (void *data)
52{
53 if (imgbuf) {
54 for (int i = 0; i < 1; i++) {
55 byte buf[4 * 400];
56 for(int x = 0; x < 400; x++) {
57 buf[4 * x + 0] = x * 255 / 399;
58 buf[4 * x + 1] = (399 - x) * 255 / 399;
59 buf[4 * x + 2] = imgRow * 255 / 199;
60 buf[4 * x + 3] = (199 - imgRow) * 255 / 199;
61 }
62
63 imgbuf->copyRow (imgRow, buf);
64 image->drawRow (imgRow);
65 imgRow++;
66 }
67 }
68
69 if(imgRow < 200)
70 Fl::repeat_timeout (0.5, imageDrawTimeout, NULL);
71}
72*/
73
74static void imageDrawTimeout (void *data)
75{
76 if (imgbuf) {
77 for (int i = 0; i < 1; i++) {
78 byte buf[3 * 400];
79 for(int x = 0; x < 400; x++) {
80 buf[3 * x + 0] = x * 255 / 399;
81 buf[3 * x + 1] = (399 - x) * 255 / 399;
82 buf[3 * x + 2] = imgRow * 255 / 199;
83 }
84
85 imgbuf->copyRow (imgRow, buf);
87 imgRow++;
88 }
89 }
90
91 if(imgRow < 200)
92 Fl::repeat_timeout (0.5, imageDrawTimeout, NULL);
93}
94
95int main(int argc, char **argv)
96{
98 layout = new Layout (platform);
99
100 Fl_Window *window = new Fl_Window(410, 210, "Dw Simple Image");
101 window->box(FL_NO_BOX);
102 window->begin();
103
104 FltkViewport *viewport = new FltkViewport (0, 0, 410, 210);
106
107 StyleAttrs styleAttrs;
108 styleAttrs.initValues ();
109 styleAttrs.margin.setVal (5);
110
111 FontAttrs fontAttrs;
112 fontAttrs.name = "Bitstream Charter";
113 fontAttrs.size = 14;
114 fontAttrs.weight = 400;
115 fontAttrs.style = FONT_STYLE_NORMAL;
116 fontAttrs.letterSpacing = 0;
118 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
119
120 styleAttrs.color = Color::create (layout, 0x000000);
121 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
122
123 Style *widgetStyle = Style::create (&styleAttrs);
124
125 Textblock *textblock = new Textblock (false);
126 textblock->setStyle (widgetStyle);
127 layout->setWidget (textblock);
128
130
131 styleAttrs.margin.setVal (0);
132 styleAttrs.backgroundColor = NULL;
133
134 Style *imageStyle = Style::create (&styleAttrs);
135
136 image = new dw::Image ("");
137 textblock->addWidget (image, imageStyle);
138 textblock->addSpace (imageStyle);
139
140 imageStyle->unref();
141
142 textblock->flush ();
143
144 window->resizable(viewport);
145 window->show();
146
147 Fl::add_timeout (2.0, imageInitTimeout, NULL);
148 Fl::add_timeout (0.1, imageDrawTimeout, NULL);
149
150 int errorCode = Fl::run();
151
152 delete layout;
153
154 return errorCode;
155}
int main(void)
Definition bookmarks.c:1613
Displays an instance of dw::core::Imgbuf.
Definition image.hh:120
void drawRow(int row)
Called, when data from a row is available and has been copied into the image buffer.
Definition image.cc:520
void setBuffer(core::Imgbuf *buffer, bool resize=false)
Called, when an image buffer is attached.
Definition image.cc:489
A Widget for rendering text blocks, i.e.
Definition textblock.hh:206
void addWidget(core::Widget *widget, core::style::Style *style)
Add a widget (word type) to the page.
void addSpace(core::style::Style *style)
?
The platform independent interface for image buffers.
Definition imgbuf.hh:162
virtual void copyRow(int row, const byte *data)=0
The central class for managing and drawing a widget tree.
Definition layout.hh:17
void attachView(View *view)
Attach a view to the layout.
Definition layout.cc:459
void setWidget(Widget *widget)
Definition layout.cc:433
Imgbuf * createImgbuf(Imgbuf::Type type, int width, int height, double gamma)
Definition layout.hh:410
virtual void setStyle(style::Style *style)
Change the style of a widget.
Definition widget.cc:1316
void setVal(int val)
Definition style.hh:510
static Color * create(Layout *layout, int color)
Definition style.cc:529
FontVariant fontVariant
Definition style.hh:688
static Font * create(Layout *layout, FontAttrs *attrs)
Definition style.cc:444
static Style * create(StyleAttrs *attrs)
Definition style.hh:629
static Style * widgetStyle
static Fl_Window * window
static FltkPlatform * platform
static FltkViewport * viewport
static Image * image
static void imageInitTimeout(void *data)
static Layout * layout
static core::Imgbuf * imgbuf
static int imgRow
static void imageDrawTimeout(void *data)
Anything related to Dillo Widget styles is defined here.
Definition style.cc:34
@ FONT_VARIANT_NORMAL
Definition style.hh:333
The core of Dw is defined in this namespace.
Definition core.hh:23
This namespace contains FLTK implementations of Dw interfaces.
Dw is in this namespace, or sub namespaces of this one.