aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-11-29 09:43:01 +0100
committerThomas White <taw@physics.org>2017-11-29 09:43:01 +0100
commit8a37f2dc1a8421ba47e8f2d6332c5e5910d2249d (patch)
treeebcb51d0385010618022ca4b76456f7450c82b23
parent63eae9accbb9eb02ff22b3f33cf48c352d0f8902 (diff)
Scale the slide in the slide window
-rw-r--r--src/sc_editor.c30
-rw-r--r--src/sc_editor.h2
-rw-r--r--src/slide_window.c37
3 files changed, 48 insertions, 21 deletions
diff --git a/src/sc_editor.c b/src/sc_editor.c
index 15ac49b..7443781 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -172,6 +172,11 @@ static gboolean resize_sig(GtkWidget *widget, GdkEventConfigure *event,
cr = gdk_cairo_create(gtk_widget_get_window(widget));
pc = pango_cairo_create_context(cr);
+ if ( e->scale ) {
+ e->w = event->width;
+ e->h = event->height;
+ }
+
e->visible_height = event->height;
e->visible_width = event->width;
@@ -616,6 +621,10 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, SCEditor *e)
cairo_rectangle(cr, 0.0, 0.0, width, height);
cairo_fill(cr);
+ if ( e->scale ) {
+ cairo_scale(cr, (double)e->w/e->log_w, (double)e->h/e->log_h);
+ }
+
/* Contents */
cairo_translate(cr, -e->h_scroll_pos, -e->scroll_pos);
cairo_translate(cr, e->border_offs_x, e->border_offs_y);
@@ -1094,6 +1103,8 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
x = event->x - e->border_offs_x;
y = event->y - e->border_offs_y + e->scroll_pos;
+ x /= e->w/e->log_w;
+ y /= e->h/e->log_h;
shift = event->state & GDK_SHIFT_MASK;
if ( within_frame(e->selection, x, y) ) {
@@ -1136,8 +1147,8 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
find_cursor(clicked, x-fr->x, y-fr->y,
&e->cursor_para, &e->cursor_pos, &e->cursor_trail);
- e->start_corner_x = event->x - e->border_offs_x;
- e->start_corner_y = event->y - e->border_offs_y;
+ e->start_corner_x = x;
+ e->start_corner_y = y;
if ( event->type == GDK_2BUTTON_PRESS ) {
check_callback_click(e->cursor_frame, e->cursor_para);
@@ -1164,8 +1175,8 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
unset_selection(e);
if ( shift ) {
- e->start_corner_x = event->x - e->border_offs_x;
- e->start_corner_y = event->y - e->border_offs_y;
+ e->start_corner_x = x;
+ e->start_corner_y = y;
e->drag_status = DRAG_STATUS_COULD_DRAG;
e->drag_reason = DRAG_REASON_CREATE;
} else {
@@ -1210,6 +1221,8 @@ static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event,
x = event->x - e->border_offs_x;
y = event->y - e->border_offs_y + e->scroll_pos;
+ x /= e->w/e->log_w;
+ y /= e->h/e->log_h;
if ( e->drag_status == DRAG_STATUS_COULD_DRAG ) {
@@ -1343,6 +1356,8 @@ static gboolean button_release_sig(GtkWidget *da, GdkEventButton *event,
x = event->x - e->border_offs_x;
y = event->y - e->border_offs_y;
+ x /= e->w/e->log_w;
+ y /= e->h/e->log_h;
/* Not dragging? Then I don't care. */
if ( e->drag_status != DRAG_STATUS_DRAGGING ) return FALSE;
@@ -1962,6 +1977,12 @@ int sc_editor_get_num_paras(SCEditor *e)
}
+void sc_editor_set_scale(SCEditor *e, int scale)
+{
+ e->scale = scale;
+}
+
+
SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets,
PangoLanguage *lang, const char *storename)
{
@@ -1984,6 +2005,7 @@ SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets,
sceditor->cbl = NULL;
sceditor->scroll_pos = 0;
sceditor->flow = 0;
+ sceditor->scale = 0;
sceditor->lang = lang;
sceditor->para_highlight = 0;
diff --git a/src/sc_editor.h b/src/sc_editor.h
index 3c836a6..7efc03f 100644
--- a/src/sc_editor.h
+++ b/src/sc_editor.h
@@ -110,6 +110,7 @@ struct _sceditor
int visible_height;
int visible_width;
int flow;
+ int scale;
/* Pointers to the frame currently being edited */
struct frame *selection;
@@ -176,6 +177,7 @@ extern SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock **stylesheets,
extern void sc_editor_set_size(SCEditor *e, int w, int h);
extern void sc_editor_set_logical_size(SCEditor *e, double w, double h);
extern void sc_editor_set_flow(SCEditor *e, int flow);
+extern void sc_editor_set_scale(SCEditor *e, int scale);
extern void sc_editor_redraw(SCEditor *e);
extern void sc_editor_set_background(SCEditor *e, double r, double g, double b);
extern void sc_editor_set_slidenum(SCEditor *e, int slidenum);
diff --git a/src/slide_window.c b/src/slide_window.c
index 415caeb..9c14283 100644
--- a/src/slide_window.c
+++ b/src/slide_window.c
@@ -249,35 +249,38 @@ SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks,
sw->sceditor = sc_editor_new(ch, stylesheets, p->lang,
colloquium_get_imagestore(app));
sc_editor_set_slidenum(sw->sceditor, slide_number(sw->p, scblocks));
-
- scroll = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(sw->sceditor));
- gtk_window_set_focus(GTK_WINDOW(window), GTK_WIDGET(sw->sceditor));
+ sc_editor_set_scale(sw->sceditor, 1);
+
+// scroll = gtk_scrolled_window_new(NULL, NULL);
+// gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
+// GTK_POLICY_AUTOMATIC,
+// GTK_POLICY_AUTOMATIC);
+// gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(sw->sceditor));
+// gtk_window_set_focus(GTK_WINDOW(window), GTK_WIDGET(sw->sceditor));
g_signal_connect(G_OBJECT(sw->sceditor), "key-press-event",
G_CALLBACK(key_press_sig), sw);
/* Size of SCEditor surface in pixels */
/* FIXME: Somewhat arbitrary. Should come from slide itself */
- sc_editor_set_size(sw->sceditor, 1024, 768);
+// sc_editor_set_size(sw->sceditor, 1024, 768);
sc_editor_set_logical_size(sw->sceditor, 1024.0, 768.0);
- gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(scroll));
+ gtk_window_set_default_size(GTK_WINDOW(window), 1024.0, 768.0);
+
+ gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(sw->sceditor));
/* Default size */
- gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(scroll),
- 1024);
- gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scroll),
- 768);
+// gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(scroll),
+// 1024);
+// gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scroll),
+// 768);
gtk_window_set_resizable(GTK_WINDOW(sw->window), TRUE);
gtk_widget_show_all(window);
- gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(scroll),
- 100);
- gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scroll),
- 100);
+// gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(scroll),
+// 100);
+// gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scroll),
+// 100);
return sw;
}