[win32] re-introduced perf_text, tiger, and ui examples

This commit is contained in:
martinfouilleul 2023-05-17 15:14:14 +02:00
parent 2bec7a633a
commit 9f7cfd985c
4 changed files with 1189 additions and 1182 deletions

View File

@ -92,6 +92,8 @@ mg_font create_font(const char* path)
return(font);
}
enum { FONT_COUNT = 3 };
int main()
{
mp_init();
@ -109,17 +111,16 @@ int main()
mg_canvas canvas = mg_canvas_create();
const int fontCount = 3;
int fontIndex = 0;
mg_font fonts[fontCount] = {create_font("../resources/OpenSansLatinSubset.ttf"),
mg_font fonts[FONT_COUNT] = {create_font("../resources/OpenSansLatinSubset.ttf"),
create_font("../resources/CMUSerif-Roman.ttf"),
create_font("../resources/courier.ttf")};
mg_font_extents extents[fontCount];
f32 fontScales[fontCount];
f32 lineHeights[fontCount];
mg_font_extents extents[FONT_COUNT];
f32 fontScales[FONT_COUNT];
f32 lineHeights[FONT_COUNT];
for(int i=0; i<fontCount; i++)
for(int i=0; i<FONT_COUNT; i++)
{
extents[i] = mg_font_get_extents(fonts[i]);
fontScales[i] = mg_font_get_scale_for_em_pixels(fonts[i], 14);
@ -206,7 +207,7 @@ int main()
{
if(event->key.code == MP_KEY_SPACE && event->key.action == MP_KEY_PRESS)
{
fontIndex = (fontIndex+1)%fontCount;
fontIndex = (fontIndex+1)%FONT_COUNT;
}
} break;
@ -313,7 +314,7 @@ int main()
}
for(int i=0; i<fontCount; i++)
for(int i=0; i<FONT_COUNT; i++)
{
mg_font_destroy(fonts[i]);
}

View File

@ -1,4 +1,4 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_canvas.exe
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_tiger.exe

View File

@ -8,6 +8,7 @@
*****************************************************************/
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<errno.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC

View File

@ -8,6 +8,7 @@
*****************************************************************/
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<errno.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
@ -15,8 +16,6 @@
#include"milepost.h"
#define LOG_SUBSYSTEM "Main"
void debug_print_indent(int indent)
{
for(int i=0; i<indent; i++)
@ -206,12 +205,12 @@ void widget_end_view(void)
int main()
{
LogLevel(LOG_LEVEL_WARNING);
mp_init();
mp_clock_init(); //TODO put that in mp_init()?
ui_init();
ui_context context;
ui_init(&context);
ui_set_context(&context);
mp_rect windowRect = {.x = 100, .y = 100, .w = 810, .h = 610};
mp_window window = mp_window_create(windowRect, "test", 0);
@ -219,11 +218,11 @@ int main()
mp_rect contentRect = mp_window_get_content_rect(window);
//NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_DEFAULT);
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS);
mg_surface_swap_interval(surface, 0);
//TODO: create canvas
mg_canvas canvas = mg_canvas_create(surface);
mg_canvas canvas = mg_canvas_create();
if(mg_canvas_is_nil(canvas))
{
@ -247,10 +246,12 @@ int main()
f64 startTime = mp_get_time(MP_CLOCK_MONOTONIC);
mp_pump_events(0);
mp_event event = {0};
while(mp_next_event(&event))
mp_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0)
{
switch(event.type)
ui_process_event(event);
switch(event->type)
{
case MP_EVENT_WINDOW_CLOSE:
{
@ -260,7 +261,7 @@ int main()
case MP_EVENT_KEYBOARD_KEY:
{
if(event.key.action == MP_KEY_PRESS && event.key.code == MP_KEY_P)
if(event->key.action == MP_KEY_PRESS && event->key.code == MP_KEY_P)
{
printDebugStyle = true;
}
@ -289,7 +290,11 @@ int main()
ui_flags debugFlags = UI_FLAG_DRAW_BORDER;
ui_box* root = 0;
ui_frame(&defaultStyle, defaultMask)
mp_rect frameRect = mg_surface_get_frame(surface);
vec2 frameSize = {frameRect.w, frameRect.h};
ui_frame(frameSize, &defaultStyle, defaultMask)
{
root = ui_box_top();
ui_style_match_before(ui_pattern_all(), &defaultStyle, defaultMask);
@ -518,7 +523,7 @@ int main()
UI_STYLE_SIZE);
widget_view("Test")
{
ui_pattern pattern = {};
ui_pattern pattern = {0};
ui_pattern_push(mem_scratch(), &pattern, (ui_selector){.kind = UI_SEL_TEXT, .text = STR8("panel")});
ui_style_match_after(pattern, &(ui_style){.bgColor = {0.3, 0.3, 1, 1}}, UI_STYLE_BG_COLOR);
@ -592,7 +597,7 @@ int main()
ui_draw();
mg_flush();
mg_render(surface, canvas);
mg_surface_present(surface);
mem_arena_clear(mem_scratch());