commit 0e0ba467caee941cd30b6b6a956019fa7208360c
parent e6f2e0819aa4045a81a2ee64ae29f71e11e9048a
Author: hhvn <dev@hhvn.uk>
Date: Fri, 18 Nov 2022 18:37:42 +0000
Move sys view to own file
Diffstat:
4 files changed, 85 insertions(+), 65 deletions(-)
diff --git a/src/main.h b/src/main.h
@@ -86,7 +86,6 @@ extern void (*view_drawers[UI_VIEW_LAST])(void);
extern Screen screen;
extern Focus focus;
extern Mouse mouse;
-extern View_sys view_sys;
extern int charpx;
void ui_init(void);
void ui_update_screen(void);
@@ -120,12 +119,10 @@ float ui_vectordist(Vector a, Vector b);
void ui_handle_view_colonies(int nowsel);
void ui_handle_view_fleets(int nowsel);
void ui_handle_view_design(int nowsel);
-void ui_handle_view_sys(int nowsel);
void ui_handle_view_settings(int nowsel);
void ui_draw_view_colonies(void);
void ui_draw_view_fleets(void);
void ui_draw_view_design(void);
-void ui_draw_view_sys(void);
void ui_draw_view_settings(void);
/* gui.c */
@@ -137,16 +134,21 @@ void gui_dropdown(int x, int y, int w, Dropdown *d);
void gui_input(int x, int y, int w, Input *in);
void gui_treeview(int x, int y, int w, int h, Treeview *tv);
-/* ui/main.c */
+/* views/main.c */
extern View_main view_main;
void ui_handle_view_main(int nowsel);
void ui_draw_view_main(void);
-/* ui/bodies.c */
+/* views/bodies.c */
extern View_bodies view_bodies;
void ui_handle_view_bodies(int nowsel);
void ui_draw_view_bodies(void);
+/* views/sys.c */
+extern View_sys view_sys;
+void ui_handle_view_sys(int nowsel);
+void ui_draw_view_sys(void);
+
/* pane.c */
void pane_begin(Pane *f);
void pane_end(void);
diff --git a/src/ui.c b/src/ui.c
@@ -42,24 +42,6 @@ Tabs view_tabs = {
{&image_settings, "Settings", 0}}
};
-View_sys view_sys = {
- .info = {
- .geom = {
- .x = 0,
- .y = VIEWS_HEIGHT,
- .w = 300,
- .h = 0, /* see ui_handle_view_sys() */
- },
- },
- .pan = 0,
- .off = {
- .x = 0,
- .y = 0,
- },
- .lytopx = 0.025,
- .sel = NULL,
-};
-
int charpx; /* thank god for monospaced fonts */
void
@@ -384,15 +366,6 @@ ui_handle_view_design(int nowsel) {
}
void
-ui_handle_view_sys(int nowsel) {
- if (nowsel)
- ui_title("Systems");
- view_sys.info.geom.h = GetScreenHeight() - VIEWS_HEIGHT;
- if (!view_sys.sel)
- view_sys.sel = sys_default();
-}
-
-void
ui_handle_view_settings(int nowsel) {
if (nowsel)
ui_title("Settings");
@@ -422,37 +395,6 @@ ui_draw_view_design(void) {
}
void
-ui_draw_view_sys(void) {
- int x, y;
-
- x = view_sys.info.geom.x + view_sys.info.geom.w;
- y = view_sys.info.geom.y;
-
- /* draw map */
-
- /* draw divider */
- ui_draw_line(x, y, x, y + view_sys.info.geom.h, 1, col_border);
-
- /* draw info */
- x = view_sys.info.geom.x + PAD;
- y += PAD;
- if (view_sys.sel) {
- ui_print(x, y, col_fg, "%s", view_sys.sel->name);
- ui_draw_line(x, y + FONT_SIZE, x + view_sys.info.geom.w - 20,
- y + FONT_SIZE, 1, col_border);
- y += 30;
- ui_print(x, y, col_fg, "Stars: %d", view_sys.sel->num.stars);
- ui_print(x, y + 10, col_fg, "Planets: %d", view_sys.sel->num.planets);
- ui_print(x, y + 20, col_fg, "Dwarfs: %d", view_sys.sel->num.dwarfs);
- ui_print(x, y + 30, col_fg, "Asteroids: %d", view_sys.sel->num.asteroids);
- ui_print(x, y + 40, col_fg, "Comets: %d", view_sys.sel->num.comets);
- ui_print(x, y + 50, col_fg, "Moons: %d", view_sys.sel->num.moons);
- ui_draw_line(x, y + 62, x + 85, y + 62, 1, col_fg);
- /* ui_print(x, y + 65, col_fg, "Total: %d", view_sys.sel->bodies_len); TODO: tree_count() */
- }
-}
-
-void
ui_draw_view_settings(void) {
ui_print(PAD, VIEWS_HEIGHT + PAD, col_fg, "Settings here");
}
diff --git a/src/views/struct.h b/src/views/struct.h
@@ -59,7 +59,9 @@ typedef struct {
Geom geom;
} info;
int pan;
- Vector off;
- float lytopx;
+ struct {
+ float x, y;
+ float topx;
+ } ly;
System *sel;
} View_sys;
diff --git a/src/views/sys.c b/src/views/sys.c
@@ -0,0 +1,74 @@
+#include "../main.h"
+
+static View_sys *v = &view_sys;
+View_sys view_sys = {
+ .info = {
+ .geom = {
+ .x = 0,
+ .y = VIEWS_HEIGHT,
+ .w = 300,
+ .h = 0, /* see ui_handle_view_sys() */
+ },
+ },
+ .pan = 0,
+ .ly = {
+ .x = 0,
+ .y = 0,
+ .topx = 0.05,
+ },
+ .sel = NULL,
+};
+
+void
+ui_handle_view_sys(int nowsel) {
+ if (nowsel)
+ ui_title("Systems");
+ v->info.geom.h = screen.h - VIEWS_HEIGHT;
+ if (!v->sel)
+ v->sel = sys_default();
+}
+
+#define SYSDIAM (100 * v->ly.topx)
+
+void
+ui_draw_view_sys(void) {
+ Tree *t;
+ System *s;
+ int x, y;
+ int cx, cy;
+
+ /* draw map */
+ x = v->info.geom.x + v->info.geom.w + screen.w / 2;
+ y = v->info.geom.y + screen.h / 2;
+ for (t = save->systems.d; t; t = t->n) {
+ s = t->data;
+ cx = x + s->lypos.x / v->ly.topx;
+ cy = y + s->lypos.y / v->ly.topx;
+ ui_draw_circle(cx, cy, SYSDIAM, col_fg);
+ }
+
+ x = v->info.geom.x;
+ y = v->info.geom.y;
+
+ /* draw divider */
+ ui_draw_line(x + v->info.geom.w, v->info.geom.y,
+ x + v->info.geom.w, screen.h, 1, col_border);
+
+ /* draw info */
+ x += PAD;
+ y += PAD;
+ if (v->sel) {
+ ui_print(x, y, col_fg, "%s", v->sel->name);
+ ui_draw_line(x, y + FONT_SIZE, x + v->info.geom.w - 20,
+ y + FONT_SIZE, 1, col_border);
+ y += 30;
+ ui_print(x, y, col_fg, "Stars: %d", v->sel->num.stars);
+ ui_print(x, y + 10, col_fg, "Planets: %d", v->sel->num.planets);
+ ui_print(x, y + 20, col_fg, "Dwarfs: %d", v->sel->num.dwarfs);
+ ui_print(x, y + 30, col_fg, "Asteroids: %d", v->sel->num.asteroids);
+ ui_print(x, y + 40, col_fg, "Comets: %d", v->sel->num.comets);
+ ui_print(x, y + 50, col_fg, "Moons: %d", v->sel->num.moons);
+ ui_draw_line(x, y + 62, x + 85, y + 62, 1, col_fg);
+ /* ui_print(x, y + 65, col_fg, "Total: %d", v->sel->bodies_len); TODO: tree_count() */
+ }
+}