Skip to content

Commit

Permalink
Add zoom buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-graj committed Aug 22, 2022
1 parent 4bd0b94 commit 15402d0
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 28 deletions.
31 changes: 27 additions & 4 deletions res/ui/ui.glade
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,6 @@
<object class="GtkToggleToolButton" id="play">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">toolbutton</property>
<property name="use-underline">True</property>
<property name="icon-name">media-playback-start</property>
<property name="active">True</property>
Expand Down Expand Up @@ -1354,7 +1353,6 @@
<object class="GtkToolButton" id="decelerate">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">__glade_unnamed_11</property>
<property name="use-underline">True</property>
<property name="icon-name">media-seek-backward</property>
<signal name="clicked" handler="on_decelerate_clicked" swapped="no"/>
Expand Down Expand Up @@ -1386,7 +1384,6 @@
<object class="GtkToolButton" id="accelerate">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">__glade_unnamed_13</property>
<property name="use-underline">True</property>
<property name="icon-name">media-seek-forward</property>
<signal name="clicked" handler="on_accelerate_clicked" swapped="no"/>
Expand All @@ -1406,6 +1403,32 @@
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="zoom_out">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="icon-name">zoom-out</property>
<signal name="clicked" handler="on_zoom_out_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="zoom_in">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="icon-name">zoom-in</property>
<signal name="clicked" handler="on_zoom_in_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkSeparatorToolItem">
<property name="visible">True</property>
Expand Down Expand Up @@ -1435,7 +1458,7 @@
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
Expand Down
4 changes: 2 additions & 2 deletions src/gfx/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "perf.h"
#include "render.h"
#include "thread.h"
#include "timemgr.h"
#include "toolbar.h"

