Committing before major refactor.
This commit is contained in:
@ -13,7 +13,7 @@
|
|||||||
/** Representation of a Label UI Element */
|
/** Representation of a Label UI Element */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
font_t *font;
|
font_t *font;
|
||||||
float x, y, z;
|
float x, y;
|
||||||
float fontSize;
|
float fontSize;
|
||||||
fonttextinfo_t info;
|
fonttextinfo_t info;
|
||||||
primitive_t primitive;
|
primitive_t primitive;
|
||||||
|
@ -24,7 +24,6 @@ typedef struct {
|
|||||||
int32_t y;
|
int32_t y;
|
||||||
int32_t width;
|
int32_t width;
|
||||||
int32_t height;
|
int32_t height;
|
||||||
int32_t i;
|
|
||||||
} menuitem_t;
|
} menuitem_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
24
include/dawn/ui/menulist.h
Normal file
24
include/dawn/ui/menulist.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "../libs.h"
|
||||||
|
#include "label.h"
|
||||||
|
#include "menu.h"
|
||||||
|
|
||||||
|
/** Maximum number of items that the list supports */
|
||||||
|
#define MENULIST_ITEMS_MAX 32
|
||||||
|
|
||||||
|
/** Representation of a menu list, a menu with multiple menu items. */
|
||||||
|
typedef struct {
|
||||||
|
float x, y;
|
||||||
|
char *items[MENULIST_ITEMS_MAX];
|
||||||
|
label_t labels[MENULIST_ITEMS_MAX];
|
||||||
|
menu_t menu;
|
||||||
|
uint8_t count;
|
||||||
|
uint8_t selected;
|
||||||
|
} menulist_t;
|
@ -10,7 +10,6 @@
|
|||||||
void labelInit(label_t *label) {
|
void labelInit(label_t *label) {
|
||||||
label->x = 0;
|
label->x = 0;
|
||||||
label->y = 0;
|
label->y = 0;
|
||||||
label->z = 0;
|
|
||||||
label->fontSize = FONT_SIZE_DEFAULT;
|
label->fontSize = FONT_SIZE_DEFAULT;
|
||||||
label->font = NULL;
|
label->font = NULL;
|
||||||
label->primitive.verticeCount = 0;
|
label->primitive.verticeCount = 0;
|
||||||
@ -29,7 +28,7 @@ void labelSetText(label_t *label, font_t *font, char *text) {
|
|||||||
|
|
||||||
void labelRender(label_t *label, shader_t *shader) {
|
void labelRender(label_t *label, shader_t *shader) {
|
||||||
if(label->primitive.verticeCount == 0) return;
|
if(label->primitive.verticeCount == 0) return;
|
||||||
shaderUsePosition(shader, label->x, label->y, label->z, 0, 0, 0);
|
shaderUsePosition(shader, label->x,label->y,0, 0,0,0);
|
||||||
shaderUseTexture(shader, &label->font->texture);
|
shaderUseTexture(shader, &label->font->texture);
|
||||||
primitiveDraw(&label->primitive, 0, -1);
|
primitiveDraw(&label->primitive, 0, -1);
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,12 @@ void menuInit(menu_t *menu) {
|
|||||||
menu->selected = 0;
|
menu->selected = 0;
|
||||||
menu->cursorX = 0;
|
menu->cursorX = 0;
|
||||||
menu->cursorY = 0;
|
menu->cursorY = 0;
|
||||||
|
|
||||||
for(i = 0; i < MENU_ITEMS_MAX; i++) menu->items[i].i = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void menuUpdate(menu_t *menu, engine_t *engine) {
|
void menuUpdate(menu_t *menu, engine_t *engine) {
|
||||||
menuitem_t *current;
|
menuitem_t *current;
|
||||||
menuitem_t *item;
|
menuitem_t *item;
|
||||||
int32_t x, y, i;
|
int32_t x, y, i, j;
|
||||||
|
|
||||||
current = menu->items + menu->selected;
|
current = menu->items + menu->selected;
|
||||||
|
|
||||||
@ -58,31 +56,29 @@ void menuUpdate(menu_t *menu, engine_t *engine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the item selected
|
// Get the item selected
|
||||||
int32_t targetIndex = -1;
|
j = -1;
|
||||||
for(i = 0; i < menu->itemCount; i++) {
|
for(i = 0; i < menu->itemCount; i++) {
|
||||||
if(i == menu->selected) continue;
|
if(i == menu->selected) continue;
|
||||||
item = menu->items + i;
|
item = menu->items + i;
|
||||||
|
|
||||||
if(
|
if(
|
||||||
item->i == -1 ||
|
|
||||||
item->x > menu->cursorX || (item->x+item->width-1) < menu->cursorX ||
|
item->x > menu->cursorX || (item->x+item->width-1) < menu->cursorX ||
|
||||||
item->y > menu->cursorY || (item->y+item->height-1) < menu->cursorY
|
item->y > menu->cursorY || (item->y+item->height-1) < menu->cursorY
|
||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
targetIndex = i;
|
j = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Was a target found?
|
// Was a target found?
|
||||||
if(targetIndex == -1) return;
|
if(j == -1) return;
|
||||||
menu->selected = targetIndex;
|
menu->selected = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
menuitem_t * menuAdd(menu_t *menu) {
|
menuitem_t * menuAdd(menu_t *menu) {
|
||||||
menuitem_t *item = menu->items + menu->itemCount;
|
menuitem_t *item = menu->items + menu->itemCount;
|
||||||
|
|
||||||
item->i = menu->itemCount;
|
|
||||||
item->x = 0;
|
item->x = 0;
|
||||||
item->y = 0;
|
item->y = 0;
|
||||||
item->width = 1;
|
item->width = 1;
|
||||||
|
12
src/ui/menulist.c
Normal file
12
src/ui/menulist.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "menulist.h"
|
||||||
|
|
||||||
|
void menuListInit(menulist_t *list) {
|
||||||
|
|
||||||
|
}
|
9
src/ui/menulist.h
Normal file
9
src/ui/menulist.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <dawn/dawn.h>
|
Reference in New Issue
Block a user