- [NEW] menu i menu::popup

- [WIP] toolbar
- [WIP] treeview
This commit is contained in:
2025-11-17 22:31:48 +01:00
parent 3ed64a471a
commit 8028d0533b
7 changed files with 186 additions and 35 deletions

View File

@@ -2,6 +2,8 @@
#include "japi/game.h" #include "japi/game.h"
#include "japi/font.h" #include "japi/font.h"
#include "menu.h" #include "menu.h"
#include "toolbar.h"
#include "treeview.h"
bool loop(); bool loop();
@@ -10,15 +12,17 @@ void game::init()
draw::init("DILEMMAKER v0.1", 800, 600); draw::init("DILEMMAKER v0.1", 800, 600);
game::setState(loop); game::setState(loop);
font::load("font/8bithud"); font::load("font/8bithud");
draw::cls(0x00000000);
} }
bool loop() bool loop()
{ {
draw::cls(0x00000000);
menu::start(); menu::start();
if (menu::option("FILE")) { if (menu::option("FILE")) {
menu::popup::start(); menu::popup::start();
menu::popup::option("New...");
menu::popup::option("Load...");
menu::popup::option("Save...");
menu::popup::end(); menu::popup::end();
} }
if (menu::option("EDIT")) { if (menu::option("EDIT")) {
@@ -33,6 +37,24 @@ bool loop()
menu::popup::start(); menu::popup::start();
menu::popup::end(); menu::popup::end();
} }
if (menu::end()) { draw::render(); return true; }
toolbar::start();
treeview::start();
if (treeview::option("room01", 0)) {
treeview::option("abad", 1);
treeview::option("Jailer", 1);
}
if (treeview::option("room02", 0)) {
treeview::option("abad", 1);
treeview::option("Jailer", 1);
}
if (treeview::option("room03", 0)) {
treeview::option("abad", 1);
treeview::option("Jailer", 1);
}
treeview::end();
/*x1 += 6; x2 = x1 + font::len("FILE")+6; /*x1 += 6; x2 = x1 + font::len("FILE")+6;
font::print("FILE", x1, 5); x1=x2; font::print("FILE", x1, 5); x1=x2;

View File

@@ -2,17 +2,71 @@
#include "japi/input.h" #include "japi/input.h"
#include "japi/draw.h" #include "japi/draw.h"
#include "japi/font.h" #include "japi/font.h"
#include <stdio.h>
namespace menu namespace menu
{ {
int x1, x2, m; int x1, x2, m;
int menu_shown = -1; int menu_shown = -1;
bool must_stop = false;
bool changing = false;
namespace popup
{
int x=0, y=0, width=0, height=0;
void start()
{
popup::x = x1-8;
draw::setColor(0xff3c3c3c);
draw::fillrect(popup::x,24,popup::width,popup::height);
int mx = input::mouseX();
int my = input::mouseY();
if (mx>=popup::x && my>=24 && mx<popup::x+popup::width && my<24+popup::height) {
if (input::mouseClk(input::mouse::button::left)) {
input::mouseDiscard();
}
}
popup::y = 24;
}
bool option(const char* label)
{
bool result = false;
int mx = input::mouseX();
int my = input::mouseY();
if (mx>=popup::x && my>=popup::y && mx<popup::x+popup::width && my<popup::y+24) {
draw::setColor(0xff464646);
draw::fillrect(popup::x, popup::y, popup::width, 24);
if (input::mouseClk(input::mouse::button::left)) {
input::mouseDiscard();
result = true;
}
}
font::print(label, popup::x+8, popup::y+8);
if (popup::height < popup::y) popup::height = popup::y;
popup::y += 24;
const int option_width = font::len(label);
if (popup::width < option_width+16) popup::width = option_width+16;
return result;
}
void end()
{
if (input::mouseClk(input::mouse::button::left)) {
input::mouseDiscard();
menu_shown = -1;
}
}
}
void start() void start()
{ {
draw::setColor(0xff3c3c3c); draw::setColor(0xff3c3c3c);
draw::fillrect(0,0,draw::getWindowSize().x,24); draw::fillrect(0,0,draw::getWindowSize().x,24);
x1=0; x2=0; m=-1; x1=0; x2=0; m=-1;
menu::must_stop = menu::changing = false;
} }
bool option(const char* label) bool option(const char* label)
@@ -21,48 +75,35 @@ namespace menu
x1 = x2 + 8; x2 = x1 + font::len(label)+8; x1 = x2 + 8; x2 = x1 + font::len(label)+8;
int mx = input::mouseX(); int mx = input::mouseX();
int my = input::mouseY(); int my = input::mouseY();
const int old_menu = menu_shown;
if (mx>=x1 && my>=0 && mx<x2 && my<24) { if (mx>=x1 && my>=0 && mx<x2 && my<24) {
draw::setColor(0xff464646); draw::setColor(0xff565656);
draw::fillrect(x1-8, 0, x2-x1+8, 24); draw::fillrect(x1-8, 0, x2-x1+8, 24);
if (input::mouseClk(input::mouse::button::left)) { if (input::mouseClk(input::mouse::button::left)) {
input::mouseDiscard(); input::mouseDiscard();
menu_shown = (menu_shown == m) ? -1 : m; menu_shown = (menu_shown == m) ? -1 : m;
} else { } else {
if (menu_shown != -1) menu_shown = m; if (menu_shown != -1) {
} if (menu_shown != m) menu::changing = true;
} menu_shown = m;
font::print(label, x1, 9);
return menu_shown==m;
}
namespace popup
{
void start()
{
draw::setColor(0xff3c3c3c);
draw::fillrect(x1-8,24,200,200);
int mx = input::mouseX();
int my = input::mouseY();
if (mx>=x1-8 && my>=24 && mx<x1-8+200 && my<24+200) {
if (input::mouseClk(input::mouse::button::left)) {
input::mouseDiscard();
} }
} }
} if (menu_shown != -1 && menu_shown != old_menu) {
popup::width = 100;
bool option(const char* label) popup::height = 0;
{
return false;
}
void end()
{
if (input::mouseClk(input::mouse::button::left)) {
menu_shown = -1;
} }
} else if (menu_shown==m) {
draw::setColor(0xff565656);
draw::fillrect(x1-8, 0, x2-x1+8, 24);
} }
font::print(label, x1, 9);
//if (menu_shown==m) menu::must_stop = true;
return (menu_shown==m);
} }
bool end()
{
return (menu::menu_shown != -1) && !menu::changing;
}
} }

View File

@@ -4,6 +4,7 @@ namespace menu
{ {
void start(); void start();
bool option(const char* label); bool option(const char* label);
bool end();
namespace popup namespace popup
{ {

26
source/toolbar.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "toolbar.h"
#include "japi/draw.h"
namespace toolbar
{
const int top = 24;
void start()
{
draw::setColor(0xff3c3c3c);
draw::fillrect(0,top,draw::getWindowSize().x,24);
draw::setColor(0xff565656);
draw::line(0, top, draw::getWindowSize().x, top);
}
bool button(SDL_Texture* surf, const int sx, const int sy)
{
}
bool pushbutton(SDL_Texture* surf, const int sx, const int sy, const bool pushed)
{
}
}

9
source/toolbar.h Normal file
View File

@@ -0,0 +1,9 @@
#pragma once
#include <SDL3/SDL.h>
namespace toolbar
{
void start();
bool button(SDL_Texture* surf, const int sx, const int sy);
bool pushbutton(SDL_Texture* surf, const int sx, const int sy, const bool pushed);
}

44
source/treeview.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include "treeview.h"
#include "japi/draw.h"
#include "japi/font.h"
#include "japi/input.h"
namespace treeview
{
int width = 200;
int scroll = 0;
int current = -1;
int selected = -1;
void start()
{
draw::setColor(0xff181818);
draw::fillrect(0,48,treeview::width, draw::getWindowSize().y-48);
current = 0;
}
bool option(const char* label, const int level)
{
int mx = input::mouseX();
int my = input::mouseY();
const int opt_y = (48+current*24);
if (mx>=0 && my>=opt_y && mx<treeview::width && my<opt_y+24) {
if (input::mouseClk(input::mouse::button::left)) {
input::mouseDiscard();
selected = current;
}
draw::setColor(selected==current ? 0xff37373d : 0xff2a2d2e);
draw::fillrect(0, opt_y, treeview::width, 24);
}
font::print(label, 8+16*level, opt_y+8);
current++;
return selected==current;
}
void end()
{
}
}

8
source/treeview.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
namespace treeview
{
void start();
bool option(const char* label, const int level);
void end();
}