summaryrefslogtreecommitdiff
path: root/src/ui.c
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2016-04-01 19:28:22 +0200
committerPaweł Redman <pawel.redman@gmail.com>2016-04-01 19:28:22 +0200
commit2a8925a8612b5e632b0dbaa762ce834ad61704a8 (patch)
treea39adf291a2bc9d5ce85ae1e728e39a681baadf0 /src/ui.c
parenta5677db21bee18f8e5b67ba2b0615403ebe6dc8a (diff)
Yee grid.
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c109
1 files changed, 72 insertions, 37 deletions
diff --git a/src/ui.c b/src/ui.c
index 4e2f791..72a7c7b 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -24,7 +24,7 @@ struct {
typedef struct {
phy_sim *sim;
- bool dragging;
+ bool dragging, selecting;
r_xsection_type xsection_type;
float xsection_frac;
bool select_valid;
@@ -143,27 +143,7 @@ void ui_infof(ui_window *uiw, const char *fmt, ...)
static void ui_simview_set_select(ui_simview *sv, vec2_t sel_2d)
{
- if (sel_2d[0] < 0.0f || sel_2d[0] > 1.0f ||
- sel_2d[1] < 0.0f || sel_2d[1] > 1.0f) {
- sv->select_valid = false;
- return;
- }
-
- switch (sv->xsection_type) {
- case XSECTION_XY:
- v3_set(sv->select, sel_2d[0], sel_2d[1], sv->xsection_frac);
- break;
-
- case XSECTION_XZ:
- v3_set(sv->select, sel_2d[0], sv->xsection_frac, sel_2d[1]);
- break;
- case XSECTION_YZ:
- v3_set(sv->select, sv->xsection_frac, sel_2d[0], sel_2d[1]);
- break;
- }
-
- sv->select_valid = true;
}
void ui_event_window(SDL_Event *event, ui_window *uiw)
@@ -192,22 +172,21 @@ void ui_event_window(SDL_Event *event, ui_window *uiw)
break;
case SDL_MOUSEBUTTONDOWN:
- if (event->button.button == SDL_BUTTON_LEFT &&
- event->button.y > sv->margin_top &&
- event->button.y < uiw->h - sv->margin_bottom)
- sv->dragging = true;
-
- if (event->button.button == SDL_BUTTON_RIGHT) {
- vec2_t sel_2d;
+ if (event->button.y > sv->margin_top &&
+ event->button.y < uiw->h - sv->margin_bottom) {
+ if (event->button.button == SDL_BUTTON_LEFT)
+ sv->dragging = true;
- v2_div_mst2(sel_2d, uiw->mouse, sv->tf_x2s);
- ui_simview_set_select(sv, sel_2d);
+ if (event->button.button == SDL_BUTTON_RIGHT)
+ sv->selecting = true;
}
break;
case SDL_MOUSEBUTTONUP:
if (event->button.button == SDL_BUTTON_LEFT)
sv->dragging = false;
+ else if (event->button.button == SDL_BUTTON_RIGHT)
+ sv->selecting = false;
break;
case SDL_MOUSEMOTION:
@@ -256,6 +235,14 @@ void ui_event_window(SDL_Event *event, ui_window *uiw)
case SDLK_p:
itc_chan_push(&sv->sim->ctl, PHY_CMD_RESUME, NULL);
break;
+
+ case SDLK_l:
+ itc_chan_push(&sv->sim->ctl, PHY_CMD_STEP, NULL);
+ break;
+
+ case SDLK_r:
+ itc_chan_push(&sv->sim->ctl, PHY_CMD_RESET, NULL);
+ break;
}
}
}
@@ -342,6 +329,38 @@ void ui_draw_simview_selection(ui_window *uiw)
phy_sim *sim = sv->sim;
vec2_t select_s;
+ if (sv->selecting)
+ {
+ vec2_t select_2d;
+
+ v2_div_mst2(select_2d, uiw->mouse, sv->tf_x2s);
+
+ if (select_2d[0] < 0.0f || select_2d[0] > 1.0f ||
+ select_2d[1] < 0.0f || select_2d[1] > 1.0f) {
+ sv->select_valid = false;
+ return;
+ }
+
+ switch (sv->xsection_type) {
+ case XSECTION_XY:
+ v3_set(sv->select,
+ select_2d[0], select_2d[1], sv->xsection_frac);
+ break;
+
+ case XSECTION_XZ:
+ v3_set(sv->select,
+ select_2d[0], sv->xsection_frac, select_2d[1]);
+ break;
+
+ case XSECTION_YZ:
+ v3_set(sv->select,
+ sv->xsection_frac, select_2d[0], select_2d[1]);
+ break;
+ }
+
+ sv->select_valid = true;
+ }
+
if (!sv->select_valid)
return;
@@ -377,6 +396,8 @@ void ui_draw_simview_bars(ui_window *uiw, float dt)
ui_simview *sv = &uiw->simview;
phy_sim *sim = sv->sim;
+ phy_field_em *field_em = sim->fields + 1;
+ phy_field_info *fi = &sim->field_info;
// upper
@@ -406,16 +427,30 @@ void ui_draw_simview_bars(ui_window *uiw, float dt)
if (sv->select_valid) {
size_t x, y, z, offs;
- sv->margin_bottom += 2 * theme.font_size;
+ sv->margin_bottom += 3 * theme.font_size;
- r_draw_rect(uiw->rw, 0, uiw->h - 3 * theme.font_size,
- uiw->w, 2 * theme.font_size, theme.color_main);
+ r_draw_rect(uiw->rw, 0, uiw->h - 4 * theme.font_size,
+ uiw->w, 3 * theme.font_size, theme.color_main);
- r_draw_text(uiw->rw, 0, uiw->h - theme.font_size,
- theme.font_size,
- va("x = [%f %f %f]", sv->select[0],
- sv->select[1], sv->select[2]),
+ x = sv->select[0] * fi->width;
+ y = sv->select[1] * fi->height;
+ z = sv->select[2] * fi->depth;
+ offs = z * fi->zstr + y * fi->ystr + x * fi->xstr;
+
+ r_draw_text(uiw->rw, 0, uiw->h - 4 * theme.font_size,
+ theme.font_size, va("x = [%zu %zu %zu]", x, y, z),
theme.color_text, 0);
+
+
+ r_draw_text(uiw->rw, 0, uiw->h - 3 * theme.font_size,
+ theme.font_size, va("E(x) = [%+E %+E %+E]",
+ field_em->E[offs], field_em->E[offs + 1],
+ field_em->E[offs + 2]), theme.color_text, 0);
+
+ r_draw_text(uiw->rw, 0, uiw->h - 2 * theme.font_size,
+ theme.font_size, va("H(x) = [%+E %+E %+E]",
+ field_em->H[offs], field_em->H[offs + 1],
+ field_em->H[offs + 2]), theme.color_text, 0);
}
}