struct GLCtx e_gl_ctx;
static GtkGLArea *glarea;
Expand Down Expand Up @@ -67,7 +67,7 @@ gboolean on_glarea_render(GtkGLArea *area, GdkGLContext *context, gpointer user_
thread_dispatch(THRD_PHYS, NULL);
satellites_tic();
render_process();
timemgr_tic();
toolbar_tic();
info_tic();
perf_tic();
thread_join(THRD_PHYS);
Expand Down
3 changes: 2 additions & 1 deletion src/phys/phys.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
#include "setting.h"
#include "system.h"
#include "thread.h"
#include "timemgr.h"

enum Timeflow e_timeflow = TIME_REALTIME;
float e_timescale = 1.f;
struct PhysCtx e_phys;
static gint64 epoch_ms;
static struct PhysCtx phys_ctx_sync;
Expand Down
8 changes: 8 additions & 0 deletions src/phys/phys.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ struct PhysCtx {
vec3 sun_dir;
};

enum Timeflow {
TIME_REALTIME = 0u,
TIME_PAUSE,
TIME_ARBITRARY,
};

extern enum Timeflow e_timeflow;
extern float e_timescale;
extern struct PhysCtx e_phys;

void phys_init(void);
Expand Down
30 changes: 25 additions & 5 deletions src/ui/timemgr.c → src/ui/toolbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
* GNU General Public License for more details.
**/

#include "timemgr.h"
#include "toolbar.h"

#include "camera.h"
#include "phys.h"
#include "setting.h"
#include "system.h"

#include <stdio.h>

enum Timeflow e_timeflow = TIME_REALTIME;
float e_timescale = 1.f;
#define ZOOM_DIST 0.2

static GtkToggleToolButton *play_button;
static GtkEntry *time_entry;
Expand All @@ -31,6 +31,8 @@ static void on_play_toggled(GtkToggleToolButton *toggle_tool_button, gpointer us
static void on_realtime_clicked(GtkToolButton *toolbutton, gpointer user_data);
static void on_decelerate_clicked(GtkToolButton *toolbutton, gpointer user_data);
static void on_accelerate_clicked(GtkToolButton *toolbutton, gpointer user_data);
static void on_zoom_out_clicked(GtkToolButton *toolbutton, gpointer user_data);
static void on_zoom_in_clicked(GtkToolButton *toolbutton, gpointer user_data);
static void on_time_activate(GtkEntry *entry, gpointer user_data);
static void on_speed_activate(GtkEntry *entry, gpointer user_data);
static void timeflow_set(enum Timeflow timeflow);
Expand Down Expand Up @@ -70,6 +72,22 @@ void on_accelerate_clicked(GtkToolButton *toolbutton, gpointer user_data)
e_timescale *= 1.05f;
}

static void on_zoom_out_clicked(GtkToolButton *toolbutton, gpointer user_data)
{
(void)toolbutton;
(void)user_data;

camera_zoom(&e_camera, -ZOOM_DIST);
}

static void on_zoom_in_clicked(GtkToolButton *toolbutton, gpointer user_data)
{
(void)toolbutton;
(void)user_data;

camera_zoom(&e_camera, ZOOM_DIST);
}

void on_time_activate(GtkEntry *entry, gpointer user_data)
{
(void)entry;
Expand Down Expand Up @@ -111,7 +129,7 @@ void timeflow_set(enum Timeflow timeflow)
gtk_toggle_tool_button_set_active(play_button, (timeflow == TIME_PAUSE) ? FALSE : TRUE);
}

void timemgr_init(GtkBuilder *builder)
void toolbar_init(GtkBuilder *builder)
{
gtk_builder_add_callback_symbols(builder,
"on_play_toggled", G_CALLBACK(on_play_toggled),
Expand All @@ -120,13 +138,15 @@ void timemgr_init(GtkBuilder *builder)
"on_accelerate_clicked", G_CALLBACK(on_accelerate_clicked),
"on_time_activate", G_CALLBACK(on_time_activate),
"on_speed_activate", G_CALLBACK(on_speed_activate),
"on_zoom_in_clicked", G_CALLBACK(on_zoom_in_clicked),
"on_zoom_out_clicked", G_CALLBACK(on_zoom_out_clicked),
NULL);
play_button = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "play"));
time_entry = GTK_ENTRY(gtk_builder_get_object(builder, "time"));
speed_entry = GTK_ENTRY(gtk_builder_get_object(builder, "speed"));
}

void timemgr_tic(void)
void toolbar_tic(void)
{
if (!gtk_widget_has_focus(GTK_WIDGET(time_entry)))
gtk_entry_set_text(time_entry, epoch_to_iso8601(e_phys.epoch_ms, gs_gmt, TRUE));
Expand Down
19 changes: 5 additions & 14 deletions src/ui/timemgr.h → src/ui/toolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,12 @@
* GNU General Public License for more details.
**/

#ifndef __TIMEMGR_H__
#define __TIMEMGR_H__
#ifndef __TOOLBAR_H__
#define __TOOLBAR_H__

#include "ui.h"

enum Timeflow {
TIME_REALTIME = 0u,
TIME_PAUSE,
TIME_ARBITRARY,
};
void toolbar_init(GtkBuilder *builder);
void toolbar_tic(void);

extern enum Timeflow e_timeflow;
extern float e_timescale;

void timemgr_init(GtkBuilder *builder);
void timemgr_tic(void);

#endif /* __TIMEMGR_H__ */
#endif /* __TOOLBAR_H__ */
4 changes: 2 additions & 2 deletions src/ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "status.h"
#include "system.h"
#include "thread.h"
#include "timemgr.h"
#include "toolbar.h"

const gchar *FILENAME_GUI = "res/ui/ui.glade";

Expand Down Expand Up @@ -79,7 +79,7 @@ void ui_init(int argc, char ***argv)
gfx_init(builder);
input_init(builder);
status_init(builder);
timemgr_init(builder);
toolbar_init(builder);
catalog_init(builder);
setting_init(builder);
info_init(builder);
Expand Down

0 comments on commit 15402d0

Please sign in to comment.