/* * Roo/E, the Kangaroo Punch Portable GUI Toolkit * Copyright (C) 2022 Scott Duensing * * http://kangaroopunch.com * * * This file is part of Roo/E. * * Roo/E is free software: you can redistribute it and/or modify it under the * terms of the GNU Affero General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) * any later version. * * Roo/E is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License * along with Roo/E. If not, see . * */ #include "../image.h" #include "picture.h" uint8_t __MAGIC_PICTURE = 0; static void pictureDestroy(struct WidgetS *widget, ...); static void picturePaint(struct WidgetS *widget, ...); void pictureClickSet(PictureT *picture, ClickHandlerT handler, void *data) { picture->base.reg->click = handler; picture->base.data = data; } PictureT *pictureCreate(char *filename, ...) { PictureT *p = NULL; NEW(PictureT, p); memset(p, 0, sizeof(PictureT)); p->picture = imageLoad(filename); if (!p->picture) { DEL(p); return NULL; } guiWidgetBaseSet(W(p), __MAGIC_PICTURE, surfaceWidthGet(p->picture), surfaceHeightGet(p->picture)); return p; } static void pictureDestroy(struct WidgetS *widget, ...) { PictureT *p = (PictureT *)widget; if (p->picture) DEL(p->picture); DEL(p); } static void picturePaint(struct WidgetS *widget, ...) { PictureT *p = (PictureT *)widget; if (guiWidgetDirtyGet(widget)) { guiWidgetDirtySet(widget, 0); // ***TODO*** Clipping. surfaceBlit(p->base.r.x, p->base.r.y, 0, 0, 0, 0, p->picture); } } RegisterT *pictureRegister(uint8_t magic) { static RegisterT reg = { "Picture", NULL, // No default on-click handler. pictureDestroy, picturePaint, NULL // No unregister handler. }; // One-time widget startup code. __MAGIC_PICTURE = magic; return ® }