Improve preview positioning
This commit is contained in:
parent
207aabf16a
commit
70f8ddbada
|
@ -23,7 +23,7 @@
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child type="overlay">
|
<child type="overlay">
|
||||||
<object class="GtkBox">
|
<object class="GtkBox" id="top-box">
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="halign">fill</property>
|
<property name="halign">fill</property>
|
||||||
<property name="valign">start</property>
|
<property name="valign">start</property>
|
||||||
|
@ -95,7 +95,7 @@
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child type="overlay">
|
<child type="overlay">
|
||||||
<object class="GtkBox">
|
<object class="GtkBox" id="bottom-box">
|
||||||
<property name="orientation">horizontal</property>
|
<property name="orientation">horizontal</property>
|
||||||
<property name="halign">fill</property>
|
<property name="halign">fill</property>
|
||||||
<property name="valign">end</property>
|
<property name="valign">end</property>
|
||||||
|
|
19
src/main.c
19
src/main.c
|
@ -67,6 +67,8 @@ GtkWidget *open_last_stack;
|
||||||
GtkWidget *thumb_last;
|
GtkWidget *thumb_last;
|
||||||
GtkWidget *process_spinner;
|
GtkWidget *process_spinner;
|
||||||
GtkWidget *scanned_codes;
|
GtkWidget *scanned_codes;
|
||||||
|
GtkWidget *preview_top_box;
|
||||||
|
GtkWidget *preview_bottom_box;
|
||||||
|
|
||||||
int
|
int
|
||||||
remap(int value, int input_min, int input_max, int output_min, int output_max)
|
remap(int value, int input_min, int input_max, int output_min, int output_max)
|
||||||
|
@ -289,13 +291,24 @@ preview_realize(GtkGLArea *area)
|
||||||
static void
|
static void
|
||||||
position_preview(float *offset_x, float *offset_y, float *size_x, float *size_y)
|
position_preview(float *offset_x, float *offset_y, float *size_x, float *size_y)
|
||||||
{
|
{
|
||||||
|
int scale = gtk_widget_get_scale_factor(preview);
|
||||||
|
int preview_height = gtk_widget_get_allocated_height(preview) * scale;
|
||||||
|
int top_height = gtk_widget_get_allocated_height(preview_top_box) * scale;
|
||||||
|
int bottom_height = gtk_widget_get_allocated_height(preview_bottom_box) * scale;
|
||||||
|
int inner_height = preview_height - top_height - bottom_height;
|
||||||
|
|
||||||
double ratio = preview_buffer_height / (double)preview_buffer_width;
|
double ratio = preview_buffer_height / (double)preview_buffer_width;
|
||||||
|
|
||||||
*offset_x = 0;
|
*offset_x = 0;
|
||||||
*offset_y = 0;
|
|
||||||
*size_x = preview_width;
|
*size_x = preview_width;
|
||||||
*size_y = preview_width * ratio;
|
*size_y = preview_width * ratio;
|
||||||
|
|
||||||
|
if (*size_y > inner_height) {
|
||||||
|
*offset_y = (preview_height - *size_y) / 2.0;
|
||||||
|
} else {
|
||||||
|
*offset_y = top_height + (inner_height - *size_y) / 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -760,6 +773,8 @@ activate(GtkApplication *app, gpointer data)
|
||||||
thumb_last = GTK_WIDGET(gtk_builder_get_object(builder, "thumb_last"));
|
thumb_last = GTK_WIDGET(gtk_builder_get_object(builder, "thumb_last"));
|
||||||
process_spinner = GTK_WIDGET(gtk_builder_get_object(builder, "process_spinner"));
|
process_spinner = GTK_WIDGET(gtk_builder_get_object(builder, "process_spinner"));
|
||||||
scanned_codes = GTK_WIDGET(gtk_builder_get_object(builder, "scanned-codes"));
|
scanned_codes = GTK_WIDGET(gtk_builder_get_object(builder, "scanned-codes"));
|
||||||
|
preview_top_box = GTK_WIDGET(gtk_builder_get_object(builder, "top-box"));
|
||||||
|
preview_bottom_box = GTK_WIDGET(gtk_builder_get_object(builder, "bottom-box"));
|
||||||
|
|
||||||
g_signal_connect(window, "realize", G_CALLBACK(on_realize), NULL);
|
g_signal_connect(window, "realize", G_CALLBACK(on_realize), NULL);
|
||||||
|
|
||||||
|
@ -775,7 +790,7 @@ activate(GtkApplication *app, gpointer data)
|
||||||
|
|
||||||
// Setup actions
|
// Setup actions
|
||||||
create_simple_action(app, "capture", G_CALLBACK(run_capture_action));
|
create_simple_action(app, "capture", G_CALLBACK(run_capture_action));
|
||||||
create_simple_action(app, "camera-switch", G_CALLBACK(run_camera_switch_action));
|
create_simple_action(app, "switch-camera", G_CALLBACK(run_camera_switch_action));
|
||||||
create_simple_action(app, "open-settings", G_CALLBACK(run_open_settings_action));
|
create_simple_action(app, "open-settings", G_CALLBACK(run_open_settings_action));
|
||||||
create_simple_action(app, "close-settings", G_CALLBACK(run_close_settings_action));
|
create_simple_action(app, "close-settings", G_CALLBACK(run_close_settings_action));
|
||||||
create_simple_action(app, "open-last", G_CALLBACK(run_open_last_action));
|
create_simple_action(app, "open-last", G_CALLBACK(run_open_last_action));
|
||||||
|
|
Loading…
Reference in New Issue