Initial commit
This commit is contained in:
127
src/k3menu.h
Normal file
127
src/k3menu.h
Normal file
@@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include<stdint.h>
|
||||
#include<stdlib.h>
|
||||
#include<stdbool.h>
|
||||
#include"k3font.h"
|
||||
|
||||
struct k3MObj;
|
||||
|
||||
#define k3M_EVENT_MOUSE_ENTER 0
|
||||
#define k3M_EVENT_MOUSE_MOTION 1
|
||||
#define k3M_EVENT_MOUSE_LEAVE 2
|
||||
#define k3M_EVENT_MOUSE_PRESS 3
|
||||
#define k3M_EVENT_MOUSE_RELEASE 4
|
||||
#define k3M_EVENT_MOUSE_CLICK 5
|
||||
#define k3M_EVENT_KEY_PRESS 6
|
||||
#define k3M_EVENT_KEY_RELEASE 7
|
||||
#define k3M_EVENT_INPUT 8
|
||||
#define k3M_EVENT_DRAW 9
|
||||
#define k3M_EVENT_COMPLETE 10
|
||||
#define k3M_EVENT_ALL 11
|
||||
|
||||
#define k3M_MOUSE_BUTTON_0 0
|
||||
#define k3M_MOUSE_BUTTON_1 1
|
||||
#define k3M_MOUSE_BUTTON_2 2
|
||||
|
||||
#define k3M_EVENTKIND_DIRECT 0
|
||||
#define k3M_EVENTKIND_CAPTURE 1
|
||||
#define k3M_EVENTKIND_BUBBLE 2
|
||||
|
||||
#define k3M_USERDATA_SIZE 16
|
||||
|
||||
struct k3MEvent {
|
||||
uint16_t code;
|
||||
|
||||
uint8_t kind;
|
||||
|
||||
struct k3MObj *original;
|
||||
struct k3MObj *target;
|
||||
|
||||
union {
|
||||
struct {
|
||||
int button;
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
} mouse;
|
||||
struct {
|
||||
uint32_t num;
|
||||
} key;
|
||||
struct {
|
||||
uint32_t code;
|
||||
} input;
|
||||
};
|
||||
};
|
||||
|
||||
typedef bool(*k3MEventHandlerFunc)(struct k3MEvent*, uint8_t *ud);
|
||||
|
||||
typedef struct k3MEventHandler {
|
||||
uint8_t ud[k3M_USERDATA_SIZE];
|
||||
k3MEventHandlerFunc callback;
|
||||
uint16_t code;
|
||||
} k3MEventHandler;
|
||||
|
||||
struct k3MObj {
|
||||
struct k3MObj *parent;
|
||||
|
||||
size_t childCount;
|
||||
struct k3MObj **children;
|
||||
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t w;
|
||||
int16_t h;
|
||||
|
||||
bool invisible, hovered, disabled;
|
||||
|
||||
k3MEventHandler *handlers;
|
||||
size_t handlerCount;
|
||||
};
|
||||
|
||||
#define k3MenuSetBounds(a, x, y, w, h) k3MenuSetBounds_((struct k3MObj*) (a), (x), (y), (w), (h))
|
||||
void k3MenuSetBounds_(struct k3MObj *this, int16_t x, int16_t y, int16_t w, int16_t h);
|
||||
|
||||
#define k3MRegisterEventHandler(a, c, cb, ud, udsz) k3MRegisterEventHandler_((struct k3MObj*) (a), (c), (cb), (ud), (udsz))
|
||||
int k3MRegisterEventHandler_(struct k3MObj *obj, uint16_t evcode, k3MEventHandlerFunc callback, uint8_t *ud, size_t udSize);
|
||||
|
||||
bool k3MEventSend(struct k3MEvent *ev);
|
||||
|
||||
int k3MRemoveChild(struct k3MObj *parent, struct k3MObj *child);
|
||||
void k3MAddChild(struct k3MObj *parent, struct k3MObj *child);
|
||||
|
||||
struct k3MLabel {
|
||||
struct k3MObj;
|
||||
|
||||
struct k3Font *font;
|
||||
float sz;
|
||||
char *txt;
|
||||
};
|
||||
struct k3MLabel *k3MLabel(struct k3Font *font, float sz, const char *txt);
|
||||
|
||||
struct k3MScreen {
|
||||
struct k3MObj;
|
||||
|
||||
struct k3MObj *keyboardFocus;
|
||||
};
|
||||
struct k3MScreen *k3MScreen();
|
||||
|
||||
struct k3MTextButton {
|
||||
struct k3MObj;
|
||||
|
||||
struct k3Font *font;
|
||||
float sz;
|
||||
char *txt;
|
||||
};
|
||||
struct k3MTextButton *k3MTextButton(struct k3Font *font, float sz, const char *txt);
|
||||
|
||||
struct k3MTextInput {
|
||||
struct k3MObj;
|
||||
|
||||
struct k3Font *font;
|
||||
float sz;
|
||||
|
||||
char *placeholder;
|
||||
|
||||
char *txt;
|
||||
};
|
||||
struct k3MTextInput *k3MTextInput(struct k3Font *font, float sz, const char *placeholder, const char *txt);
|
||||
Reference in New Issue
Block a user