diff options
author | Sebastian Geerken <devnull@localhost> | 2013-09-16 12:49:03 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2013-09-16 12:49:03 +0200 |
commit | c8a4d1e1da9534f030908c792e8922d8509eb2a4 (patch) | |
tree | 8ce3eeae41cd81d8e44e78e1d2682997a3f27772 | |
parent | 3331bb0ed3cc7ffb4d283170659c151abd5fa884 (diff) |
Extended test for bg images.
-rw-r--r-- | test/dw_image_background.cc | 71 |
1 files changed, 49 insertions, 22 deletions
diff --git a/test/dw_image_background.cc b/test/dw_image_background.cc index ccb59479..4e91cde0 100644 --- a/test/dw_image_background.cc +++ b/test/dw_image_background.cc @@ -17,6 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <stdlib.h> + #include <FL/Fl.H> #include <FL/Fl_Window.H> @@ -31,36 +33,54 @@ using namespace dw::core; using namespace dw::core::style; using namespace dw::fltk; -static StyleImage *image; +static StyleImage *image1 = NULL, *image2 = NULL; static Layout *layout; -static int imgRow = 0; +static int imgRow1 = 0, imgRow2 = 0; static void imageInitTimeout (void *data) { - Imgbuf *imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200, 1); - image->getMainImgRenderer()->setBuffer (imgbuf, false); + if (image1) { + Imgbuf *imgbuf1 = layout->createImgbuf (Imgbuf::RGB, 400, 200, 1); + image1->getMainImgRenderer()->setBuffer (imgbuf1, false); + } + + if (image2) { + Imgbuf *imgbuf2 = layout->createImgbuf (Imgbuf::RGB, 100, 100, 1); + image2->getMainImgRenderer()->setBuffer (imgbuf2, false); + } } static void imageDrawTimeout (void *data) { - Imgbuf *imgbuf = image->getImgbuf (); - - if (imgbuf) { - for (int i = 0; i < 1; i++) { - byte buf[3 * 400]; - for(int x = 0; x < 400; x++) { - buf[3 * x + 0] = x * 255 / 399; - buf[3 * x + 1] = (399 - x) * 255 / 399; - buf[3 * x + 2] = imgRow * 255 / 199; - } - - imgbuf->copyRow (imgRow, buf); - image->getMainImgRenderer()->drawRow (imgRow); - imgRow++; + Imgbuf *imgbuf1 = image1 ? image1->getImgbuf () : NULL; + Imgbuf *imgbuf2 = image2 ? image2->getImgbuf () : NULL; + + if (imgbuf1 && imgRow1 < 200) { + byte buf[3 * 400]; + for(int x = 0; x < 400; x++) { + buf[3 * x + 0] = 128 + x * 127 / 399; + buf[3 * x + 1] = 128 + (399 - x) * 127 / 399; + buf[3 * x + 2] = 128 + imgRow1 * 127 / 199; + } + + imgbuf1->copyRow (imgRow1, buf); + image1->getMainImgRenderer()->drawRow (imgRow1); + imgRow1++; + } + + if (imgbuf2 && imgRow2 < 100) { + byte buf[3 * 100]; + for(int x = 0; x < 100; x++) { + int r = 128 + rand () % 127; + buf[3 * x + 0] = buf[3 * x + 1] = buf[3 * x + 2] = r; } + + imgbuf2->copyRow (imgRow2, buf); + image2->getMainImgRenderer()->drawRow (imgRow2); + imgRow2++; } - if(imgRow < 200) + if(imgRow1 < 200 || imgRow2 < 100) Fl::repeat_timeout (0.5, imageDrawTimeout, NULL); } @@ -92,7 +112,7 @@ int main(int argc, char **argv) styleAttrs.color = Color::create (layout, 0x000000); styleAttrs.backgroundColor = Color::create (layout, 0xffffff); - image = styleAttrs.backgroundImage = StyleImage::create (); + image1 = styleAttrs.backgroundImage = StyleImage::create (); styleAttrs.backgroundRepeat = BACKGROUND_REPEAT_Y; styleAttrs.backgroundPositionX = createPerLength (0.5); styleAttrs.backgroundPositionY = createAbsLength (30); @@ -111,6 +131,12 @@ int main(int argc, char **argv) Style *wordStyle = Style::create (&styleAttrs); + image2 = styleAttrs.backgroundImage = StyleImage::create (); + styleAttrs.backgroundRepeat = BACKGROUND_REPEAT; + styleAttrs.backgroundPositionX = createPerLength (0); + styleAttrs.backgroundPositionY = createPerLength (0); + Style *wordStyleBg = Style::create (&styleAttrs); + for(int i = 1; i <= 10; i++) { char buf[4]; sprintf(buf, "%d.", i); @@ -121,7 +147,7 @@ int main(int argc, char **argv) NULL }; for(int j = 0; words[j]; j++) { - textblock->addText(words[j], wordStyle); + textblock->addText(words[j], j == 3 ? wordStyleBg : wordStyle); textblock->addSpace(wordStyle); } @@ -129,13 +155,14 @@ int main(int argc, char **argv) } wordStyle->unref(); + wordStyleBg->unref(); textblock->flush (); window->resizable(viewport); window->show(); - Fl::add_timeout (2.0, imageInitTimeout, NULL); + Fl::add_timeout (1.0, imageInitTimeout, NULL); Fl::add_timeout (0.1, imageDrawTimeout, NULL); int errorCode = Fl::run(); |