fix ctx.selected_op on swap
parent
8623c18127
commit
276bd21b65
BIN
art/demo.ecotex
BIN
art/demo.ecotex
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 9.1 KiB |
|
@ -13,6 +13,9 @@
|
|||
#define GUI_FILE_DIALOG_IMPLEMENTATION
|
||||
#include "gui_file_dialog.h"
|
||||
|
||||
#define GUI_TEXTBOX_EXTENDED_IMPLEMENTATION
|
||||
#include "gui_textbox_extended.h"
|
||||
|
||||
static uint16_t screenWidth = 1280;
|
||||
static uint16_t screenHeight = 720;
|
||||
static float zoom = 4.0f;
|
||||
|
@ -24,6 +27,7 @@ static float zoom = 4.0f;
|
|||
|
||||
typedef enum {
|
||||
TPARAM_FLOAT,
|
||||
TPARAM_COORD,
|
||||
TPARAM_INT,
|
||||
TPARAM_COLOR,
|
||||
TPARAM_STRING,
|
||||
|
@ -52,6 +56,7 @@ typedef enum {
|
|||
TOP_DRAW_LINE,
|
||||
TOP_DITHER,
|
||||
TOP_LOAD_IMAGE,
|
||||
TOP_DRAW_TEXT,
|
||||
|
||||
TOP_FORCE_UINT8 = UINT8_MAX
|
||||
} td_op_kind;
|
||||
|
@ -126,6 +131,8 @@ void texed_run(void) {
|
|||
|
||||
texed_new(TD_DEFAULT_IMG_WIDTH, TD_DEFAULT_IMG_HEIGHT);
|
||||
|
||||
GuiSetStyle(TEXTBOX, TEXT_COLOR_NORMAL, ColorToInt(RAYWHITE));
|
||||
|
||||
zpl_aabb2 screen = {
|
||||
.min = (zpl_vec2) {.x = 0.0f, .y = 0.0f},
|
||||
.max = (zpl_vec2) {.x = screenWidth, .y = screenHeight},
|
||||
|
@ -222,7 +229,7 @@ void texed_swp_op(int idx, int idx2) {
|
|||
td_op tmp = ctx.ops[idx2];
|
||||
ctx.ops[idx2] = ctx.ops[idx];
|
||||
ctx.ops[idx] = tmp;
|
||||
|
||||
ctx.selected_op = idx2;
|
||||
texed_repaint_preview();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,14 @@ void texed_process_ops(void) {
|
|||
zpl_printf("TOP_LOAD_IMAGE: src %s not found!\n", op->params[0].str);
|
||||
}
|
||||
}break;
|
||||
case TOP_DRAW_TEXT: {
|
||||
char const *str = op->params[0].str;
|
||||
int x = op->params[1].i32;
|
||||
int y = op->params[2].i32;
|
||||
int size = op->params[3].i32;
|
||||
Color color = op->params[4].color;
|
||||
ImageDrawText(&ctx.img, str, x, y, size, color);
|
||||
}break;
|
||||
default: {
|
||||
zpl_printf("%s\n", "unsupported op!");
|
||||
}break;
|
||||
|
@ -74,7 +82,10 @@ void texed_process_params(void) {
|
|||
p->flt = (float)zpl_str_to_f64(p->str, NULL);
|
||||
}break;
|
||||
case TPARAM_INT: {
|
||||
p->u32 = (int)zpl_str_to_i64(p->str, NULL, 10);
|
||||
p->u32 = (uint32_t)zpl_str_to_i64(p->str, NULL, 10);
|
||||
}break;
|
||||
case TPARAM_COORD: {
|
||||
p->i32 = (int32_t)zpl_str_to_i64(p->str, NULL, 10);
|
||||
}break;
|
||||
case TPARAM_COLOR: {
|
||||
uint32_t color = (uint32_t)zpl_str_to_u64(p->str, NULL, 16);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#define PARAM(k,n,v) { .kind = k, .name = n, .str = v }
|
||||
#define PARAM_DEF_COLOR "000000ff"
|
||||
|
||||
static td_op default_ops[] = {
|
||||
{
|
||||
|
@ -13,22 +14,22 @@ static td_op default_ops[] = {
|
|||
OP(TOP_DRAW_RECT),
|
||||
.num_params = 5,
|
||||
.params = (td_param[]) {
|
||||
PARAM(TPARAM_INT, "x", "0"),
|
||||
PARAM(TPARAM_INT, "y", "0"),
|
||||
PARAM(TPARAM_INT, "w", "10"),
|
||||
PARAM(TPARAM_INT, "h", "10"),
|
||||
PARAM(TPARAM_COLOR, "color", "0"),
|
||||
PARAM(TPARAM_COORD, "x", "0"),
|
||||
PARAM(TPARAM_COORD, "y", "0"),
|
||||
PARAM(TPARAM_COORD, "w", "10"),
|
||||
PARAM(TPARAM_COORD, "h", "10"),
|
||||
PARAM(TPARAM_COLOR, "color", PARAM_DEF_COLOR),
|
||||
}
|
||||
},
|
||||
{
|
||||
OP(TOP_DRAW_LINE),
|
||||
.num_params = 5,
|
||||
.params = (td_param[]) {
|
||||
PARAM(TPARAM_INT, "x1", "0"),
|
||||
PARAM(TPARAM_INT, "y1", "0"),
|
||||
PARAM(TPARAM_INT, "x2", "64"),
|
||||
PARAM(TPARAM_INT, "y2", "64"),
|
||||
PARAM(TPARAM_COLOR, "color", "0"),
|
||||
PARAM(TPARAM_COORD, "x1", "0"),
|
||||
PARAM(TPARAM_COORD, "y1", "0"),
|
||||
PARAM(TPARAM_COORD, "x2", "64"),
|
||||
PARAM(TPARAM_COORD, "y2", "64"),
|
||||
PARAM(TPARAM_COLOR, "color", PARAM_DEF_COLOR),
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -45,17 +46,28 @@ static td_op default_ops[] = {
|
|||
OP(TOP_LOAD_IMAGE),
|
||||
.num_params = 6,
|
||||
.params = (td_param[]) {
|
||||
PARAM(TPARAM_STRING, "src", "art/natives/test.png"),
|
||||
PARAM(TPARAM_INT, "x", "0"),
|
||||
PARAM(TPARAM_INT, "y", "0"),
|
||||
PARAM(TPARAM_INT, "w", "-1"),
|
||||
PARAM(TPARAM_INT, "h", "-1"),
|
||||
PARAM(TPARAM_STRING, "src", "art/samples/test.png"),
|
||||
PARAM(TPARAM_COORD, "x", "0"),
|
||||
PARAM(TPARAM_COORD, "y", "0"),
|
||||
PARAM(TPARAM_COORD, "w", "-1"),
|
||||
PARAM(TPARAM_COORD, "h", "-1"),
|
||||
PARAM(TPARAM_COLOR, "tint", "ffffffff"),
|
||||
}
|
||||
},
|
||||
{
|
||||
OP(TOP_DRAW_TEXT),
|
||||
.num_params = 5,
|
||||
.params = (td_param[]) {
|
||||
PARAM(TPARAM_STRING, "text", "hello world"),
|
||||
PARAM(TPARAM_COORD, "x", "0"),
|
||||
PARAM(TPARAM_COORD, "y", "0"),
|
||||
PARAM(TPARAM_INT, "size", "16"),
|
||||
PARAM(TPARAM_COLOR, "color", "ffffffff"),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// NOTE(zaklaus): IMPORTANT !! keep these in sync
|
||||
static char const *add_op_list = "CLEAR SOLID;DRAW RECTANGLE;PLOT LINE;DITHER;LOAD IMAGE";
|
||||
static char const *add_op_list = "CLEAR SOLID;DRAW RECTANGLE;PLOT LINE;DITHER;LOAD IMAGE;DRAW TEXT";
|
||||
|
||||
#define DEF_OPS_LEN (int)(sizeof(default_ops) / (sizeof(default_ops[0])))
|
||||
|
|
|
@ -38,13 +38,12 @@ void texed_load(void) {
|
|||
int parmarrsize = (int)uc.item.as.array.size;
|
||||
for (int j = 0; j < parmarrsize; j += 1) {
|
||||
td_param *p = &op->params[j];
|
||||
UNPACK(CWP_ITEM_POSITIVE_INTEGER);
|
||||
p->kind = (td_param_kind)uc.item.as.u64;
|
||||
UNPACK(CWP_ITEM_STR);
|
||||
zpl_memcopy(p->str, uc.item.as.str.start, uc.item.as.str.length);
|
||||
|
||||
// NOTE(zaklaus): fix up other metadata
|
||||
p->name = default_ops[kind].params[j].name;
|
||||
p->kind = default_ops[kind].params[j].kind;;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +76,6 @@ void texed_save(void) {
|
|||
cw_pack_array_size(&pc, op->num_params);
|
||||
for (int j = 0; j < op->num_params; j += 1) {
|
||||
td_param *p = &op->params[j];
|
||||
cw_pack_unsigned(&pc, p->kind);
|
||||
cw_pack_str(&pc, p->str, zpl_strlen(p->str));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ void texed_draw_props_pane(zpl_aabb2 r) {
|
|||
|
||||
switch (p->kind) {
|
||||
case TPARAM_COLOR: {
|
||||
if (GuiTextBox(aabb2_ray(tbox_r), p->str, 64, p->edit_mode)) {
|
||||
if (GuiTextBoxEx(aabb2_ray(tbox_r), p->str, 64, p->edit_mode)) {
|
||||
p->edit_mode = true;
|
||||
}
|
||||
|
||||
|
@ -198,9 +198,18 @@ void texed_draw_props_pane(zpl_aabb2 r) {
|
|||
}
|
||||
}
|
||||
}break;
|
||||
case TPARAM_COORD: {
|
||||
if (GuiValueBox(aabb2_ray(tbox_r), NULL, &p->i32, INT32_MIN, INT32_MAX, p->edit_mode)) {
|
||||
p->edit_mode = !p->edit_mode;
|
||||
|
||||
if (!p->edit_mode) {
|
||||
sprintf(p->str, "%d", p->i32);
|
||||
texed_repaint_preview();
|
||||
}
|
||||
};
|
||||
}break;
|
||||
default: {
|
||||
if (GuiTextBox(aabb2_ray(tbox_r), p->str, 64, p->edit_mode)) {
|
||||
if (GuiTextBoxEx(aabb2_ray(tbox_r), p->str, 64, p->edit_mode)) {
|
||||
p->edit_mode = !p->edit_mode;
|
||||
|
||||
if (!p->edit_mode)
|
||||
|
|
|
@ -53,30 +53,30 @@ typedef struct GuiTextBoxState {
|
|||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
RAYGUIDEF void GuiTextBoxSetActive(Rectangle bounds); // Sets the active textbox
|
||||
RAYGUIDEF Rectangle GuiTextBoxGetActive(void); // Get bounds of active textbox
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
RAYGUIDEF void GuiTextBoxSetActive(Rectangle bounds); // Sets the active textbox
|
||||
RAYGUIDEF Rectangle GuiTextBoxGetActive(void); // Get bounds of active textbox
|
||||
|
||||
RAYGUIDEF void GuiTextBoxSetCursor(int cursor); // Set cursor position of active textbox
|
||||
RAYGUIDEF int GuiTextBoxGetCursor(void); // Get cursor position of active textbox
|
||||
RAYGUIDEF void GuiTextBoxSetCursor(int cursor); // Set cursor position of active textbox
|
||||
RAYGUIDEF int GuiTextBoxGetCursor(void); // Get cursor position of active textbox
|
||||
|
||||
RAYGUIDEF void GuiTextBoxSetSelection(int start, int length); // Set selection of active textbox
|
||||
RAYGUIDEF Vector2 GuiTextBoxGetSelection(void); // Get selection of active textbox (x - selection start y - selection length)
|
||||
RAYGUIDEF void GuiTextBoxSetSelection(int start, int length); // Set selection of active textbox
|
||||
RAYGUIDEF Vector2 GuiTextBoxGetSelection(void); // Get selection of active textbox (x - selection start y - selection length)
|
||||
|
||||
RAYGUIDEF bool GuiTextBoxIsActive(Rectangle bounds); // Returns true if a textbox control with specified `bounds` is the active textbox
|
||||
RAYGUIDEF GuiTextBoxState GuiTextBoxGetState(void); // Get state for the active textbox
|
||||
RAYGUIDEF void GuiTextBoxSetState(GuiTextBoxState state); // Set state for the active textbox (state must be valid else things will break)
|
||||
RAYGUIDEF bool GuiTextBoxIsActive(Rectangle bounds); // Returns true if a textbox control with specified `bounds` is the active textbox
|
||||
RAYGUIDEF GuiTextBoxState GuiTextBoxGetState(void); // Get state for the active textbox
|
||||
RAYGUIDEF void GuiTextBoxSetState(GuiTextBoxState state); // Set state for the active textbox (state must be valid else things will break)
|
||||
|
||||
RAYGUIDEF void GuiTextBoxSelectAll(const char *text); // Select all characters in the active textbox (same as pressing `CTRL` + `A`)
|
||||
RAYGUIDEF void GuiTextBoxCopy(const char *text); // Copy selected text to clipboard from the active textbox (same as pressing `CTRL` + `C`)
|
||||
RAYGUIDEF void GuiTextBoxPaste(char *text, int textSize); // Paste text from clipboard into the textbox (same as pressing `CTRL` + `V`)
|
||||
RAYGUIDEF void GuiTextBoxCut(char *text); // Cut selected text in the active textbox and copy it to clipboard (same as pressing `CTRL` + `X`)
|
||||
RAYGUIDEF int GuiTextBoxDelete(char *text, int length, bool before); // Deletes a character or selection before from the active textbox (depending on `before`). Returns bytes deleted.
|
||||
RAYGUIDEF int GuiTextBoxGetByteIndex(const char *text, int start, int from, int to); // Get the byte index for a character starting at position `from` with index `start` until position `to`.
|
||||
RAYGUIDEF void GuiTextBoxSelectAll(const char *text); // Select all characters in the active textbox (same as pressing `CTRL` + `A`)
|
||||
RAYGUIDEF void GuiTextBoxCopy(const char *text); // Copy selected text to clipboard from the active textbox (same as pressing `CTRL` + `C`)
|
||||
RAYGUIDEF void GuiTextBoxPaste(char *text, int textSize); // Paste text from clipboard into the textbox (same as pressing `CTRL` + `V`)
|
||||
RAYGUIDEF void GuiTextBoxCut(char *text); // Cut selected text in the active textbox and copy it to clipboard (same as pressing `CTRL` + `X`)
|
||||
RAYGUIDEF int GuiTextBoxDelete(char *text, int length, bool before); // Deletes a character or selection before from the active textbox (depending on `before`). Returns bytes deleted.
|
||||
RAYGUIDEF int GuiTextBoxGetByteIndex(const char *text, int start, int from, int to); // Get the byte index for a character starting at position `from` with index `start` until position `to`.
|
||||
|
||||
RAYGUIDEF bool GuiTextBoxEx(Rectangle bounds, char *text, int textSize, bool editMode);
|
||||
RAYGUIDEF bool GuiTextBoxEx(Rectangle bounds, char *text, int textSize, bool editMode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ RAYGUIDEF int GuiTextBoxDelete(char *text, int length, bool before)
|
|||
else
|
||||
{
|
||||
// Delete character after cursor
|
||||
if (guiTextBoxState.cursor + 1 <= GuiCountCodepointsUntilNewline(text))
|
||||
if (guiTextBoxState.cursor + 1 <= (int)GuiCountCodepointsUntilNewline(text))
|
||||
{
|
||||
startIdx = GuiTextBoxGetByteIndex(text, 0, 0, guiTextBoxState.cursor);
|
||||
endIdx = GuiTextBoxGetByteIndex(text, 0, 0, guiTextBoxState.cursor+1);
|
||||
|
@ -401,7 +401,7 @@ RAYGUIDEF void GuiTextBoxCut(char* text)
|
|||
RAYGUIDEF bool GuiTextBoxEx(Rectangle bounds, char *text, int textSize, bool editMode)
|
||||
{
|
||||
// Define the cursor movement/selection speed when movement keys are held/pressed
|
||||
#define TEXTBOX_CURSOR_COOLDOWN 5
|
||||
#define TEXTBOX_CURSOR_COOLDOWN 5
|
||||
|
||||
static int framesCounter = 0; // Required for blinking cursor
|
||||
|
||||
|
|
Loading…
Reference in New Issue