Fix incorrect canvas scroll sizes and margins
This commit is contained in:
parent
bd8fc3f7d4
commit
53d52f0fe3
@ -150,7 +150,7 @@
|
|||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="hadjustment">canvas_horiz</property>
|
<property name="hadjustment">canvas_horiz</property>
|
||||||
<property name="vadjustment">canvas_vert</property>
|
<property name="vadjustment">canvas_vert</property>
|
||||||
<property name="min_content_width">300</property>
|
<property name="min_content_width">400</property>
|
||||||
<property name="min_content_height">300</property>
|
<property name="min_content_height">300</property>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
|
40
src/main.c
40
src/main.c
@ -38,7 +38,7 @@ __attribute__((noreturn)) void wd_fatal_error(int status, const char *message) {
|
|||||||
#define DEFAULT_ZOOM 0.1
|
#define DEFAULT_ZOOM 0.1
|
||||||
#define MIN_ZOOM (1./1000.)
|
#define MIN_ZOOM (1./1000.)
|
||||||
#define MAX_ZOOM 1000.
|
#define MAX_ZOOM 1000.
|
||||||
#define CANVAS_MARGIN 100
|
#define CANVAS_MARGIN 40
|
||||||
|
|
||||||
static const char *MODE_PREFIX = "mode";
|
static const char *MODE_PREFIX = "mode";
|
||||||
static const char *TRANSFORM_PREFIX = "transform";
|
static const char *TRANSFORM_PREFIX = "transform";
|
||||||
@ -201,6 +201,10 @@ static void update_scroll_size(struct wd_state *state) {
|
|||||||
gtk_adjustment_set_page_increment(scroll_y_adj, state->render.viewport_height);
|
gtk_adjustment_set_page_increment(scroll_y_adj, state->render.viewport_height);
|
||||||
gtk_adjustment_set_step_increment(scroll_x_adj, state->render.viewport_width / 10);
|
gtk_adjustment_set_step_increment(scroll_x_adj, state->render.viewport_width / 10);
|
||||||
gtk_adjustment_set_step_increment(scroll_y_adj, state->render.viewport_height / 10);
|
gtk_adjustment_set_step_increment(scroll_y_adj, state->render.viewport_height / 10);
|
||||||
|
double x = gtk_adjustment_get_value(scroll_x_adj);
|
||||||
|
double y = gtk_adjustment_get_value(scroll_y_adj);
|
||||||
|
gtk_adjustment_set_value(scroll_x_adj, MIN(x, scroll_x_upper));
|
||||||
|
gtk_adjustment_set_value(scroll_y_adj, MIN(y, scroll_y_upper));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -212,26 +216,28 @@ static void update_canvas_size(struct wd_state *state) {
|
|||||||
int ymin = 0;
|
int ymin = 0;
|
||||||
int ymax = 0;
|
int ymax = 0;
|
||||||
|
|
||||||
struct wd_head *head;
|
g_autoptr(GList) forms = gtk_container_get_children(GTK_CONTAINER(state->stack));
|
||||||
wl_list_for_each(head, &state->heads, link) {
|
for (GList *form_iter = forms; form_iter != NULL; form_iter = form_iter->next) {
|
||||||
int w = head->custom_mode.width;
|
GtkBuilder *builder = GTK_BUILDER(g_object_get_data(G_OBJECT(form_iter->data), "builder"));
|
||||||
int h = head->custom_mode.height;
|
gboolean enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "enabled")));
|
||||||
if (head->enabled && head->mode != NULL) {
|
if (enabled) {
|
||||||
w = head->mode->width;
|
int x1 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "pos_x")));
|
||||||
h = head->mode->height;
|
int y1 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "pos_y")));
|
||||||
|
int w = gtk_spin_button_get_value(GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "width")));
|
||||||
|
int h = gtk_spin_button_get_value(GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "height")));
|
||||||
|
int x2 = x1 + w;
|
||||||
|
int y2 = y1 + w;
|
||||||
|
double scale = gtk_spin_button_get_value(GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "scale")));
|
||||||
|
if (scale > 0.) {
|
||||||
|
w /= scale;
|
||||||
|
h /= scale;
|
||||||
}
|
}
|
||||||
if (head->scale > 0.) {
|
xmin = MIN(xmin, x1);
|
||||||
w /= head->scale;
|
|
||||||
h /= head->scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x2 = head->x + w;
|
|
||||||
int y2 = head->y + h;
|
|
||||||
xmin = MIN(xmin, head->x);
|
|
||||||
xmax = MAX(xmax, x2);
|
xmax = MAX(xmax, x2);
|
||||||
ymin = MIN(ymin, head->y);
|
ymin = MIN(ymin, y1);
|
||||||
ymax = MAX(ymax, y2);
|
ymax = MAX(ymax, y2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// update canvas sizings
|
// update canvas sizings
|
||||||
state->render.x_origin = floor(xmin * state->zoom) - CANVAS_MARGIN;
|
state->render.x_origin = floor(xmin * state->zoom) - CANVAS_MARGIN;
|
||||||
state->render.y_origin = floor(ymin * state->zoom) - CANVAS_MARGIN;
|
state->render.y_origin = floor(ymin * state->zoom) - CANVAS_MARGIN;
|
||||||
|
@ -29,8 +29,6 @@
|
|||||||
#include <epoxy/gl.h>
|
#include <epoxy/gl.h>
|
||||||
#include <wayland-util.h>
|
#include <wayland-util.h>
|
||||||
|
|
||||||
#define CANVAS_MARGIN 100
|
|
||||||
|
|
||||||
#define BT_UV_VERT_SIZE (2 + 2)
|
#define BT_UV_VERT_SIZE (2 + 2)
|
||||||
#define BT_UV_QUAD_SIZE (6 * BT_UV_VERT_SIZE)
|
#define BT_UV_QUAD_SIZE (6 * BT_UV_VERT_SIZE)
|
||||||
#define BT_UV_MAX (BT_COLOR_QUAD_SIZE * HEADS_MAX)
|
#define BT_UV_MAX (BT_COLOR_QUAD_SIZE * HEADS_MAX)
|
||||||
|
Loading…
Reference in New Issue
Block a user