Dillo v3.1.1-99-gf3103cc4
Loading...
Searching...
No Matches
dw_images_scaled2.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;
39static core::Imgbuf *imgbuf = NULL;
40static int imgRow = 0;
41
42static void imageInitTimeout (void *data)
43{
44 imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200, 1);
47}
48
49static void imageDrawTimeout (void *data)
50{
51 if (imgbuf) {
52 for (int i = 0; i < 1; i++) {
53 byte buf[3 * 400];
54 for(int x = 0; x < 400; x++) {
55 buf[3 * x + 0] = x * 255 / 399;
56 buf[3 * x + 1] = (399 - x) * 255 / 399;
57 buf[3 * x + 2] = imgRow * 255 / 199;
58 }
59
60 imgbuf->copyRow (imgRow, buf);
63 imgRow++;
64 }
65 }
66
67 if(imgRow < 200)
68 Fl::repeat_timeout (0.5, imageDrawTimeout, NULL);
69}
70
71int main(int argc, char **argv)
72{
74 layout = new Layout (platform);
75
76 Fl_Window *window = new Fl_Window(410, 210, "Dw Scaled Image 2");
77 window->box(FL_NO_BOX);
78 window->begin();
79
80 FltkViewport *viewport = new FltkViewport (0, 0, 410, 210);
82
83 StyleAttrs styleAttrs;
84 styleAttrs.initValues ();
85 styleAttrs.margin.setVal (5);
86
87 FontAttrs fontAttrs;
88 fontAttrs.name = "Bitstream Charter";
89 fontAttrs.size = 14;
90 fontAttrs.weight = 400;
91 fontAttrs.style = FONT_STYLE_NORMAL;
92 fontAttrs.letterSpacing = 0;
94 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
95
96 styleAttrs.color = Color::create (layout, 0x000000);
97 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
98
99 Style *widgetStyle = Style::create (&styleAttrs);
100
101 Textblock *textblock = new Textblock (false);
102 textblock->setStyle (widgetStyle);
103 layout->setWidget (textblock);
104
106
107 styleAttrs.margin.setVal (0);
108 styleAttrs.borderWidth.setVal (0);
109 styleAttrs.padding.setVal (0);
110 styleAttrs.backgroundColor = NULL;
111
112 Style *wordStyle = Style::create (&styleAttrs);
113
114 styleAttrs.borderWidth.setVal (1);
115 styleAttrs.setBorderColor (Color::create (layout, 0x000080));
116 styleAttrs.setBorderStyle (BORDER_SOLID);
117 styleAttrs.padding.setVal (1);
118 styleAttrs.backgroundColor = NULL;
119 styleAttrs.width = createPerLength (0.25);
120 styleAttrs.height = createPerLength (0.25);
121
122 Style *imageStyle1 = Style::create (&styleAttrs);
123 image1 = new dw::Image ("A longer ALT Text to demonstrate clipping.");
124 textblock->addWidget (image1, imageStyle1);
125 imageStyle1->unref();
126
127 textblock->addParbreak (10, wordStyle);
128
129 styleAttrs.width = LENGTH_AUTO;
130 styleAttrs.height = LENGTH_AUTO;
131
132 Style *imageStyle2 = Style::create (&styleAttrs);
133 image2 = new dw::Image ("A longer ALT Text to demonstrate clipping.");
134 textblock->addWidget (image2, imageStyle2);
135 imageStyle2->unref();
136
137 wordStyle->unref ();
138 textblock->flush ();
139
140 window->resizable(viewport);
141 window->show();
142
143 Fl::add_timeout (3.0, imageInitTimeout, NULL);
144 Fl::add_timeout (0.1, imageDrawTimeout, NULL);
145
146 int errorCode = Fl::run();
147
148 delete layout;
149
150 return errorCode;
151}
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 addParbreak(int space, core::style::Style *style)
Cause a paragraph break.
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
void setBorderStyle(BorderStyle val)
Definition style.hh:588
void setBorderColor(Color *val)
Definition style.hh:585
static Style * create(StyleAttrs *attrs)
Definition style.hh:629
static Style * wordStyle
static Style * widgetStyle
static Fl_Window * window
static FltkPlatform * platform
static FltkViewport * viewport
static void imageInitTimeout(void *data)
static Layout * layout
static Image * image1
static core::Imgbuf * imgbuf
static Image * image2
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
@ LENGTH_AUTO
Represents "auto" lengths.
Definition style.hh:495
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.