cepheid

An Aurora 4X clone
Log | Files | Refs | README

commit b5b3c6139f452b95dee5ff6a271322e7b5925a05
parent 8d0163a8ba5dfc998b7a73ae8b8c938ef3d683fa
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 21 Nov 2022 13:37:00 +0000

Move views into own "namespace" (and (re)init properly)

Diffstat:
Msrc/main.c | 10+++++-----
Msrc/main.h | 49+++++++++++++++++++++++++++----------------------
Msrc/save.c | 6++++--
Msrc/struct.h | 18+++++++++---------
Msrc/ui.c | 90-------------------------------------------------------------------------------
Asrc/views.c | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/views/bodies.c | 17+++++++++--------
Msrc/views/main.c | 167++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/views/smenu.c | 10+++++-----
Msrc/views/struct.h | 2--
Msrc/views/sys.c | 6+++---
11 files changed, 251 insertions(+), 224 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -11,7 +11,7 @@ Save *save = NULL; int sigint = 0; int sigterm = 0; int quit = 0; -int view_before_smenu = UI_VIEW_MAIN; +int view_before_smenu = VIEW_MAIN; void error(int code, char *fmt, ...) { @@ -75,7 +75,7 @@ main(void) { while (ui_loop()) { if (IsKeyPressed(KEY_ESCAPE)) - view_tabs.sel = UI_VIEW_SMENU; + view_tabs.sel = VIEW_SMENU; if (save && (IsKeyDown(KEY_LEFT_ALT) || IsKeyDown(KEY_RIGHT_ALT))) { /* AAAAAAAAAAHHHHHHHHHHHH. WHY NOT JUST USE KEY_1, KEY_2..! */ @@ -87,12 +87,12 @@ main(void) { else if (IsKeyPressed(KEY_SIX)) view_tabs.sel = 6; } - view_handlers[view_tabs.sel](view_prev != view_tabs.sel); + view_handle[view_tabs.sel](view_prev != view_tabs.sel); BeginDrawing(); ClearBackground(col_bg); - view_drawers[view_tabs.sel](); - if (view_tabs.sel != UI_VIEW_SMENU) { + view_draw[view_tabs.sel](); + if (view_tabs.sel != VIEW_SMENU) { ui_draw_views(); view_before_smenu = view_tabs.sel; } diff --git a/src/main.h b/src/main.h @@ -69,8 +69,6 @@ void tree_sort_sideways(Tree *t, Treecompar compar, void *cdata); void tree_sort(Tree *t, Treecompar compar, void *cdata); /* ui.c */ -#define VIEWS_MAX_WIDTH (UI_VIEW_LAST*100) -#define VIEWS_HEIGHT 25 #define WINDOW_TAB_HEIGHT 20 #define TARGET_FPS 60 #define WINDOW_BORDER 2 @@ -84,9 +82,6 @@ void tree_sort(Tree *t, Treecompar compar, void *cdata); #define EXPLODE_RECT(g) g.x, g.y, g.w, g.h #define EXPLODE_CIRCLE(g) g.centre.x, g.centre.y, g.r #define EXPLODE_CIRCLEV(g) g.centre, g.r -extern Tabs view_tabs; -extern void (*view_handlers[UI_VIEW_LAST])(int); -extern void (*view_drawers[UI_VIEW_LAST])(void); extern Screen screen; extern Focus focus; extern Mouse mouse; @@ -119,16 +114,8 @@ void ui_draw_circle(int x, int y, float r, Color col); void ui_draw_line(int sx, int sy, int ex, int ey, float thick, Color col); void ui_draw_line_v(Vector start, Vector end, float thick, Color col); void ui_draw_tabbed_window(int x, int y, int w, int h, Tabs *tabs); -Vector ui_vectordiff(Vector a, Vector b); +Vector ui_vectordiff(Vector a, Vector b); 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_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_settings(void); /* gui.c */ #define BUTTON_HEIGHT (PAD + FONT_SIZE) @@ -143,25 +130,43 @@ int gui_input_next(Input *in); /* if inputs are contained in an array, this .one void gui_input_clear(Input *in); void gui_treeview(int x, int y, int w, int h, Treeview *tv); +/* views.c */ +#define VIEWS_MAX_WIDTH (VIEW_LAST*100) +#define VIEWS_HEIGHT 25 +extern void (*view_init[VIEW_LAST])(void); +extern void (*view_handle[VIEW_LAST])(int); +extern void (*view_draw[VIEW_LAST])(void); +extern Tabs view_tabs; +void view_colonies_handle(int nowsel); +void view_fleets_handle(int nowsel); +void view_design_handle(int nowsel); +void view_settings_handle(int nowsel); +void view_colonies_draw(void); +void view_fleets_draw(void); +void view_design_draw(void); +void view_settings_draw(void); + /* views/main.c */ extern View_main view_main; -void ui_handle_view_main(int nowsel); -void ui_draw_view_main(void); +void view_main_init(void); +void view_main_handle(int nowsel); +void view_main_draw(void); /* views/bodies.c */ extern View_bodies view_bodies; -void ui_handle_view_bodies(int nowsel); -void ui_draw_view_bodies(void); +void view_bodies_init(void); +void view_bodies_handle(int nowsel); +void view_bodies_draw(void); /* views/sys.c */ extern View_sys view_sys; -void ui_handle_view_sys(int nowsel); -void ui_draw_view_sys(void); +void view_sys_handle(int nowsel); +void view_sys_draw(void); /* views/smenu.c */ extern View_smenu view_smenu; -void ui_handle_view_smenu(int nowsel); -void ui_draw_view_smenu(void); +void view_smenu_handle(int nowsel); +void view_smenu_draw(void); void checkbeforequit(void); /* pane.c */ diff --git a/src/save.c b/src/save.c @@ -20,6 +20,7 @@ void save_read(char *name) { char dir[PATH_MAX]; char *str; + int i; if (save) save_free(); @@ -41,8 +42,9 @@ save_read(char *name) { if ((str = dbget(save->db.dir, "index", "homesystem"))) save->homesys = sys_get(str); - view_main.sys = NULL; - view_main.sys = sys_default(); + for (i = 0; i < VIEW_LAST; i++) + if (view_init[i]) + view_init[i](); return; }; diff --git a/src/struct.h b/src/struct.h @@ -242,15 +242,15 @@ typedef struct { } Focus; enum UiViews { - UI_VIEW_SMENU, - UI_VIEW_MAIN, - UI_VIEW_COLONIES, - UI_VIEW_BODIES, - UI_VIEW_FLEETS, - UI_VIEW_DESIGN, - UI_VIEW_SYSTEMS, - UI_VIEW_SETTINGS, - UI_VIEW_LAST + VIEW_SMENU, + VIEW_MAIN, + VIEW_COLONIES, + VIEW_BODIES, + VIEW_FLEETS, + VIEW_DESIGN, + VIEW_SYSTEMS, + VIEW_SETTINGS, + VIEW_LAST }; #define CLICKABLE_MAX 64 diff --git a/src/ui.c b/src/ui.c @@ -6,47 +6,9 @@ #include <wchar.h> #include "main.h" -void (*view_handlers[UI_VIEW_LAST])(int) = { - [UI_VIEW_SMENU] = ui_handle_view_smenu, - [UI_VIEW_MAIN] = ui_handle_view_main, - [UI_VIEW_COLONIES] = ui_handle_view_colonies, - [UI_VIEW_BODIES] = ui_handle_view_bodies, - [UI_VIEW_FLEETS] = ui_handle_view_fleets, - [UI_VIEW_DESIGN] = ui_handle_view_design, - [UI_VIEW_SYSTEMS] = ui_handle_view_sys, - [UI_VIEW_SETTINGS] = ui_handle_view_settings, -}; - -void (*view_drawers[UI_VIEW_LAST])(void) = { - [UI_VIEW_SMENU] = ui_draw_view_smenu, - [UI_VIEW_MAIN] = ui_draw_view_main, - [UI_VIEW_COLONIES] = ui_draw_view_colonies, - [UI_VIEW_BODIES] = ui_draw_view_bodies, - [UI_VIEW_FLEETS] = ui_draw_view_fleets, - [UI_VIEW_DESIGN] = ui_draw_view_design, - [UI_VIEW_SYSTEMS] = ui_draw_view_sys, - [UI_VIEW_SETTINGS] = ui_draw_view_settings, -}; - Screen screen = { 0 }; Focus focus = { 0 }; Mouse mouse = { 0 }; - -Tabs view_tabs = { - /* Tactical is the terminology used in Aurora, so I decided to use it - * in the ui; in the code it's just called 'main' for my fingers' sake */ - UI_VIEW_LAST, 0, { - {&image_burger, NULL, VIEWS_HEIGHT}, - {&image_tactical, "Tactical", 0}, - {&image_colonies, "Colonies", 0}, - {&image_bodies, "Bodies", 0}, - {&image_fleet, "Fleets", 0}, - {&image_design, "Design", 0}, - {&image_sys, "Systems", 0}, - {&image_settings, "Settings", 0}, - } -}; - int charpx; /* thank god for monospaced fonts */ void @@ -362,55 +324,3 @@ ui_draw_tabbed_window(int x, int y, int w, int h, Tabs *tabs) { gui_tabs(x, y, w, WINDOW_TAB_HEIGHT, tabs); ui_draw_border(x, y, w, h, WINDOW_BORDER); } - -void -ui_handle_view_colonies(int nowsel) { - if (nowsel) - ui_title("Colonies"); -} - -void -ui_handle_view_fleets(int nowsel) { - if (nowsel) - ui_title("Fleets"); -} - -void -ui_handle_view_design(int nowsel) { - if (nowsel) - ui_title("Design"); -} - -void -ui_handle_view_settings(int nowsel) { - if (nowsel) - ui_title("Settings"); -} - -void -ui_draw_view_colonies(void) { - ui_print(PAD, VIEWS_HEIGHT + PAD, col_fg, "Stars/colonies here"); - ui_print(GetScreenWidth() / 2, VIEWS_HEIGHT + PAD, col_fg, "Tabs here"); - ui_print(GetScreenWidth() / 2, GetScreenHeight() / 2, col_fg, "Management stuff here"); -} - - -void -ui_draw_view_fleets(void) { - ui_print(PAD, VIEWS_HEIGHT + PAD, col_fg, "Groups/fleets/subfleets/ships here"); - ui_print(GetScreenWidth() / 2, VIEWS_HEIGHT + PAD, col_fg, "Tabs here"); - ui_print(GetScreenWidth() / 2, GetScreenHeight() / 2, col_fg, "Management stuff here"); -} - -void -ui_draw_view_design(void) { - ui_print(PAD, VIEWS_HEIGHT + PAD, col_fg, "Designations/classes here"); - ui_print(GetScreenWidth() / 4, VIEWS_HEIGHT + PAD, col_fg, "Selectable components here"); - ui_print((GetScreenWidth() / 4) * 2, VIEWS_HEIGHT + PAD, col_fg, "Selected components"); - ui_print((GetScreenWidth() / 4) * 3, VIEWS_HEIGHT + PAD, col_fg, "Class info"); -} - -void -ui_draw_view_settings(void) { - ui_print(PAD, VIEWS_HEIGHT + PAD, col_fg, "Settings here"); -} diff --git a/src/views.c b/src/views.c @@ -0,0 +1,100 @@ +#include "main.h" + +void (*view_init[VIEW_LAST])(void) = { + [VIEW_MAIN] = view_main_init, + [VIEW_COLONIES] = NULL, + [VIEW_BODIES] = NULL, + [VIEW_FLEETS] = NULL, + [VIEW_DESIGN] = NULL, + [VIEW_SYSTEMS] = NULL, + [VIEW_SETTINGS] = NULL, +}; + +void (*view_handle[VIEW_LAST])(int) = { + [VIEW_SMENU] = view_smenu_handle, + [VIEW_MAIN] = view_main_handle, + [VIEW_COLONIES] = view_colonies_handle, + [VIEW_BODIES] = view_bodies_handle, + [VIEW_FLEETS] = view_fleets_handle, + [VIEW_DESIGN] = view_design_handle, + [VIEW_SYSTEMS] = view_sys_handle, + [VIEW_SETTINGS] = view_settings_handle, +}; + +void (*view_draw[VIEW_LAST])(void) = { + [VIEW_SMENU] = view_smenu_draw, + [VIEW_MAIN] = view_main_draw, + [VIEW_COLONIES] = view_colonies_draw, + [VIEW_BODIES] = view_bodies_draw, + [VIEW_FLEETS] = view_fleets_draw, + [VIEW_DESIGN] = view_design_draw, + [VIEW_SYSTEMS] = view_sys_draw, + [VIEW_SETTINGS] = view_settings_draw, +}; + +Tabs view_tabs = { + /* Tactical is the terminology used in Aurora, so I decided to use it + * in the ui; in the code it's just called 'main' for my fingers' sake */ + VIEW_LAST, 0, { + {&image_burger, NULL, VIEWS_HEIGHT}, + {&image_tactical, "Tactical", 0}, + {&image_colonies, "Colonies", 0}, + {&image_bodies, "Bodies", 0}, + {&image_fleet, "Fleets", 0}, + {&image_design, "Design", 0}, + {&image_sys, "Systems", 0}, + {&image_settings, "Settings", 0}, + } +}; + +void +view_colonies_handle(int nowsel) { + if (nowsel) + ui_title("Colonies"); +} + +void +view_fleets_handle(int nowsel) { + if (nowsel) + ui_title("Fleets"); +} + +void +view_design_handle(int nowsel) { + if (nowsel) + ui_title("Design"); +} + +void +view_settings_handle(int nowsel) { + if (nowsel) + ui_title("Settings"); +} + +void +view_colonies_draw(void) { + ui_print(PAD, VIEWS_HEIGHT + PAD, col_fg, "Stars/colonies here"); + ui_print(GetScreenWidth() / 2, VIEWS_HEIGHT + PAD, col_fg, "Tabs here"); + ui_print(GetScreenWidth() / 2, GetScreenHeight() / 2, col_fg, "Management stuff here"); +} + + +void +view_fleets_draw(void) { + ui_print(PAD, VIEWS_HEIGHT + PAD, col_fg, "Groups/fleets/subfleets/ships here"); + ui_print(GetScreenWidth() / 2, VIEWS_HEIGHT + PAD, col_fg, "Tabs here"); + ui_print(GetScreenWidth() / 2, GetScreenHeight() / 2, col_fg, "Management stuff here"); +} + +void +view_design_draw(void) { + ui_print(PAD, VIEWS_HEIGHT + PAD, col_fg, "Designations/classes here"); + ui_print(GetScreenWidth() / 4, VIEWS_HEIGHT + PAD, col_fg, "Selectable components here"); + ui_print((GetScreenWidth() / 4) * 2, VIEWS_HEIGHT + PAD, col_fg, "Selected components"); + ui_print((GetScreenWidth() / 4) * 3, VIEWS_HEIGHT + PAD, col_fg, "Class info"); +} + +void +view_settings_draw(void) { + ui_print(PAD, VIEWS_HEIGHT + PAD, col_fg, "Settings here"); +} diff --git a/src/views/bodies.c b/src/views/bodies.c @@ -11,8 +11,6 @@ static void tree_printer(int x, int y, Treeview *tv, Tree *t); static View_bodies *v = &view_bodies; View_bodies view_bodies = { - .sys = NULL, - .selstar = NULL, .sel = NULL, .show = { .planet = {1, 1, "Show planets"}, @@ -32,6 +30,13 @@ View_bodies view_bodies = { } }; +void +view_bodies_init(void) { + v->sel = NULL; + v->tree.t = NULL; + v->tree.sel = NULL; +} + static int tree_filter(Tree *t, void *data) { Body *b; @@ -79,25 +84,21 @@ tree_printer(int x, int y, Treeview *tv, Tree *t) { } void -ui_handle_view_bodies(int nowsel) { +view_bodies_handle(int nowsel) { v->prevframe.sel = v->sel; - if (!v->sys) - v->sys = sys_default(); - if (!nowsel) { if (v->tree.sel) v->sel = v->tree.sel->data; else v->sel = NULL; } else { - ui_title("Bodies in %s", v->sys->name); v->tree.t = &save->systems; } } void -ui_draw_view_bodies(void) { +view_bodies_draw(void) { int x, y; v->disp = RECT(PAD, VIEWS_HEIGHT + FONT_SIZE, diff --git a/src/views/main.c b/src/views/main.c @@ -10,6 +10,7 @@ static float min_body_rad[] = { [BODY_MOON] = 1, }; +static View_main *v = &view_main; View_main view_main = { .infobox = { .tabs = { @@ -51,67 +52,77 @@ View_main view_main = { .sys = NULL, }; +void +view_main_init(void) { + v->kmx = v->kmy = 0; + v->kmperpx = 500000; + + /* since sys_default() checks this value, set it to NULL first */ + v->sys = NULL; + v->sys = sys_default(); +} + Vector kmtopx(Vector km) { return (Vector) { - (screen.w / 2) + (km.x - view_main.kmx) / view_main.kmperpx, - (screen.h / 2) + (km.y - view_main.kmy) / view_main.kmperpx + (screen.w / 2) + (km.x - v->kmx) / v->kmperpx, + (screen.h / 2) + (km.y - v->kmy) / v->kmperpx }; } Vector pxtokm(Vector vector) { return (Vector) { - ((vector.x - screen.w / 2) * view_main.kmperpx) + view_main.kmx, - ((vector.y - screen.h / 2) * view_main.kmperpx) + view_main.kmy + ((vector.x - screen.w / 2) * v->kmperpx) + v->kmx, + ((vector.y - screen.h / 2) * v->kmperpx) + v->kmy }; } void -ui_handle_view_main(int nowsel) { +view_main_handle(int nowsel) { float wheel = mouse.scroll; float diff; Body *furth; - if (view_main.sys) - furth = view_main.sys->furthest_body; + if (v->sys) + furth = v->sys->furthest_body; #define SCROLL_DIVISOR 10 - if (!ui_collides(view_main.infobox.geom, mouse.vector)) { + if (!ui_collides(v->infobox.geom, mouse.vector)) { if (wheel) { - diff = wheel * (view_main.kmperpx/SCROLL_DIVISOR); - if (diff > 0 || !furth || view_main.kmperpx * screen.h < + diff = wheel * (v->kmperpx/SCROLL_DIVISOR); + if (diff > 0 || !furth || v->kmperpx * screen.h < 2 * (furth->type == BODY_COMET ? furth->maxdist : furth->dist)) { - view_main.kmperpx -= diff; - view_main.kmx += (mouse.x - screen.w / 2) * diff; - view_main.kmy += (mouse.y - screen.h / 2) * diff; + v->kmperpx -= diff; + v->kmx += (mouse.x - screen.w / 2) * diff; + v->kmy += (mouse.y - screen.h / 2) * diff; } } if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) { - if (view_main.pan) { - view_main.kmx -= mouse.delta.x * view_main.kmperpx; - view_main.kmy -= mouse.delta.y * view_main.kmperpx; - } else if (!ui_collides(view_main.infobox.geom, mouse.vector)) { - view_main.pan = 1; + if (v->pan) { + v->kmx -= mouse.delta.x * v->kmperpx; + v->kmy -= mouse.delta.y * v->kmperpx; + } else if (!ui_collides(v->infobox.geom, mouse.vector)) { + v->pan = 1; } } else { - view_main.pan = 0; + v->pan = 0; } - if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT) && !view_main.ruler.held) { - view_main.ruler.held = 1; - view_main.ruler.origin = pxtokm(mouse.vector); + if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT) && !v->ruler.held) { + v->ruler.held = 1; + v->ruler.origin = pxtokm(mouse.vector); } else if (IsMouseButtonUp(MOUSE_BUTTON_RIGHT)) { - view_main.ruler.held = 0; + v->ruler.held = 0; } } if (nowsel) - ui_title("Tactical: %s", view_main.sys->name); + ui_title("Tactical: %s", v->sys->name); - view_main.infobox.names.dwarfn.enabled = view_main.infobox.names.dwarf.val; - view_main.infobox.names.asteroidn.enabled = view_main.infobox.names.asteroid.val; + v->infobox.names.dwarfn.enabled = v->infobox.names.dwarf.val; + v->infobox.names.asteroidn.enabled = v->infobox.names.asteroid.val; } static int @@ -131,13 +142,13 @@ draw_orbit(Body *body) { if (!body->parent) return; if (!should_draw_body_checkbox(body, BODY_DWARF, - &view_main.infobox.orbit.dwarf)) + &v->infobox.orbit.dwarf)) return; if (!should_draw_body_checkbox(body, BODY_ASTEROID, - &view_main.infobox.orbit.asteroid)) + &v->infobox.orbit.asteroid)) return; if (!should_draw_body_checkbox(body, BODY_COMET, - &view_main.infobox.orbit.comet)) + &v->infobox.orbit.comet)) return; parent = kmtopx(body->parent->vector); @@ -160,19 +171,19 @@ draw_body(Body *body) { return; /* body */ - if (body->radius / view_main.kmperpx > min_body_rad[body->type]) - w = body->radius / view_main.kmperpx; + if (body->radius / v->kmperpx > min_body_rad[body->type]) + w = body->radius / v->kmperpx; else w = min_body_rad[body->type]; if (body->parent && body->type != BODY_COMET && - body->dist / view_main.kmperpx < + body->dist / v->kmperpx < min_body_rad[body->parent->type]) return; ui_draw_circle(body->pxloc.x, body->pxloc.y, w, col_body[body->type]); - if (body->type == BODY_COMET && view_main.infobox.comettail.val && - 10 * view_main.kmperpx < body->curdist) + if (body->type == BODY_COMET && v->infobox.comettail.val && + 10 * v->kmperpx < body->curdist) ui_draw_line_v(body->pxloc, vectorize_at(body->pxloc, (Polar){w * 11 / min_body_rad[BODY_COMET], body->inward ? body->theta : body->theta + 180}), @@ -181,28 +192,28 @@ draw_body(Body *body) { /* name */ if (body->type != BODY_STAR && (body->type == BODY_COMET ? body->maxdist : body->dist) - / view_main.kmperpx < ui_textsize(body->name)) + / v->kmperpx < ui_textsize(body->name)) return; if (body->parent && body->type != BODY_STAR && ui_vectordist(body->vector, body->parent->vector) < - min_body_rad[body->type] * view_main.kmperpx) + min_body_rad[body->type] * v->kmperpx) return; if (isdigit(*body->name) || *body->name == '(') { if (!should_draw_body_checkbox(body, BODY_DWARF, - &view_main.infobox.names.dwarfn)) + &v->infobox.names.dwarfn)) return; if (!should_draw_body_checkbox(body, BODY_ASTEROID, - &view_main.infobox.names.asteroidn)) + &v->infobox.names.asteroidn)) return; } if (!should_draw_body_checkbox(body, BODY_DWARF, - &view_main.infobox.names.dwarf)) + &v->infobox.names.dwarf)) return; if (!should_draw_body_checkbox(body, BODY_ASTEROID, - &view_main.infobox.names.asteroid)) + &v->infobox.names.asteroid)) return; if (!should_draw_body_checkbox(body, BODY_COMET, - &view_main.infobox.names.comet)) + &v->infobox.names.comet)) return; ui_print(body->pxloc.x + w + 2, body->pxloc.y + w + 2, @@ -210,7 +221,7 @@ draw_body(Body *body) { } void -ui_draw_view_main(void) { +view_main_draw(void) { Vector mousekm = pxtokm(mouse.vector); Vector ruler; Geom geom; @@ -222,65 +233,65 @@ ui_draw_view_main(void) { #ifdef DEBUG ui_print(screen.w / 2, VIEWS_HEIGHT + PAD, col_fg, "W: %f | H: %f", (float)screen.w, (float)screen.h); ui_print(screen.w / 2, VIEWS_HEIGHT + PAD * 2, col_fg, "Xoff: %f | Yoff: %f | km/px: %f", - view_main.kmx, view_main.kmy, view_main.kmperpx); + v->kmx, v->kmy, v->kmperpx); ui_print(screen.w / 2, VIEWS_HEIGHT + PAD * 3, col_fg, "X: %f | Y: %f", mousekm.x, mousekm.y); #endif /* DEBUG */ /* draw system bodies */ - for (t = view_main.sys->t->d; t; t = t->n) { + for (t = v->sys->t->d; t; t = t->n) { body = t->data; body->pxloc = kmtopx(body->vector); draw_orbit(body); } - for (t = view_main.sys->t->d; t; t = t->n) { + for (t = v->sys->t->d; t; t = t->n) { body = t->data; draw_body(body); } /* ruler */ - if (view_main.ruler.held) { - ruler = kmtopx(view_main.ruler.origin); + if (v->ruler.held) { + ruler = kmtopx(v->ruler.origin); ui_draw_line_v(ruler, mouse.vector, 1, col_info); - dist = ui_vectordist(view_main.ruler.origin, mousekm); + dist = ui_vectordist(v->ruler.origin, mousekm); ui_print(mouse.x + PAD, mouse.y - PAD, col_info, "%s (%s)", strkm(dist), strly(dist)); } /* scale */ - ui_draw_rect(view_main.scale.x, - screen.h - view_main.scale.y, - view_main.scale.w, 1, col_info); /* horizontal */ - ui_draw_rect(view_main.scale.x, - screen.h - view_main.scale.y - view_main.scale.h, - 1, view_main.scale.h, col_info); /* left vertical */ - ui_draw_rect(view_main.scale.x + view_main.scale.w, - screen.h - view_main.scale.y - view_main.scale.h, - 1, view_main.scale.h, col_info); /* right vertical */ - dist = view_main.scale.w * view_main.kmperpx; - ui_print(view_main.scale.x + view_main.scale.w + FONT_SIZE / 3, - screen.h - view_main.scale.y - FONT_SIZE / 2, + ui_draw_rect(v->scale.x, + screen.h - v->scale.y, + v->scale.w, 1, col_info); /* horizontal */ + ui_draw_rect(v->scale.x, + screen.h - v->scale.y - v->scale.h, + 1, v->scale.h, col_info); /* left vertical */ + ui_draw_rect(v->scale.x + v->scale.w, + screen.h - v->scale.y - v->scale.h, + 1, v->scale.h, col_info); /* right vertical */ + dist = v->scale.w * v->kmperpx; + ui_print(v->scale.x + v->scale.w + FONT_SIZE / 3, + screen.h - v->scale.y - FONT_SIZE / 2, col_info, "%s", strkm(dist)); /* infobox */ - ui_draw_tabbed_window(EXPLODE_RECT(view_main.infobox.geom), - &view_main.infobox.tabs); - x = view_main.infobox.geom.x + FONT_SIZE; - y = view_main.infobox.geom.y + WINDOW_TAB_HEIGHT; + ui_draw_tabbed_window(EXPLODE_RECT(v->infobox.geom), + &v->infobox.tabs); + x = v->infobox.geom.x + FONT_SIZE; + y = v->infobox.geom.y + WINDOW_TAB_HEIGHT; geom = RECT(x - FONT_SIZE, y, - view_main.infobox.geom.w - WINDOW_BORDER, - view_main.infobox.geom.h - WINDOW_TAB_HEIGHT - WINDOW_BORDER); - view_main.infobox.pane.geom = &geom; - - pane_begin(&view_main.infobox.pane); - gui_checkbox(x, y += FONT_SIZE*1.5, &view_main.infobox.names.dwarf); - gui_checkbox(x, y += FONT_SIZE*1.5, &view_main.infobox.names.dwarfn); - gui_checkbox(x, y += FONT_SIZE*1.5, &view_main.infobox.names.asteroid); - gui_checkbox(x, y += FONT_SIZE*1.5, &view_main.infobox.names.asteroidn); - gui_checkbox(x, y += FONT_SIZE*1.5, &view_main.infobox.names.comet); - gui_checkbox(x, y += FONT_SIZE*1.5, &view_main.infobox.orbit.dwarf); - gui_checkbox(x, y += FONT_SIZE*1.5, &view_main.infobox.orbit.asteroid); - gui_checkbox(x, y += FONT_SIZE*1.5, &view_main.infobox.orbit.comet); - gui_checkbox(x, y += FONT_SIZE*1.5, &view_main.infobox.comettail); + v->infobox.geom.w - WINDOW_BORDER, + v->infobox.geom.h - WINDOW_TAB_HEIGHT - WINDOW_BORDER); + v->infobox.pane.geom = &geom; + + pane_begin(&v->infobox.pane); + gui_checkbox(x, y += FONT_SIZE*1.5, &v->infobox.names.dwarf); + gui_checkbox(x, y += FONT_SIZE*1.5, &v->infobox.names.dwarfn); + gui_checkbox(x, y += FONT_SIZE*1.5, &v->infobox.names.asteroid); + gui_checkbox(x, y += FONT_SIZE*1.5, &v->infobox.names.asteroidn); + gui_checkbox(x, y += FONT_SIZE*1.5, &v->infobox.names.comet); + gui_checkbox(x, y += FONT_SIZE*1.5, &v->infobox.orbit.dwarf); + gui_checkbox(x, y += FONT_SIZE*1.5, &v->infobox.orbit.asteroid); + gui_checkbox(x, y += FONT_SIZE*1.5, &v->infobox.orbit.comet); + gui_checkbox(x, y += FONT_SIZE*1.5, &v->infobox.comettail); pane_end(); } diff --git a/src/views/smenu.c b/src/views/smenu.c @@ -144,7 +144,7 @@ newhandler_actual(Input *in) { save_create(v->new.name.str); save_read(v->new.name.str); loadadd(v->new.name.str, time(NULL)); - view_tabs.sel = UI_VIEW_MAIN; + view_tabs.sel = VIEW_MAIN; v->new.disp = 0; return 1; } @@ -173,7 +173,7 @@ loadhandler_actual(void) { l = v->load.savelist.sel->data; save_read(l->name); - view_tabs.sel = UI_VIEW_MAIN; + view_tabs.sel = VIEW_MAIN; v->load.disp = 0; return; } @@ -217,7 +217,7 @@ loadadd(char *dir, time_t mod) { void checkbeforequit(void) { if (save_changed()) { - view_tabs.sel = UI_VIEW_SMENU; + view_tabs.sel = VIEW_SMENU; savecheck("There are unsaved changes. Save before quitting?", quithandler); } else { quithandler(); @@ -245,7 +245,7 @@ loadinit(char *sdir) { } void -ui_handle_view_smenu(int nowsel) { +view_smenu_handle(int nowsel) { Tree *t; struct Loadable *cont, *l; @@ -279,7 +279,7 @@ ui_handle_view_smenu(int nowsel) { } void -ui_draw_view_smenu(void) { +view_smenu_draw(void) { Color bg = { col_bg.r, col_bg.g, col_bg.b, 0xcc }; int x, y, w, h; int i; diff --git a/src/views/struct.h b/src/views/struct.h @@ -36,8 +36,6 @@ typedef struct { /* bodies */ typedef struct { - System *sys; - Body *selstar; Body *sel; struct { Checkbox planet; diff --git a/src/views/sys.c b/src/views/sys.c @@ -7,7 +7,7 @@ View_sys view_sys = { .x = 0, .y = VIEWS_HEIGHT, .w = 300, - .h = 0, /* see ui_handle_view_sys() */ + .h = 0, /* see view_sys_handle() */ }, }, .pan = 0, @@ -20,7 +20,7 @@ View_sys view_sys = { }; void -ui_handle_view_sys(int nowsel) { +view_sys_handle(int nowsel) { if (nowsel) ui_title("Systems"); v->info.geom.h = screen.h - VIEWS_HEIGHT; @@ -31,7 +31,7 @@ ui_handle_view_sys(int nowsel) { #define SYSDIAM (100 * v->ly.topx) void -ui_draw_view_sys(void) { +view_sys_draw(void) { Tree *t; System *s; int x, y;