Skip to content

Commit

Permalink
fix poor display on smaller screens
Browse files Browse the repository at this point in the history
  • Loading branch information
lets-all-be-stupid-forever committed Sep 18, 2024
1 parent 0ebb351 commit 127a023
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
15 changes: 3 additions & 12 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,14 @@ void UiLoad(Ui* ui) {
// For now the ui scale only works at scale=2, there are some hard coded
// scale that needs to be fixed (low priority)
ui->scale = 2;

#ifndef WEB
int k = 110;
int screen_width = k * 16 - 2;
int screen_height = k * 9 - 32;
int screen_width = 640 * 2;
int screen_height = 320 * 2;
SetTraceLogLevel(LOG_NONE);
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
#else
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
int screen_width = 640 * 2;
int screen_height = 360 * 2;
#endif
InitWindow(screen_width, screen_height, "Circuit Artist");
SetWindowState(FLAG_WINDOW_MAXIMIZED);
ui->icon = LoadImage("../assets/icon32.png");
#ifndef WEB
SetWindowIcon(ui->icon);
#endif
LoadArtFont("../assets/font5x7.png");
ui->sprites = LoadTexture("../assets/sprite4.png");
HideCursor();
Expand Down
10 changes: 7 additions & 3 deletions src/w_about.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@ static void AboutUpdateLayout() {
int sw = GetScreenWidth();
int sh = GetScreenHeight();
int bw = 12 * 35 * 2;
int s = 2;
int total_w = bw + 2 * 2;
int x = (sw - total_w) / 2;
int bh = 9 * 35 * 2;
int bh = 9 * 35 * s;
#ifdef WEB
// Making it smaller for the web version
bh = 4 * 35 * 2;
#endif
int s = 2;
int total_h = (bh + 35 * 2 + 35 * 2);
int pad = 10 * s;
while (total_h + 2 * pad + 10 > sh) {
total_h -= 35 * s;
bh -= 35 * s;
}
int y = (sh - total_h) / 2;
int yy = y + 35 * 2;
C.title = (Rectangle){x, y, total_w, 35 * 2};
int pad = 10 * s;
C.modal = (Rectangle){x - pad, y - pad, total_w + 2 * pad, total_h + 2 * pad};
Rectangle box = {x + 2 * s, yy, bw, bh};
C.textbox_wrap = box;
Expand Down
7 changes: 6 additions & 1 deletion src/w_cpedia.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ void CpediaUpdateLayout() {
int x = (sw - total_w) / 2;
int bh = 9 * 35 * 2;
int s = 2;
int pad = 10 * s;
int total_h = (bh + 35 * 2 + 35 * 2);
while (total_h + 2 * pad > sh) {
bh -= 35 * 2;
total_h -= 35 * 2;
}

int y = (sh - total_h) / 2;
int yy = y + 35 * 2;
C.title = (Rectangle){x, y, total_w, 35 * 2};
int pad = 10 * s;
C.modal = (Rectangle){x - pad, y - pad, total_w + 2 * pad, total_h + 2 * pad};
Rectangle lb_box = {x, yy, lw, bh};
Rectangle box = {x + lw + 2 * s, yy, bw, bh};
Expand Down
8 changes: 6 additions & 2 deletions src/w_levels.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ static void LevelsUpdateLayout(Ui* ui) {
int screen_width = GetScreenWidth();
int screen_height = GetScreenHeight();

int h = 8;
int h = 9;
int bsize = 35 * s;

int box_w = bsize * 12;
int list_w = bsize * 5;
int total_w = list_w + box_w + 2 * s;
int x0 = (screen_width - total_w) / 2;
int total_h = (h + 2) * bsize;
int pad = 8 * s;
while (total_h + 2 * pad + 10 > screen_height) {
total_h -= bsize;
h -= 1;
}
int y0 = (screen_height - total_h) / 2;
C.title = (Rectangle){x0, y0, total_w, 35 * 2};
int pad = 8 * s;
C.modal = (Rectangle){
x0 - pad,
y0 - pad,
Expand Down
26 changes: 10 additions & 16 deletions src/w_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void MainInit(Ui* ui) {
}

void MainUpdate(Ui* ui) {
MainCheckWindowResize(ui);
MainUpdateViewport(ui);
MainCheckFileDrop();
MsgUpdate();
C.mouse_on_target = false;
Expand Down Expand Up @@ -597,14 +597,17 @@ void MainUpdateViewport(Ui* ui) {
.x = pad + 42 * scale + tt,
.y = C.header_size + 2 * scale + tt,
};
if (C.img_target_tex.texture.width > 0) {
UnloadRenderTexture(C.img_target_tex);
UnloadRenderTexture(C.level_overlay_tex);
}
int tgt_size_x = sw - C.target_pos.x - pad - tt - 8 * scale - 35 * scale;
int tgt_size_y = sh - C.bottom_size - C.header_size - tt;
C.img_target_tex = LoadRenderTexture(tgt_size_x, tgt_size_y);
C.level_overlay_tex = LoadRenderTexture(tgt_size_x, tgt_size_y);
if (tgt_size_x != C.img_target_tex.texture.width ||
tgt_size_y != C.img_target_tex.texture.height) {
if (C.img_target_tex.texture.width > 0) {
UnloadRenderTexture(C.img_target_tex);
UnloadRenderTexture(C.level_overlay_tex);
}
C.img_target_tex = LoadRenderTexture(tgt_size_x, tgt_size_y);
C.level_overlay_tex = LoadRenderTexture(tgt_size_x, tgt_size_y);
}

int s = ui->scale;
C.minimap.s = s;
Expand Down Expand Up @@ -815,15 +818,6 @@ void MainUpdateWidgets() {
}
}

void MainCheckWindowResize(Ui* ui) {
bool needs_update_viewport = C.img_target_tex.texture.width == 0;
if (IsWindowResized() || needs_update_viewport) {
MainUpdateViewport(ui);
RectangleInt r = MainGetTargetRegion();
PaintSetViewport(&C.ca, r.x, r.y, r.width, r.height);
}
}

void MainNewFile(Ui* ui) {
if (C.fname) {
free(C.fname);
Expand Down

0 comments on commit 127a023

Please sign in to comment.