2022-12-13 12:32:36 -06:00
|
|
|
#include "window.h"
|
2022-06-30 10:31:23 -05:00
|
|
|
#include "input.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "log.h"
|
|
|
|
#include "script.h"
|
|
|
|
#include "texture.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2023-11-03 22:01:30 -05:00
|
|
|
#include "jsffi.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-09-04 09:48:44 -05:00
|
|
|
#include "render.h"
|
2022-12-14 13:01:42 -06:00
|
|
|
|
2022-08-26 09:19:17 -05:00
|
|
|
#include "stb_ds.h"
|
|
|
|
|
2023-08-31 13:00:33 -05:00
|
|
|
#include "sokol/sokol_app.h"
|
2024-03-03 16:58:59 -06:00
|
|
|
#include "stb_image_resize2.h"
|
2023-08-31 13:00:33 -05:00
|
|
|
|
2024-04-10 16:21:46 -05:00
|
|
|
struct window mainwin = {
|
|
|
|
.sample_count = 1,
|
|
|
|
.vsync = 1,
|
|
|
|
.enable_clipboard = 0,
|
|
|
|
.enable_dragndrop = 0,
|
|
|
|
};
|
2022-06-27 14:12:26 -05:00
|
|
|
|
2022-11-03 16:58:03 -05:00
|
|
|
static struct window *windows = NULL;
|
2022-08-26 09:19:17 -05:00
|
|
|
|
2024-03-13 03:51:44 -05:00
|
|
|
struct texture *icon = NULL;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-08-31 02:05:06 -05:00
|
|
|
void window_resize(int width, int height)
|
|
|
|
{
|
2024-03-13 16:30:55 -05:00
|
|
|
window *w = &mainwin;
|
|
|
|
w->size.x = width;
|
|
|
|
w->size.y = height;
|
|
|
|
window_apply(w);
|
2024-03-12 09:01:52 -05:00
|
|
|
|
|
|
|
script_evalf("prosperon.resize([%d,%d]);", width,height);
|
2022-06-30 10:31:23 -05:00
|
|
|
}
|
|
|
|
|
2024-03-13 16:30:55 -05:00
|
|
|
void window_apply(window *w)
|
|
|
|
{
|
|
|
|
w->aspect = w->size.x/w->size.y;
|
|
|
|
w->raspect = w->rendersize.x/w->rendersize.y;
|
|
|
|
w->psize.x = w->size.x*(w->raspect/w->aspect);
|
|
|
|
w->psize.y = w->size.y*(w->aspect/w->raspect);
|
|
|
|
w->left = (w->size.x-w->psize.x)/2;
|
|
|
|
w->top = (w->size.y-w->psize.y)/2;
|
|
|
|
}
|
|
|
|
|
2023-08-31 02:05:06 -05:00
|
|
|
void window_focused(int focus)
|
|
|
|
{
|
|
|
|
mainwin.focus = focus;
|
2024-03-12 09:01:52 -05:00
|
|
|
script_evalf("prosperon.focus(%d);", focus);
|
2023-08-31 02:05:06 -05:00
|
|
|
}
|
2022-06-27 14:12:26 -05:00
|
|
|
|
2023-08-31 02:05:06 -05:00
|
|
|
void window_iconified(int s)
|
|
|
|
{
|
|
|
|
mainwin.iconified = s;
|
2024-03-12 09:01:52 -05:00
|
|
|
script_evalf("prosperon.iconified(%d);", s);
|
2023-08-31 02:05:06 -05:00
|
|
|
}
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2023-08-31 02:05:06 -05:00
|
|
|
void window_suspended(int s)
|
|
|
|
{
|
2024-03-12 09:01:52 -05:00
|
|
|
script_evalf("prosperon.suspended(%d);", s);
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
|
|
|
|
2024-03-18 08:16:25 -05:00
|
|
|
void set_icon(const char *png) {
|
2024-03-13 03:51:44 -05:00
|
|
|
icon = texture_from_file(png);
|
2023-08-31 02:05:06 -05:00
|
|
|
window_seticon(&mainwin, icon);
|
2022-01-19 16:43:21 -06:00
|
|
|
}
|
|
|
|
|
2024-03-13 16:30:55 -05:00
|
|
|
void window_setfullscreen(window *w, int f)
|
|
|
|
{
|
|
|
|
if (w->fullscreen == f) return;
|
|
|
|
w->fullscreen = f;
|
|
|
|
|
|
|
|
if (!w->start) return;
|
|
|
|
|
|
|
|
if (sapp_is_fullscreen() == f) return;
|
2023-08-31 02:05:06 -05:00
|
|
|
sapp_toggle_fullscreen();
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2024-03-13 03:51:44 -05:00
|
|
|
void window_seticon(struct window *w, struct texture *tex)
|
2023-08-31 13:00:33 -05:00
|
|
|
{
|
|
|
|
struct isize {
|
|
|
|
int size;
|
|
|
|
unsigned char *data;
|
|
|
|
};
|
2023-09-19 01:10:00 -05:00
|
|
|
struct isize sizes[4];
|
2023-08-31 13:00:33 -05:00
|
|
|
sizes[0].size = 16;
|
|
|
|
sizes[1].size = 32;
|
|
|
|
sizes[2].size = 64;
|
2023-09-19 01:10:00 -05:00
|
|
|
sizes[3].size = 128;
|
2023-08-31 13:00:33 -05:00
|
|
|
|
2023-09-19 01:10:00 -05:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2023-08-31 13:00:33 -05:00
|
|
|
sizes[i].data = malloc(4*sizes[i].size*sizes[i].size);
|
2024-03-03 16:58:59 -06:00
|
|
|
stbir_resize_uint8_linear(tex->data, tex->width, tex->height, 0, sizes[i].data, sizes[i].size, sizes[i].size, 0, 4);
|
2023-08-31 13:00:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sapp_icon_desc idsc = {
|
|
|
|
.images = {
|
|
|
|
{ .width = sizes[0].size, .height = sizes[0].size, .pixels = { .ptr=sizes[0].data, .size=4*sizes[0].size*sizes[0].size } },
|
|
|
|
{ .width = sizes[1].size, .height = sizes[1].size, .pixels = { .ptr=sizes[1].data, .size=4*sizes[1].size*sizes[1].size } },
|
2023-09-19 01:10:00 -05:00
|
|
|
{ .width = sizes[2].size, .height = sizes[2].size, .pixels = { .ptr=sizes[2].data, .size=4*sizes[2].size*sizes[2].size } },
|
|
|
|
{ .width = sizes[3].size, .height = sizes[3].size, .pixels = { .ptr=sizes[3].data, .size=4*sizes[3].size*sizes[3].size } },
|
2023-08-31 13:00:33 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
sapp_set_icon(&idsc);
|
2023-09-19 01:10:00 -05:00
|
|
|
for (int i = 0; i < 4; i++)
|
2023-08-31 13:00:33 -05:00
|
|
|
free(sizes[i].data);
|
2022-02-06 10:14:57 -06:00
|
|
|
}
|
|
|
|
|
2024-03-13 16:30:55 -05:00
|
|
|
void window_free(window *w)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|