100 lines
2.7 KiB
C
100 lines
2.7 KiB
C
#include "EGA8x8.h"
|
|
#include "field.h"
|
|
#include "font.h"
|
|
#include "picture.h"
|
|
#include "platform.h"
|
|
#include "types.h"
|
|
|
|
#include <stdio.h>
|
|
#include <SDL3/SDL.h>
|
|
|
|
int main() {
|
|
|
|
int w = 1280, h = 720;
|
|
|
|
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
|
fprintf(stderr, "Can't init: %s\n", SDL_GetError());
|
|
return -1;
|
|
}
|
|
|
|
SDL_Window *window = SDL_CreateWindow("xormod", w, h, ACCEL_PLATFORM);
|
|
if (window == NULL) {
|
|
fprintf(stderr, "Can't open window: %s\n", SDL_GetError());
|
|
return -1;
|
|
}
|
|
|
|
SDL_GetWindowSize(window, &w, &h);
|
|
|
|
SDL_Renderer *rend = SDL_CreateRenderer(window, NULL);
|
|
|
|
SDL_Texture *font = load_font(rend);
|
|
|
|
Field f;
|
|
Field_init(&f, rend, w, h);
|
|
|
|
struct float2 mouse_prev = { -1, -1 };
|
|
int running = 1;
|
|
while (running) {
|
|
const bool *keys = SDL_GetKeyboardState(NULL);
|
|
if (keys[SDL_SCANCODE_ESCAPE] || keys[SDL_SCANCODE_Q]) {
|
|
break;
|
|
}
|
|
if (keys[SDL_SCANCODE_LEFT] || keys[SDL_SCANCODE_A]) {
|
|
f.offset.x -= 16;
|
|
}
|
|
if (keys[SDL_SCANCODE_RIGHT] || keys[SDL_SCANCODE_D]) {
|
|
f.offset.x += 16;
|
|
}
|
|
if (keys[SDL_SCANCODE_UP] || keys[SDL_SCANCODE_W]) {
|
|
f.offset.y -= 16;
|
|
}
|
|
if (keys[SDL_SCANCODE_DOWN] || keys[SDL_SCANCODE_S]) {
|
|
f.offset.y += 16;
|
|
}
|
|
|
|
struct float2 mouse;
|
|
|
|
if (SDL_GetMouseState(&mouse.x, &mouse.y) & SDL_BUTTON_LMASK) {
|
|
if (mouse_prev.x != -1 ) {
|
|
f.offset.x -= mouse.x - mouse_prev.x;
|
|
f.offset.y -= mouse.y - mouse_prev.y;
|
|
}
|
|
mouse_prev = mouse;
|
|
} else if (mouse_prev.x != -1) {
|
|
mouse_prev = (struct float2) { -1, -1 };
|
|
}
|
|
|
|
Field_scroll(&f, rend);
|
|
Field_draw(&f, rend);
|
|
|
|
char buf[72];
|
|
SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
|
|
SDL_RenderFillRect(rend, &(SDL_FRect) {
|
|
0, 0, sizeof(buf)*font_w, 8*font_h
|
|
});
|
|
|
|
draw_text(rend, font, ACCEL_PLATFORM_STR, sizeof(ACCEL_PLATFORM_STR), RC(1,1), 255, 255, 255);
|
|
|
|
size_t len = snprintf(buf, sizeof(buf),
|
|
"off.x: %d, off.y: %d", f.offset.x, f.offset.y);
|
|
draw_text(rend, font, buf, len, RC(2, 1), 255, 255, 255);
|
|
|
|
char *q[] = {"TL", "TR", "BL", "BR"};
|
|
for (int i = 0; i < 4; i++) {
|
|
Picture *p = f.pics[i];
|
|
len = snprintf(buf, sizeof(buf), "%s| x1: %05d, x2: %05d, y1: %05d, y2: %05d, p: %p",
|
|
q[i], p->x1, p->x2, p->y1, p->y2, p);
|
|
draw_text(rend, font, buf, len, RC(3+i, 1), 255, 255, 255);
|
|
}
|
|
|
|
SDL_RenderPresent(rend);
|
|
SDL_PumpEvents();
|
|
}
|
|
|
|
SDL_DestroyRenderer(rend);
|
|
SDL_DestroyWindow(window);
|
|
SDL_Quit();
|
|
|
|
return 0;
|
|
}
|