texed bugfixes and qol improvements

isolation_bkp/dynres
Dominik Madarász 2021-05-15 22:09:25 +02:00
parent 7090a8601d
commit a42bdf1d3c
9 changed files with 1047 additions and 902 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

@ -22,6 +22,7 @@ static float zoom = 4.0f;
static Texture2D checker_tex; static Texture2D checker_tex;
static uint16_t old_screen_w; static uint16_t old_screen_w;
static uint16_t old_screen_h; static uint16_t old_screen_h;
static bool is_loading_prj = false;
#define TD_DEFAULT_IMG_WIDTH 64 #define TD_DEFAULT_IMG_WIDTH 64
#define TD_DEFAULT_IMG_HEIGHT 64 #define TD_DEFAULT_IMG_HEIGHT 64
@ -162,6 +163,7 @@ void texed_run(void) {
Image checkerboard = GenImageChecked(preview_rect.width, preview_rect.height, 16, 16, BLACK, ColorAlpha(GRAY, 0.2f)); Image checkerboard = GenImageChecked(preview_rect.width, preview_rect.height, 16, 16, BLACK, ColorAlpha(GRAY, 0.2f));
checker_tex = LoadTextureFromImage(checkerboard); checker_tex = LoadTextureFromImage(checkerboard);
UnloadImage(checkerboard); UnloadImage(checkerboard);
ctx.fileDialog = InitGuiFileDialog(420, 310, zpl_bprintf("%s/art", GetWorkingDirectory()), false);
} }
BeginDrawing(); BeginDrawing();
@ -206,6 +208,7 @@ void texed_destroy(void) {
} }
void texed_repaint_preview(void) { void texed_repaint_preview(void) {
if (is_loading_prj) return;
UnloadTexture(ctx.tex); UnloadTexture(ctx.tex);
texed_process_params(); texed_process_params();
texed_process_ops(); texed_process_ops();
@ -247,8 +250,6 @@ void texed_rem_op(int idx) {
zpl_mfree(ctx.ops[idx].params); zpl_mfree(ctx.ops[idx].params);
zpl_array_remove_at(ctx.ops, idx); zpl_array_remove_at(ctx.ops, idx);
if (idx == ctx.selected_op) { if (zpl_array_count(ctx.ops) > 0 && idx <= ctx.selected_op) ctx.selected_op -= 1;
if (idx > 0) ctx.selected_op -= 1;
}
texed_repaint_preview(); texed_repaint_preview();
} }

View File

@ -34,8 +34,9 @@ void texed_process_ops(void) {
op->params[3].i32); op->params[3].i32);
}break; }break;
case TOP_LOAD_IMAGE: { case TOP_LOAD_IMAGE: {
if (FileExists(op->params[0].str)) { char const *str = zpl_bprintf("art/%s", op->params[0].str);
Image img = LoadImage(op->params[0].str); if (FileExists(str)) {
Image img = LoadImage(str);
int x = op->params[1].i32; int x = op->params[1].i32;
int y = op->params[2].i32; int y = op->params[2].i32;
int w = op->params[3].i32; int w = op->params[3].i32;
@ -52,7 +53,7 @@ void texed_process_ops(void) {
UnloadImage(img); UnloadImage(img);
} else { } else {
zpl_printf("TOP_LOAD_IMAGE: src %s not found!\n", op->params[0].str); zpl_printf("TOP_LOAD_IMAGE: src %s not found!\n", str);
} }
}break; }break;
case TOP_DRAW_TEXT: { case TOP_DRAW_TEXT: {
@ -64,6 +65,7 @@ void texed_process_ops(void) {
ImageDrawText(&ctx.img, str, x, y, size, color); ImageDrawText(&ctx.img, str, x, y, size, color);
}break; }break;
case TOP_RESIZE_IMAGE: { case TOP_RESIZE_IMAGE: {
if (ctx.img.width == 0) break;
int w = op->params[0].i32; int w = op->params[0].i32;
int h = op->params[1].i32; int h = op->params[1].i32;
int mode = op->params[2].i32; int mode = op->params[2].i32;

View File

@ -48,7 +48,7 @@ static td_op default_ops[] = {
OP(TOP_LOAD_IMAGE), OP(TOP_LOAD_IMAGE),
.num_params = 6, .num_params = 6,
.params = (td_param[]) { .params = (td_param[]) {
PARAM(TPARAM_STRING, "src", "art/samples/test.png"), PARAM(TPARAM_STRING, "src", "samples/test.png"),
PARAM(TPARAM_COORD, "x", "0"), PARAM(TPARAM_COORD, "x", "0"),
PARAM(TPARAM_COORD, "y", "0"), PARAM(TPARAM_COORD, "y", "0"),
PARAM(TPARAM_COORD, "w", "-1"), PARAM(TPARAM_COORD, "w", "-1"),
@ -63,8 +63,8 @@ static td_op default_ops[] = {
PARAM(TPARAM_STRING, "text", "hello world"), PARAM(TPARAM_STRING, "text", "hello world"),
PARAM(TPARAM_COORD, "x", "0"), PARAM(TPARAM_COORD, "x", "0"),
PARAM(TPARAM_COORD, "y", "0"), PARAM(TPARAM_COORD, "y", "0"),
PARAM(TPARAM_INT, "size", "16"), PARAM(TPARAM_COORD, "size", "16"),
PARAM(TPARAM_COLOR, "color", "ffffffff"), PARAM(TPARAM_COLOR, "color", PARAM_DEF_COLOR),
} }
}, },
{ {

View File

@ -8,6 +8,7 @@
void texed_load(void) { void texed_load(void) {
assert(ctx.filepath); assert(ctx.filepath);
zpl_printf("Loading %s ...\n", ctx.filepath); zpl_printf("Loading %s ...\n", ctx.filepath);
is_loading_prj = true;
zpl_array_clear(ctx.ops); zpl_array_clear(ctx.ops);
uint32_t size = 0; uint32_t size = 0;
@ -63,6 +64,7 @@ void texed_load(void) {
assert(uc.return_code == CWP_RC_END_OF_INPUT); assert(uc.return_code == CWP_RC_END_OF_INPUT);
ctx.selected_op = selected_op; ctx.selected_op = selected_op;
is_loading_prj = false;
texed_repaint_preview(); texed_repaint_preview();
UnloadFileData(databuf); UnloadFileData(databuf);
} }

View File

@ -1,5 +1,7 @@
static inline static inline
void int_to_hex_color(uint32_t color, char *text); void int_to_hex_color(uint32_t color, char *text);
static inline
int GuiDropdownBoxEco(Rectangle bounds, char const *text, char const *caption, int *active, bool editMode);
void texed_draw_topbar(zpl_aabb2 r) { void texed_draw_topbar(zpl_aabb2 r) {
zpl_aabb2 zoom_ctrl_r = zpl_aabb2_cut_left(&r, 150.0f); zpl_aabb2 zoom_ctrl_r = zpl_aabb2_cut_left(&r, 150.0f);
@ -83,7 +85,6 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
is_add_op_dropbox_open = true; is_add_op_dropbox_open = true;
} }
GuiSetState(ctx.filepath ? GUI_STATE_NORMAL : GUI_STATE_DISABLED); GuiSetState(ctx.filepath ? GUI_STATE_NORMAL : GUI_STATE_DISABLED);
zpl_aabb2 export_code_r = zpl_aabb2_cut_left(&oplist_header, 120.0f); zpl_aabb2 export_code_r = zpl_aabb2_cut_left(&oplist_header, 120.0f);
@ -149,9 +150,13 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
GuiDrawText(ctx.ops[i].name, GetTextBounds(LABEL, list_text), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha)); GuiDrawText(ctx.ops[i].name, GetTextBounds(LABEL, list_text), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha));
} }
if (is_add_op_dropbox_open && GuiDropdownBox(aabb2_ray(add_op_r), add_op_list, &add_op_dropbox_selected, true)) { static int op_dropdown_state = 0;
if (is_add_op_dropbox_open && (op_dropdown_state = GuiDropdownBoxEco(aabb2_ray(add_op_r), add_op_list, "ADD OPERATION", &add_op_dropbox_selected, true)) > 0) {
is_add_op_dropbox_open = false; is_add_op_dropbox_open = false;
texed_add_op(add_op_dropbox_selected); if (op_dropdown_state < 2) {
texed_add_op(add_op_dropbox_selected);
}
} }
} }
@ -180,23 +185,33 @@ void texed_draw_props_pane(zpl_aabb2 r) {
GuiDrawText(zpl_bprintf("%s: ", p->name ? p->name : "prop"), GetTextBounds(LABEL, aabb2_ray(label_r)), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha)); GuiDrawText(zpl_bprintf("%s: ", p->name ? p->name : "prop"), GetTextBounds(LABEL, aabb2_ray(label_r)), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha));
static bool is_color_editing = false;
if (is_color_editing) GuiLock();
switch (p->kind) { switch (p->kind) {
case TPARAM_COLOR: { case TPARAM_COLOR: {
if (GuiTextBoxEx(aabb2_ray(tbox_r), p->str, 64, p->edit_mode)) { if (is_color_editing) GuiUnlock();
if (GuiTextBoxEx(aabb2_ray(tbox_r), p->str, 1000, p->edit_mode)) {
p->edit_mode = true; p->edit_mode = true;
is_color_editing = true;
} }
if (p->edit_mode) { if (p->edit_mode) {
zpl_aabb2 extra_r = zpl_aabb2_add_bottom(&tbox_r, prop_height); zpl_aabb2 extra_r = zpl_aabb2_add_bottom(&tbox_r, prop_height);
DrawRectangleRec(aabb2_ray(extra_r), GRAY);
zpl_aabb2 ok_r = zpl_aabb2_cut_left(&extra_r, 50.0f); zpl_aabb2 ok_r = zpl_aabb2_cut_left(&extra_r, 50.0f);
p->color = GuiColorPicker(aabb2_ray(extra_r), p->color); p->color = GuiColorPicker(aabb2_ray(extra_r), p->color);
if (GuiButton(aabb2_ray(ok_r), "OK")) { if (GuiButton(aabb2_ray(ok_r), "OK")) {
GuiUnlock();
p->edit_mode = false; p->edit_mode = false;
is_color_editing = false;
int_to_hex_color(ColorToInt(p->color), p->str); int_to_hex_color(ColorToInt(p->color), p->str);
texed_repaint_preview(); texed_repaint_preview();
} }
} }
if (is_color_editing) GuiLock();
}break; }break;
case TPARAM_COORD: { case TPARAM_COORD: {
if (GuiValueBox(aabb2_ray(tbox_r), NULL, &p->i32, INT32_MIN, INT32_MAX, p->edit_mode)) { if (GuiValueBox(aabb2_ray(tbox_r), NULL, &p->i32, INT32_MIN, INT32_MAX, p->edit_mode)) {
@ -209,7 +224,7 @@ void texed_draw_props_pane(zpl_aabb2 r) {
}; };
}break; }break;
default: { default: {
if (GuiTextBoxEx(aabb2_ray(tbox_r), p->str, 64, p->edit_mode)) { if (GuiTextBoxEx(aabb2_ray(tbox_r), p->str, 1000, p->edit_mode)) {
p->edit_mode = !p->edit_mode; p->edit_mode = !p->edit_mode;
if (!p->edit_mode) if (!p->edit_mode)
@ -217,6 +232,8 @@ void texed_draw_props_pane(zpl_aabb2 r) {
} }
}break; }break;
}; };
if (is_color_editing) GuiUnlock();
} }
} }
@ -242,3 +259,126 @@ void int_to_hex_color(uint32_t value, char *string) {
zpl_strrev(string); zpl_strrev(string);
} }
// Dropdown Box control
// NOTE: Returns mouse click
static inline
int GuiDropdownBoxEco(Rectangle bounds, char const *text, char const *caption, int *active, bool editMode)
{
GuiControlState state = guiState;
int itemSelected = *active;
int itemFocused = -1;
// Get substrings items from text (items pointers, lengths and count)
int itemsCount = 0;
const char **items = GuiTextSplit(text, &itemsCount, NULL);
Rectangle boundsOpen = bounds;
boundsOpen.height = (itemsCount + 1)*(bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_PADDING));
Rectangle itemBounds = bounds;
bool pressed = false; // Check mouse button pressed
// Update control
//--------------------------------------------------------------------
if ((state != GUI_STATE_DISABLED) && !guiLocked && (itemsCount > 1))
{
Vector2 mousePoint = GetMousePosition();
if (editMode)
{
state = GUI_STATE_PRESSED;
// Check if already selected item has been pressed again
if (CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true;
// Check focused and selected item
for (int i = 0; i < itemsCount; i++)
{
// Update item rectangle y position for next item
itemBounds.y += (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_PADDING));
if (CheckCollisionPointRec(mousePoint, itemBounds))
{
itemFocused = i;
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
{
itemSelected = i;
pressed = true; // Item selected, change to editMode = false
}
break;
}
}
itemBounds = bounds;
}
else
{
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
pressed = true;
state = GUI_STATE_PRESSED;
}
else state = GUI_STATE_FOCUSED;
}
}
}
//--------------------------------------------------------------------
// Draw control
//--------------------------------------------------------------------
if (editMode) GuiPanel(boundsOpen);
GuiDrawRectangle(bounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, BORDER + state*3)), guiAlpha), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, BASE + state*3)), guiAlpha));
GuiDrawText(caption, GetTextBounds(DEFAULT, bounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + state*3)), guiAlpha));
if (editMode)
{
// Draw visible items
for (int i = 0; i < itemsCount; i++)
{
// Update item rectangle y position for next item
itemBounds.y += (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_PADDING));
if (i == itemSelected)
{
GuiDrawRectangle(itemBounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, BORDER_COLOR_PRESSED)), guiAlpha), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, BASE_COLOR_PRESSED)), guiAlpha));
GuiDrawText(items[i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_PRESSED)), guiAlpha));
}
else if (i == itemFocused)
{
GuiDrawRectangle(itemBounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, BORDER_COLOR_FOCUSED)), guiAlpha), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, BASE_COLOR_FOCUSED)), guiAlpha));
GuiDrawText(items[i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_FOCUSED)), guiAlpha));
}
else GuiDrawText(items[i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_NORMAL)), guiAlpha));
}
}
// TODO: Avoid this function, use icon instead or 'v'
DrawTriangle(RAYGUI_CLITERAL(Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_PADDING), bounds.y + bounds.height/2 - 2 },
RAYGUI_CLITERAL(Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_PADDING) + 5, bounds.y + bounds.height/2 - 2 + 5 },
RAYGUI_CLITERAL(Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_PADDING) + 10, bounds.y + bounds.height/2 - 2 },
Fade(GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3))), guiAlpha));
//GuiDrawText("v", RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_PADDING), bounds.y + bounds.height/2 - 2, 10, 10 },
// GUI_TEXT_ALIGN_CENTER, Fade(GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3))), guiAlpha));
//--------------------------------------------------------------------
Vector2 mousePoint = GetMousePosition();
// Check if mouse has been pressed or released outside limits
if (!CheckCollisionPointRec(mousePoint, boundsOpen))
{
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) {
return 2;
}
}
*active = itemSelected;
return pressed;
}

View File

@ -640,7 +640,7 @@ RAYGUIDEF bool GuiTextBoxEx(Rectangle bounds, char *text, int textSize, bool edi
else if (IsKeyPressed(KEY_ENTER)) pressed = true; else if (IsKeyPressed(KEY_ENTER)) pressed = true;
else else
{ {
int key = GetKeyPressed(); int key = GetCharPressed();
if ((key >= 32) && ((guiTextBoxState.cursor + 1) < textSize)) if ((key >= 32) && ((guiTextBoxState.cursor + 1) < textSize))
{ {
if ((guiTextBoxState.select != -1) && (guiTextBoxState.select != guiTextBoxState.cursor)) if ((guiTextBoxState.select != -1) && (guiTextBoxState.select != guiTextBoxState.cursor))