ext/say_win_window.h in ray-0.1.1 vs ext/say_win_window.h in ray-0.2.0
- old
+ new
@@ -198,11 +198,11 @@
}
case WM_CLOSE: {
say_event ev;
ev.type = SAY_EVENT_QUIT;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_SIZE: {
if (wparam != SIZE_MINIMIZED) {
@@ -212,36 +212,36 @@
size_t h = rect.bottom - rect.top;
say_event ev;
ev.type = SAY_EVENT_RESIZE;
ev.ev.resize.size = say_make_vector2(w, h);
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
}
break;
}
case WM_SETFOCUS: {
say_event ev;
ev.type = SAY_EVENT_FOCUS_GAIN;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_KILLFOCUS: {
say_event ev;
ev.type = SAY_EVENT_FOCUS_LOSS;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_CHAR: {
say_event ev;
ev.type = SAY_EVENT_TEXT_ENTERED;
ev.ev.text.text = (uint32_t)wparam;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_KEYDOWN:
@@ -251,11 +251,11 @@
ev.type = SAY_EVENT_KEY_PRESS;
ev.ev.key.mod = say_win_get_mod();
ev.ev.key.native_code = (uint32_t)wparam;
ev.ev.key.code = say_win_get_key(wparam, lparam);
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
}
break;
}
case WM_KEYUP:
@@ -264,11 +264,11 @@
ev.type = SAY_EVENT_KEY_RELEASE;
ev.ev.key.mod = say_win_get_mod();
ev.ev.key.native_code = (uint32_t)wparam;
ev.ev.key.code = say_win_get_key(wparam, lparam);
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_MOUSEWHEEL: {
POINT pos;
@@ -279,71 +279,71 @@
say_event ev;
ev.type = SAY_EVENT_WHEEL_MOTION;
ev.ev.wheel.pos = say_make_vector2(pos.x, pos.y);
ev.ev.wheel.delta = (int16_t)(HIWORD(wparam)) / 120;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_LBUTTONDOWN: {
say_event ev;
ev.type = SAY_EVENT_BUTTON_PRESS;
ev.ev.button.pos = say_make_vector2(LOWORD(lparam), HIWORD(lparam));
ev.ev.button.button = SAY_BUTTON_LEFT;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_LBUTTONUP: {
say_event ev;
ev.type = SAY_EVENT_BUTTON_RELEASE;
ev.ev.button.pos = say_make_vector2(LOWORD(lparam), HIWORD(lparam));
ev.ev.button.button = SAY_BUTTON_LEFT;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_RBUTTONDOWN: {
say_event ev;
ev.type = SAY_EVENT_BUTTON_PRESS;
ev.ev.button.pos = say_make_vector2(LOWORD(lparam), HIWORD(lparam));
ev.ev.button.button = SAY_BUTTON_RIGHT;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_RBUTTONUP: {
say_event ev;
ev.type = SAY_EVENT_BUTTON_RELEASE;
ev.ev.button.pos = say_make_vector2(LOWORD(lparam), HIWORD(lparam));
ev.ev.button.button = SAY_BUTTON_RIGHT;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_MBUTTONDOWN: {
say_event ev;
ev.type = SAY_EVENT_BUTTON_PRESS;
ev.ev.button.pos = say_make_vector2(LOWORD(lparam), HIWORD(lparam));
ev.ev.button.button = SAY_BUTTON_MIDDLE;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_MBUTTONUP: {
say_event ev;
ev.type = SAY_EVENT_BUTTON_RELEASE;
ev.ev.button.pos = say_make_vector2(LOWORD(lparam), HIWORD(lparam));
ev.ev.button.button = SAY_BUTTON_MIDDLE;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_MOUSEMOVE: {
if (!win->cursor_inside) {
@@ -355,27 +355,27 @@
mouse_ev.dwFlags = TME_LEAVE;
TrackMouseEvent(&mouse_ev);
say_event ev;
ev.type = SAY_EVENT_MOUSE_ENTERED;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
}
say_event ev;
ev.type = SAY_EVENT_MOUSE_MOTION;
ev.ev.motion.pos = say_make_vector2(LOWORD(lparam), HIWORD(lparam));
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
case WM_MOUSELEAVE: {
win->cursor_inside = false;
say_event ev;
ev.type = SAY_EVENT_MOUSE_LEFT;
- say_array_push(win->events, &ev);
+ mo_array_push(&win->events, &ev);
break;
}
}
}
@@ -464,18 +464,18 @@
win->win = 0;
win->icon = 0;
win->cursor = LoadCursor(NULL, IDC_ARROW);;
- win->events = say_array_create(sizeof(say_event), NULL, NULL);
+ mo_array_init(&win->events, sizeof(say_event));
return win;
}
void say_imp_window_free(say_imp_window win) {
say_imp_window_close(win);
- say_array_free(win->events);
+ mo_array_release(&win->events);
free(win);
}
bool say_imp_window_open(say_imp_window win, const char *title,
size_t w, size_t h,
@@ -586,19 +586,22 @@
if (!buf) {
say_error_set("could not allocate icon buffer");
return false;
}
- say_color *orig = say_image_get_buffer(img);
+ say_color *orig = say_flip_color_buffer_copy(say_image_get_buffer(img),
+ w, h);
for (size_t i = 0; i < w * h; i++) {
buf[i * 4 + 0] = orig[i].b;
buf[i * 4 + 1] = orig[i].g;
buf[i * 4 + 2] = orig[i].r;
buf[i * 4 + 3] = orig[i].a;
}
+ free(orig);
+
win->icon = CreateIcon(GetModuleHandle(NULL), w, h, 1, 32, NULL, buf);
if (!win->icon) {
free(buf);
say_error_set("could not create icon");
@@ -632,39 +635,39 @@
}
bool say_imp_window_poll_event(say_imp_window win, struct say_event *ev,
struct say_input *input) {
- if (say_array_get_size(win->events) == 0) {
+ if (win->events.size == 0) {
MSG message;
while (PeekMessage(&message, win->win, 0, 0, PM_REMOVE)) {
TranslateMessage(&message);
DispatchMessage(&message);
}
}
- if (say_array_get_size(win->events) == 0) {
+ if (win->events.size == 0) {
ev->type = SAY_EVENT_NONE;
return false;
}
else {
- *ev = *(say_event*)say_array_get(win->events, 0);
- say_array_delete(win->events, 0);
+ *ev = mo_array_get_as(&win->events, 0, say_event);
+ mo_array_delete(&win->events, 0);
return true;
}
}
void say_imp_window_wait_event(say_imp_window win, struct say_event *ev,
struct say_input *input) {
- while (say_array_get_size(win->events) == 0) {
+ while (win->events.size == 0) {
WaitMessage();
MSG message;
while (PeekMessage(&message, win->win, 0, 0, PM_REMOVE)) {
TranslateMessage(&message);
DispatchMessage(&message);
}
}
- *ev = *(say_event*)say_array_get(win->events, 0);
- say_array_delete(win->events, 0);
+ *ev = mo_array_get_as(&win->events, 0, say_event);
+ mo_array_delete(&win->events, 0);
}