orca/sketches/simpleWindow/main.c

132 lines
4.1 KiB
C
Raw Permalink Normal View History

2023-09-07 12:51:48 +00:00
/*************************************************************************
*
2023-09-07 12:51:48 +00:00
* Orca
* Copyright 2023 Martin Fouilleul and the Orca project contributors
* See LICENSE.txt for licensing information
*
2023-09-07 12:51:48 +00:00
**************************************************************************/
2023-08-19 12:49:23 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "orca.h"
2023-08-19 12:49:23 +00:00
int main()
{
oc_init();
2023-08-19 12:49:23 +00:00
oc_rect rect = { .x = 100, .y = 100, .w = 800, .h = 600 };
oc_window window = oc_window_create(rect, OC_STR8("test"), 0);
2023-08-19 12:49:23 +00:00
oc_window_bring_to_front(window);
oc_window_focus(window);
2023-08-19 12:49:23 +00:00
oc_window_center(window);
2023-08-19 12:49:23 +00:00
while(!oc_should_quit())
2023-08-19 12:49:23 +00:00
{
oc_arena_scope scratch = oc_scratch_begin();
oc_pump_events(0);
oc_event* event = 0;
while((event = oc_next_event(scratch.arena)) != 0)
2023-08-19 12:49:23 +00:00
{
switch(event->type)
{
case OC_EVENT_WINDOW_CLOSE:
2023-08-19 12:49:23 +00:00
{
oc_request_quit();
2023-08-19 12:49:23 +00:00
}
break;
case OC_EVENT_WINDOW_RESIZE:
2023-08-19 12:49:23 +00:00
{
oc_log_info("resized, frame = {%f, %f, %f, %f}, content = {%f, %f, %f, %f}\n",
event->move.frame.x,
event->move.frame.y,
event->move.frame.w,
event->move.frame.h,
event->move.content.x,
event->move.content.y,
event->move.content.w,
event->move.content.h);
2023-08-19 12:49:23 +00:00
}
break;
case OC_EVENT_WINDOW_MOVE:
2023-08-19 12:49:23 +00:00
{
oc_log_info("moved, frame = {%f, %f, %f, %f}, content = {%f, %f, %f, %f}\n",
event->move.frame.x,
event->move.frame.y,
event->move.frame.w,
event->move.frame.h,
event->move.content.x,
event->move.content.y,
event->move.content.w,
event->move.content.h);
2023-08-19 12:49:23 +00:00
}
break;
case OC_EVENT_MOUSE_MOVE:
2023-08-19 12:49:23 +00:00
{
oc_log_info("mouse moved, pos = {%f, %f}, delta = {%f, %f}\n",
event->mouse.x,
event->mouse.y,
event->mouse.deltaX,
event->mouse.deltaY);
2023-08-19 12:49:23 +00:00
}
break;
case OC_EVENT_MOUSE_WHEEL:
2023-08-19 12:49:23 +00:00
{
oc_log_info("mouse wheel, delta = {%f, %f}\n",
event->mouse.deltaX,
event->mouse.deltaY);
2023-08-19 12:49:23 +00:00
}
break;
case OC_EVENT_MOUSE_ENTER:
2023-08-19 12:49:23 +00:00
{
oc_log_info("mouse enter\n");
2023-08-19 12:49:23 +00:00
}
break;
case OC_EVENT_MOUSE_LEAVE:
2023-08-19 12:49:23 +00:00
{
oc_log_info("mouse leave\n");
2023-08-19 12:49:23 +00:00
}
break;
case OC_EVENT_MOUSE_BUTTON:
2023-08-19 12:49:23 +00:00
{
oc_log_info("mouse button %i: %i\n",
event->key.code,
event->key.action == OC_KEY_PRESS ? 1 : 0);
2023-08-19 12:49:23 +00:00
}
break;
case OC_EVENT_KEYBOARD_KEY:
2023-08-19 12:49:23 +00:00
{
oc_log_info("key %i: %s\n",
event->key.code,
event->key.action == OC_KEY_PRESS ? "press" : (event->key.action == OC_KEY_RELEASE ? "release" : "repeat"));
2023-08-19 12:49:23 +00:00
}
break;
case OC_EVENT_KEYBOARD_CHAR:
2023-08-19 12:49:23 +00:00
{
oc_log_info("entered char %s\n", event->character.sequence);
2023-08-19 12:49:23 +00:00
}
break;
default:
break;
}
}
oc_scratch_end(scratch);
2023-08-19 12:49:23 +00:00
}
oc_terminate();
2023-08-19 12:49:23 +00:00
return (0);
}