Browse Source

Added basic work on ScrumbleOS/nuklear

master
dirkson 3 years ago
parent
commit
929ecd4c80
  1. 20
      scripts/win32cross.txt
  2. 20
      scripts/win64cross.txt
  3. 196
      src/client-nuklear/main.c

20
scripts/win32cross.txt

@ -0,0 +1,20 @@
[binaries]
c = 'i686-w64-mingw32.static-gcc'
cpp = 'i686-w64-mingw32.static-g++'
ar = 'i686-w64-mingw32.static-ar'
strip = 'i686-w64-mingw32.static-strip'
pkgconfig = 'i686-w64-mingw32.static-pkg-config'
exe_wrapper = 'wine' # A command used to run generated executables.
[properties]
has_function_printf = true
c_args = ['-DBOKSI_BUILD_WIN']
#c_link_args = ['']
needs_exe_wrapper = true
[host_machine]
system = 'windows'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'

20
scripts/win64cross.txt

@ -0,0 +1,20 @@
[binaries]
c = 'x86_64-w64-mingw32.static-gcc'
cpp = 'x86_64-w64-mingw32.static-g++'
ar = 'x86_64-w64-mingw32.static-ar'
strip = 'x86_64-w64-mingw32.static-strip'
pkgconfig = 'x86_64-w64-mingw32.static-pkg-config'
#exe_wrapper = 'true' # A command used to run generated executables.
[properties]
has_function_printf = true
c_args = ['-DBOKSI_BUILD_WIN']
#c_link_args = ['']
needs_exe_wrapper = true
[host_machine]
system = 'windows'
cpu_family = 'x86'
cpu = 'x86_64'
endian = 'little'

196
src/client-nuklear/main.c

