diff options
author | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:56:41 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:59:33 -0800 |
commit | d577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch) | |
tree | 590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/test/canvas_cdsimple.c |
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/test/canvas_cdsimple.c')
-rwxr-xr-x | iup/test/canvas_cdsimple.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/iup/test/canvas_cdsimple.c b/iup/test/canvas_cdsimple.c new file mode 100755 index 0000000..3a73c22 --- /dev/null +++ b/iup/test/canvas_cdsimple.c @@ -0,0 +1,91 @@ +#include <stdlib.h> +#include <stdio.h> +#include "iup.h" +#include "cd.h" +#include "cdiup.h" +#include "cddbuf.h" + + +static int redraw_cb(Ihandle *ih) +{ + int width, height; + cdCanvas *cdcanvas = (cdCanvas*)IupGetAttribute(ih, "_APP_CDCANVAS"); + + cdCanvasBackground(cdcanvas, CD_WHITE); + cdCanvasClear(cdcanvas); + + cdCanvasForeground(cdcanvas, CD_RED); + cdCanvasGetSize(cdcanvas, &width, &height, NULL, NULL); + cdCanvasLine(cdcanvas, 0, 0, width-1, height-1); + cdCanvasLine(cdcanvas, 0, height-1, width-1, 0); + return IUP_DEFAULT; +} + +static int resize_cb(Ihandle *ih) +{ + cdCanvas *cdcanvas = (cdCanvas*)IupGetAttribute(ih, "_APP_CDCANVAS"); + + /* update canvas size */ + cdCanvasActivate(cdcanvas); + + return IUP_DEFAULT; +} + +static int map_cb(Ihandle *ih) +{ + cdCanvas *cdcanvas; + + cdcanvas = cdCreateCanvas(CD_IUP, ih); + if (!cdcanvas) + return IUP_DEFAULT; + + IupSetAttribute(ih, "_APP_CDCANVAS", (char*)cdcanvas); + + return IUP_DEFAULT; +} + +static int unmap_cb(Ihandle *ih) +{ + cdCanvas *cdcanvas = (cdCanvas*)IupGetAttribute(ih, "_APP_CDCANVAS"); + + if (cdcanvas) + cdKillCanvas(cdcanvas); + + return IUP_DEFAULT; +} + +void CanvasCDSimpleTest(void) +{ + Ihandle *dlg, *canvas; + + canvas = IupCanvas(NULL); + IupSetAttribute(canvas, "RASTERSIZE", "300x200"); /* initial size */ + + IupSetCallback(canvas, "RESIZE_CB", (Icallback)resize_cb); + IupSetCallback(canvas, "ACTION", (Icallback)redraw_cb); + IupSetCallback(canvas, "MAP_CB", (Icallback)map_cb); + IupSetCallback(canvas, "UNMAP_CB", (Icallback)unmap_cb); + + dlg = IupDialog(canvas); + IupSetAttribute(dlg, "TITLE", "CD Simple Buffer Test"); + + IupMap(dlg); + IupSetAttribute(canvas, "RASTERSIZE", NULL); /* release the minimum limitation */ + + IupShowXY(dlg,IUP_CENTER,IUP_CENTER); +} + +#ifndef BIG_TEST +int main(int argc, char* argv[]) +{ + IupOpen(&argc, &argv); + + CanvasCDSimpleTest(); + + IupMainLoop(); + + IupClose(); + + return EXIT_SUCCESS; +} +#endif |