2023-06-20 09:47:02 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2023-06-20 09:47:02 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
#include "orca.h"
|
2023-06-20 09:47:02 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_init();
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
|
|
|
|
oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_rect contentRect = oc_window_get_content_rect(window);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
//NOTE: create surface
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface surface1 = oc_surface_create_for_window(window, OC_CANVAS);
|
|
|
|
if(oc_surface_is_nil(surface1))
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
printf("Error: couldn't create surface 1\n");
|
|
|
|
return (-1);
|
|
|
|
}
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface_swap_interval(surface1, 0);
|
2023-08-19 12:49:23 +00:00
|
|
|
//*
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface surface2 = oc_surface_create_for_window(window, OC_CANVAS);
|
|
|
|
if(oc_surface_is_nil(surface2))
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
printf("Error: couldn't create surface 2\n");
|
|
|
|
return (-1);
|
|
|
|
}
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface_swap_interval(surface2, 0);
|
2023-08-19 12:49:23 +00:00
|
|
|
//*/
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_canvas canvas1 = oc_canvas_create();
|
|
|
|
if(oc_canvas_is_nil(canvas1))
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
printf("Error: couldn't create canvas 1\n");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
//*
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_canvas canvas2 = oc_canvas_create();
|
|
|
|
if(oc_canvas_is_nil(canvas2))
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
printf("Error: couldn't create canvas 2\n");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
//*/
|
|
|
|
// start app
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_window_center(window);
|
|
|
|
oc_window_bring_to_front(window);
|
|
|
|
oc_window_focus(window);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
while(!oc_should_quit())
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_pump_events(0);
|
|
|
|
oc_event* event = 0;
|
|
|
|
while((event = oc_next_event(oc_scratch())) != 0)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
switch(event->type)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_EVENT_WINDOW_CLOSE:
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_request_quit();
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-08-28 13:48:24 +00:00
|
|
|
case OC_EVENT_KEYBOARD_KEY:
|
|
|
|
{
|
|
|
|
if(event->key.action == OC_KEY_PRESS)
|
|
|
|
{
|
|
|
|
if(event->key.code == OC_KEY_UP)
|
|
|
|
{
|
|
|
|
oc_surface_bring_to_front(surface2);
|
|
|
|
}
|
|
|
|
else if(event->key.code == OC_KEY_DOWN)
|
|
|
|
{
|
|
|
|
oc_surface_send_to_back(surface2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface_select(surface1);
|
|
|
|
oc_canvas_set_current(canvas1);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_set_color_rgba(0, 0, 0.5, 0.5);
|
|
|
|
oc_clear();
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_set_color_rgba(1, 0, 0, 1);
|
|
|
|
oc_rectangle_fill(100, 100, 300, 150);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_render(surface1, canvas1);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
//*
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface_select(surface2);
|
|
|
|
oc_canvas_set_current(canvas2);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_set_color_rgba(0, 0, 0, 0);
|
|
|
|
oc_clear();
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_set_color_rgba(0, 0, 1, 1);
|
2023-08-28 13:48:24 +00:00
|
|
|
oc_rectangle_fill(200, 200, 300, 200);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_render(surface2, canvas2);
|
2023-08-19 12:49:23 +00:00
|
|
|
//*/
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface_present(surface1);
|
|
|
|
oc_surface_present(surface2);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_arena_clear(oc_scratch());
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_canvas_destroy(canvas1);
|
|
|
|
oc_surface_destroy(surface1);
|
|
|
|
oc_canvas_destroy(canvas2);
|
|
|
|
oc_surface_destroy(surface2);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_window_destroy(window);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_terminate();
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
return (0);
|
2023-06-20 09:47:02 +00:00
|
|
|
}
|