Dillo v3.1.1-99-gf3103cc4
Loading...
Searching...
No Matches
dw_images_scaled.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 //imgbuf = layout->createImgbuf (Imgbuf::RGBA, 400, 200);
45 imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200, 1);
47}
48
49/*
50static void imageDrawTimeout (void *data)
51{
52 if (imgbuf) {
53 for (int i = 0; i < 1; i++) {
54 byte buf[4 * 400];
55 for(int x = 0; x < 400; x++) {
56 buf[4 * x + 0] = x * 255 / 399;
57 buf[4 * x + 1] = (399 - x) * 255 / 399;
58 buf[4 * x + 2] = imgRow * 255 / 199;
59 buf[4 * x + 3] = (199 - imgRow) * 255 / 199;
60 }
61
62 imgbuf->copyRow (imgRow, buf);
63 image->drawRow (imgRow);
64 imgRow++;
65 }
66 }
67
68 if(imgRow < 200)
69 ::fltk::repeat_timeout (0.5, imageDrawTimeout, NULL);
70}
71*/
72
73static void imageDrawTimeout (void *data)
74{
75 if (imgbuf) {
76 for (int i = 0; i < 1; i++) {
77 byte buf[3 * 400];
78 for(int x = 0; x < 400; x++) {
79 buf[3 * x + 0] = x * 255 / 399;
80 buf[3 * x + 1] = (399 - x) * 255 / 399;
81 buf[3 * x + 2] = imgRow * 255 / 199;
82 }
83
84 imgbuf->copyRow (imgRow, buf);
86 imgRow++;
87 }
88 }
89
90 if(imgRow < 200)
91 Fl::repeat_timeout (0.5, imageDrawTimeout, NULL);
92}
93
94int main(int argc, char **argv)
95{
97 layout = new Layout (platform);
98
99 Fl_Window *window = new Fl_Window(410, 210, "Dw Scaled Image");
100 window->box(FL_NO_BOX);
101 window->begin();
102
103 FltkViewport *viewport = new FltkViewport (0, 0, 410, 210);
105
106 StyleAttrs styleAttrs;
107 styleAttrs.initValues ();
108 styleAttrs.margin.setVal (5);
109 styleAttrs.width = createPerLength (1.0);
110 styleAttrs.height = createPerLength (1.0);
111
112 FontAttrs fontAttrs;
113 fontAttrs.name = "Bitstream Charter";
114 fontAttrs.size = 14;
115 fontAttrs.weight = 400;
116 fontAttrs.style = FONT_STYLE_NORMAL;
117 fontAttrs.letterSpacing = 0;
119 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
120
121 styleAttrs.color = Color::create (layout, 0x000000);
122 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
123
124 Style *widgetStyle = Style::create (&styleAttrs);
125
126 Textblock *textblock = new Textblock (false);
127 textblock->setStyle (widgetStyle);
128 layout->setWidget (textblock);
129
131
132 styleAttrs.margin.setVal (0);
133 styleAttrs.backgroundColor = NULL;
134
135 Style *imageStyle = Style::create (&styleAttrs);
136
137 image = new dw::Image ("");
138 textblock->addWidget (image, imageStyle);
139 textblock->addSpace (imageStyle);
140
141 imageStyle->unref();
142
143 textblock->flush ();
144
145 window->resizable(viewport);
146 window->show();
147
148 Fl::add_timeout (2.0, imageInitTimeout, NULL);
149 Fl::add_timeout (0.1, imageDrawTimeout, NULL);
150
151 int errorCode = Fl::run();
152
153 delete layout;
154
155 return errorCode;
156}
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
Length createPerLength(double v)
Returns a percentage, v is relative to 1, not to 100.
Definition style.hh:435
@ 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.