@ -12,7 +12,6 @@
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_IMPLEMENTATION
#define NK_GLFW_GL2_IMPLEMENTATION
#define NK_KEYSTATE_BASED_INPUT
@ -28,7 +27,19 @@
//Sensible OSes.
#endif
//#include "simsecl_nuklear_tabs.h"
#define SCRUMBLEOS_WINDOW_STANDARD NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_TITLE | NK_WINDOW_CLOSABLE
#define SCRUMBLEOS_WINDOW_BACKGROUND NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BACKGROUND
#define COLOR_GLOW nk_rgb(0,180,0)
#define COLOR_GLOW_BRIGHT nk_rgb(0,230,0)
#define COLOR_MONITOR nk_rgb(247, 230, 154)
#define COLOR_BEVEL nk_rgb(68,68,68)
#define COLOR_SCREEN nk_rgb(0,10,0)
#define HEADER_MARGIN 130
#define MARGIN 50
#define MONITOR_TOP 110
#define MONITOR_SIZE 30
#define BEVEL_SIZE 10
GLFWwindow *win;
@ -38,36 +49,140 @@ static void glfw_err(int err, const char *str)
printf("Err: %s\n", str);
}
struct nk_canvas {
struct nk_command_buffer *painter;
struct nk_vec2 item_spacing;
struct nk_vec2 panel_padding;
struct nk_style_item window_background;
};
static struct nk_vec2 herd_window(struct nk_context *ctx, char *name, int width, int height)
{
struct nk_rect windowInfo = nk_window_get_bounds(ctx);
if (windowInfo.x < MARGIN)
windowInfo.x = MARGIN;
else if (windowInfo.x + windowInfo.w + MARGIN > width)
windowInfo.x = width - windowInfo.w - MARGIN;
if (windowInfo.y < HEADER_MARGIN)
windowInfo.y = HEADER_MARGIN;
else if (windowInfo.y + windowInfo.h + MARGIN > height)
windowInfo.y = height - windowInfo.h - MARGIN;
struct nk_vec2 pos;
pos.x = windowInfo.x;
pos.y = windowInfo.y;
nk_window_set_position(ctx, name, pos);
return pos;
}
static void canvas_begin(struct nk_context *ctx, struct nk_canvas *canvas, nk_flags flags,
int x, int y, int width, int height, struct nk_color background_color)
{
/* save style properties which will be overwritten */
canvas->panel_padding = ctx->style.window.padding;
canvas->item_spacing = ctx->style.window.spacing;
canvas->window_background = ctx->style.window.fixed_background;
/* use the complete window space and set background */
ctx->style.window.spacing = nk_vec2(0,0);
ctx->style.window.padding = nk_vec2(0,0);
ctx->style.window.fixed_background = nk_style_item_color(background_color);
/* create/update window and set position + size */
//flags = flags & ~NK_WINDOW_DYNAMIC;
//nk_window_set_bounds(ctx, "Can", nk_rect(x, y, width, height));
nk_begin(ctx, "Can", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_NO_INPUT|flags);
/* allocate the complete window space for drawing */
{
//struct nk_rect total_space;
// total_space = nk_window_get_content_region(ctx);
// nk_layout_row_dynamic(ctx, total_space.h, 1);
// nk_widget(&total_space, ctx);
canvas->painter = nk_window_get_canvas(ctx);}
}
static void
canvas_end(struct nk_context *ctx, struct nk_canvas *canvas)
{
nk_end(ctx);
ctx->style.window.spacing = canvas->panel_padding;
ctx->style.window.padding = canvas->item_spacing;
ctx->style.window.fixed_background = canvas->window_background;
}
void MainLoop(GLFWwindow *win, struct nk_context* ctx)
{
printf("%p %p \n", win, ctx);
struct nk_vec2 demopos = {0};
//Do somethin'
while (!glfwWindowShouldClose(win))
{
//Input
glfwPollEvents();
//Get current window height
int width = 0, height = 0;
glfwGetWindowSize(win, &width, &height);
//Nuklear
nk_window_set_position(ctx, "Demo", demopos);
nk_glfw3_new_frame();
nk_window_set_position(ctx, "Demo", demopos);
//Demo window
struct nk_canvas canvas;
canvas_begin(ctx, &canvas, 0, 0, 0, width, height, nk_rgba(250,250,250, 0));
{
nk_fill_rect(canvas.painter, nk_rect(0,0,width,MONITOR_TOP), 5, COLOR_MONITOR);
nk_fill_rect(canvas.painter, nk_rect(0,0,MONITOR_SIZE,height), 5, COLOR_MONITOR);
nk_fill_rect(canvas.painter, nk_rect(width-MONITOR_SIZE,0,MONITOR_SIZE,height), 5, COLOR_MONITOR);
nk_fill_rect(canvas.painter, nk_rect(0,height-MONITOR_SIZE,width,MONITOR_SIZE), 5, COLOR_MONITOR);
//nk_fill_arc(canvas.painter, 200, 200, 50, 0, 3.141592654f * 3.0f / 4.0f, COLOR_MONITOR);
nk_fill_rect(canvas.painter, nk_rect(MONITOR_SIZE-BEVEL_SIZE,MONITOR_TOP-BEVEL_SIZE, width-MONITOR_SIZE-BEVEL_SIZE,height-MONITOR_TOP-BEVEL_SIZE), 5, COLOR_BEVEL);
nk_fill_rect(canvas.painter, nk_rect(MONITOR_SIZE,MONITOR_TOP, width-MONITOR_SIZE-BEVEL_SIZE*3,height-MONITOR_TOP-BEVEL_SIZE*3), 5, COLOR_SCREEN);
//nk_fill_rect(canvas.painter, nk_rect(20,20,200,200), 5, nk_rgb(188, 174, 118));
}
canvas_end(ctx, &canvas);
//struct nk_rect windowInfo = {0};
nk_window_set_position(ctx, "Demo", demopos);
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)
SCRUMBLEOS_WINDOW_STANDARD)
) {
demopos = herd_window(ctx, "Demo", width, height);
nk_layout_row_static(ctx, 30, 80, 1);
if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");
}
nk_end(ctx);
nk_window_set_position(ctx, "Demo", demopos);
//nk_window_set_bounds(ctx, "Demo", windowInfo);
//Render
int width = 0, height = 0;
glfwGetWindowSize(win, &width, &height);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.1f, 0.18f, 0.24f, 1.0f);
glClearColor(0.0f, 0.02f, 0.0f, 1.0f);
nk_window_set_position(ctx, "Demo", demopos);
nk_glfw3_render(NK_ANTI_ALIASING_ON);
nk_window_set_position(ctx, "Demo", demopos);
/*
nk_glfw3_new_frame();
struct nk_canvas canvas;
canvas_begin(ctx, &canvas, 0, 0, 0, width, height, nk_rgba(250,250,250, 0));
{
nk_fill_rect(canvas.painter, nk_rect(0,0,width,20), 5, nk_rgb(247, 230, 154));
//nk_fill_rect(canvas.painter, nk_rect(20,20,200,200), 5, nk_rgb(188, 174, 118));
}
canvas_end(ctx, &canvas);
nk_glfw3_render(NK_ANTI_ALIASING_ON);
*/
//NK_ANTI_ALIASING_OFF);
glfwSwapBuffers(win);
nk_window_set_position(ctx, "Demo", demopos);
//TODO: Sleep
}
}
@ -86,18 +201,74 @@ int BuildWindow(GLFWwindow ** win, struct nk_context** ctx)
{
glfwSetErrorCallback(glfw_err);
*win = glfwCreateWindow(600, 400, "Demo", NULL, NULL);
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
*win = glfwCreateWindow(mode->width, mode->height, "ScrumbleLaunch", monitor, NULL);
if (NULL == *win)
return 0;
glfwMakeContextCurrent(*win);
glfwSetInputMode(*win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
*ctx = nk_glfw3_init(*win, NK_GLFW3_INSTALL_CALLBACKS);
if (NULL == *ctx)
return 0;
struct nk_color table[NK_COLOR_COUNT];
table[NK_COLOR_TEXT] = COLOR_GLOW;
table[NK_COLOR_WINDOW] = nk_rgb(40, 40, 40);
table[NK_COLOR_HEADER] = nk_rgb(15, 15, 15);
table[NK_COLOR_BORDER] = COLOR_GLOW;
table[NK_COLOR_BUTTON] = nk_rgb(0, 0, 0);
table[NK_COLOR_BUTTON_HOVER] = COLOR_GLOW;
table[NK_COLOR_BUTTON_ACTIVE] = COLOR_GLOW_BRIGHT;
table[NK_COLOR_TOGGLE] = nk_rgb(0, 0, 0);
table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(120, 120, 120, 255);
table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_SELECT] = COLOR_GLOW;
table[NK_COLOR_SELECT_ACTIVE] = COLOR_GLOW_BRIGHT;
table[NK_COLOR_SLIDER] = nk_rgba(190, 190, 190, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(80, 80, 80, 255);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(70, 70, 70, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(60, 60, 60, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_EDIT_CURSOR] = COLOR_GLOW;
table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255);
table[NK_COLOR_SCROLLBAR] = nk_rgba(180, 180, 180, 255);
table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(140, 140, 140, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255);
nk_style_from_table(*ctx, table);
(*ctx)->style.button.text_hover = nk_rgb(0,0,0);
(*ctx)->style.button.text_active = nk_rgb(0,0,0);
//(*ctx)->style.window.border_color = nk_rgb(0,150,0);
//
//(*ctx)->style.window.fixed_background = nk_style_item_color(nk_rgb(0,0,0));
//(*ctx)->style.window.border = 1;
//(*ctx)->style.window.rounding = -5.5f;
struct nk_font_atlas *atlas;
nk_glfw3_font_stash_begin(&atlas);
struct nk_font *connection = nk_font_atlas_add_from_memory(atlas, font_connection, sizeof(font_connection), 18, 0);
@ -112,7 +283,6 @@ int BuildWindow(GLFWwindow ** win, struct nk_context** ctx)
void Cleanup()
{
nk_glfw3_shutdown();
glfwTerminate();
}
@ -128,6 +298,12 @@ int main()
MainLoop(win, ctx);
glfwDestroyWindow(win);
nk_glfw3_shutdown();
//Run ScrumbleShip
Cleanup();
return 0;

Loading…
Cancel
Save