/*
GameEngine and Editor
by John Ryland
Copyright (c) 2023
*/
////////////////////////////////////////////////////////////////////////////////////
// Editor UI
#include <stdio.h>
#include "Application.h"
#include "NkAssets.h"
#include "NkOpenGLRenderDevice.h"
#include "NkWindow.h"
#include "Image.h"
using namespace GameEngine;
FontDesc fontList[] =
{
{ "resources/Roboto-Regular.ttf", 14.0f },
{ "resources/Roboto-Regular.ttf", 18.0f },
{ "resources/Roboto-Regular.ttf", 20.0f },
{ "resources/Roboto-Regular.ttf", 22.0f },
};
ImageDesc imageList[] =
{
{ "resources/unchecked.png" },
{ "resources/checked.png" },
{ "resources/rocket.png" },
{ "resources/cloud.png" },
{ "resources/pen.png" },
{ "resources/play.png" },
{ "resources/pause.png" },
{ "resources/stop.png" },
{ "resources/next.png" },
{ "resources/prev.png" },
{ "resources/tools.png" },
{ "resources/directory.png" },
{ "resources/copy.png" },
{ "resources/export.png" },
{ "resources/delete.png" },
{ "resources/edit.png" },
{ "resources/home.png" },
{ "resources/phone.png" },
{ "resources/plane.png" },
{ "resources/wifi.png" },
{ "resources/settings.png" },
{ "resources/volume.png" },
{ "resources/image0.png" },
{ "resources/image1.png" },
{ "resources/image2.png" },
{ "resources/image3.png" },
{ "resources/image4.png" },
{ "resources/image5.png" },
{ "resources/image6.png" },
{ "resources/image7.png" },
{ "resources/image8.png" },
{ "resources/image9.png" }
};
static
void grid_demo(struct nk_context *ctx, Assets& assets)
{
static char text[3][64];
static int text_len[3];
static const char *items[] = {"Item 0","item 1","item 2"};
static int selected_item = 0;
static int check = 1;
auto font_14 = &fontList[0].font->handle;
auto font_18 = &fontList[1].font->handle;
auto font_20 = &fontList[2].font->handle;
int i;
nk_style_set_font(ctx, font_20);
if (nk_begin(ctx, "Grid Demo", nk_rect(600, 350, 275, 250),
NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|
NK_WINDOW_NO_SCROLLBAR))
{
nk_style_set_font(ctx, font_18);
nk_layout_row_dynamic(ctx, 30, 2);
nk_label(ctx, "Floating point:", NK_TEXT_RIGHT);
nk_edit_string(ctx, NK_EDIT_FIELD, text[0], &text_len[0], 64, nk_filter_float);
nk_label(ctx, "Hexadecimal:", NK_TEXT_RIGHT);
nk_edit_string(ctx, NK_EDIT_FIELD, text[1], &text_len[1], 64, nk_filter_hex);
nk_label(ctx, "Binary:", NK_TEXT_RIGHT);
nk_edit_string(ctx, NK_EDIT_FIELD, text[2], &text_len[2], 64, nk_filter_binary);
nk_label(ctx, "Checkbox:", NK_TEXT_RIGHT);
nk_checkbox_label(ctx, "Check me", &check);
nk_label(ctx, "Combobox:", NK_TEXT_RIGHT);
if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) {
nk_layout_row_dynamic(ctx, 25, 1);
for (i = 0; i < 3; ++i)
if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT))
selected_item = i;
nk_combo_end(ctx);
}
}
nk_end(ctx);
nk_style_set_font(ctx, font_14);
}
int main(int argc, char *argv[])
{
NK_UNUSED(argc);
NK_UNUSED(argv);
printf("Program started\n");
Application app;
NkWindow window;
OpenGLRenderDevice device;
Assets assets;
assets.InitFonts(device, fontList);
assets.LoadImages(device, imageList);
nk_init_default(window.Context(), &fontList[0].font->handle);
while (window.Update())
{
/* High DPI displays */
struct nk_vec2 scale;
int width, height, display_width, display_height;
window.GetSizes(width, height, display_width, display_height);
scale.x = (float)display_width/(float)width;
scale.y = (float)display_height/(float)height;
/* GUI */
//basic_demo(&ctx, &media);
//button_demo(&ctx, &media);
grid_demo(window.Context(), assets);
/* Draw */
device.Prepare(display_width, display_height);
device.Draw(window.Context(), width, height, scale);
device.Present();
window.Present();
}
return 0;
}