43 lines
2.5 KiB
C
43 lines
2.5 KiB
C
// widgetCanvas.h -- Canvas widget API
|
|
#ifndef WIDGET_CANVAS_H
|
|
#define WIDGET_CANVAS_H
|
|
|
|
#include "../core/dvxWidget.h"
|
|
|
|
typedef struct {
|
|
WidgetT *(*create)(WidgetT *parent, int32_t w, int32_t h);
|
|
void (*clear)(WidgetT *w, uint32_t color);
|
|
void (*setPenColor)(WidgetT *w, uint32_t color);
|
|
void (*setPenSize)(WidgetT *w, int32_t size);
|
|
void (*setMouseCallback)(WidgetT *w, void (*cb)(WidgetT *w, int32_t cx, int32_t cy, bool drag));
|
|
void (*save)(WidgetT *w, const char *path);
|
|
void (*load)(WidgetT *w, const char *path);
|
|
void (*drawLine)(WidgetT *w, int32_t x0, int32_t y0, int32_t x1, int32_t y1);
|
|
void (*drawRect)(WidgetT *w, int32_t x, int32_t y, int32_t width, int32_t height);
|
|
void (*fillRect)(WidgetT *w, int32_t x, int32_t y, int32_t width, int32_t height);
|
|
void (*fillCircle)(WidgetT *w, int32_t cx, int32_t cy, int32_t radius);
|
|
void (*setPixel)(WidgetT *w, int32_t x, int32_t y, uint32_t color);
|
|
uint32_t (*getPixel)(const WidgetT *w, int32_t x, int32_t y);
|
|
} CanvasApiT;
|
|
|
|
static inline const CanvasApiT *dvxCanvasApi(void) {
|
|
static const CanvasApiT *sApi;
|
|
if (!sApi) { sApi = (const CanvasApiT *)wgtGetApi("canvas"); }
|
|
return sApi;
|
|
}
|
|
|
|
#define wgtCanvas(parent, w, h) dvxCanvasApi()->create(parent, w, h)
|
|
#define wgtCanvasClear(w, color) dvxCanvasApi()->clear(w, color)
|
|
#define wgtCanvasSetPenColor(w, color) dvxCanvasApi()->setPenColor(w, color)
|
|
#define wgtCanvasSetPenSize(w, size) dvxCanvasApi()->setPenSize(w, size)
|
|
#define wgtCanvasSetMouseCallback(w, cb) dvxCanvasApi()->setMouseCallback(w, cb)
|
|
#define wgtCanvasSave(w, path) dvxCanvasApi()->save(w, path)
|
|
#define wgtCanvasLoad(w, path) dvxCanvasApi()->load(w, path)
|
|
#define wgtCanvasDrawLine(w, x0, y0, x1, y1) dvxCanvasApi()->drawLine(w, x0, y0, x1, y1)
|
|
#define wgtCanvasDrawRect(w, x, y, width, height) dvxCanvasApi()->drawRect(w, x, y, width, height)
|
|
#define wgtCanvasFillRect(w, x, y, width, height) dvxCanvasApi()->fillRect(w, x, y, width, height)
|
|
#define wgtCanvasFillCircle(w, cx, cy, radius) dvxCanvasApi()->fillCircle(w, cx, cy, radius)
|
|
#define wgtCanvasSetPixel(w, x, y, color) dvxCanvasApi()->setPixel(w, x, y, color)
|
|
#define wgtCanvasGetPixel(w, x, y) dvxCanvasApi()->getPixel(w, x, y)
|
|
|
|
#endif // WIDGET_CANVAS_H
|