Picture widget added.

This commit is contained in:
Scott Duensing 2022-06-28 16:29:12 -05:00
parent e812146766
commit 4923843f38
5 changed files with 148 additions and 2 deletions

View file

@ -53,6 +53,7 @@ HEADERS += \
src/gui/image.h \
src/gui/surface.h \
src/gui/widgets/label.h \
src/gui/widgets/picture.h \
src/gui/wmwindow.h \
src/os.h \
src/platform/platform.h \
@ -69,6 +70,7 @@ SOURCES += \
src/gui/image.c \
src/gui/surface.c \
src/gui/widgets/label.c \
src/gui/widgets/picture.c \
src/gui/wmwindow.c \
src/main.c \
src/platform/djgpp.c \

View file

@ -191,9 +191,8 @@ uint8_t guiStartup(int16_t width, int16_t height, int16_t depth) {
wmStartup();
// Register all known widgets with the GUI.
// Always have to have a window type.
guiRegister(windowRegister);
guiRegister(labelRegister);
return SUCCESS;
}

View file

@ -0,0 +1,92 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#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(uint16_t x, uint16_t y, 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((WidgetT *)p, __MAGIC_PICTURE, x, y, 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 &reg;
}

View file

@ -0,0 +1,47 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#ifndef PICTURE_H
#define PICTURE_H
#include "../gui.h"
typedef struct PictureS {
WidgetT base; // Required by all widgets.
SurfaceT *picture; // Picture to display.
} PictureT;
extern uint8_t __MAGIC_PICTURE; // Magic ID assigned to us from the GUI.
void pictureClickSet(PictureT *picture, ClickHandlerT handler, void *data);
PictureT *pictureCreate(uint16_t x, uint16_t y, char *filename, ...);
RegisterT *pictureRegister(uint8_t magic);
#endif // PICTURE_H

View file

@ -26,6 +26,7 @@
#include "gui/gui.h"
#include "gui/wmwindow.h"
#include "gui/widgets/label.h"
#include "gui/widgets/picture.h"
void clickHandler(WidgetT *widget, uint16_t x, uint16_t y, void *data) {
@ -46,6 +47,11 @@ int main(int argc, char *argv[]) {
logOpenByHandle(memoryLogHandleGet());
if (guiStartup(800, 600, 16) == SUCCESS) {
// Register all desired widgets with Roo/E.
guiRegister(labelRegister);
guiRegister(pictureRegister);
for (i=1; i<4; i++) {
sprintf(title, "Testing %d", i);
w = windowCreate(i * 50, i * 50, 300, 200, title, WIN_STANDARD, 640, 480);