aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-05-26 19:35:43 +0200
committerThomas White <taw@bitwiz.org.uk>2011-05-26 19:35:43 +0200
commit96605c925f243e88eeeb346dde95fb5a3066434f (patch)
treee23edbd19f8bca2a4f34f6d3dfd9fe4943cbed13 /src
parentbcbdceef6e1be59a6ca1d653b6a54bf9009b4143 (diff)
More clicky logic
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.c26
-rw-r--r--src/objects.c2
-rw-r--r--src/objects.h3
-rw-r--r--src/presentation.c20
-rw-r--r--src/presentation.h3
-rw-r--r--src/slide_render.c3
6 files changed, 46 insertions, 11 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 44fed9e..df5fd59 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -185,13 +185,29 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
struct presentation *p)
{
+ struct object *clicked;
+ gdouble x, y;
+
+ x = event->x - p->border_offs_x;
+ y = event->y - p->border_offs_y;
+
if ( p->editing_object && p->editing_object->empty ) {
delete_object(p->editing_object);
}
+ p->editing_object = NULL;
+
+ if ( (x>0.0) && (x<p->view_slide->slide_width)
+ && (y>0.0) && (y<p->view_slide->slide_height) )
+ {
+ clicked = find_object_at_position(p->view_slide, x, y);
+ if ( !clicked ) {
+ p->editing_object = add_text_object(p->view_slide,
+ x, y);
+ } else {
+ p->editing_object = clicked;
+ }
- p->editing_object = add_text_object(p->view_slide,
- event->x - p->border_offs_x,
- event->y - p->border_offs_y);
+ }
gtk_widget_grab_focus(GTK_WIDGET(da));
@@ -219,9 +235,7 @@ static void draw_editing_bits(cairo_t *cr, struct object *o)
case TEXT :
- draw_editing_box(cr, o->x - o->bb_width/2.0,
- o->y - o->bb_height/2.0,
- o->bb_width, o->bb_height);
+ draw_editing_box(cr, o->x, o->y, o->bb_width, o->bb_height);
break;
}
diff --git a/src/objects.c b/src/objects.c
index a91b737..372fac1 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -147,6 +147,8 @@ void handle_text_backspace(struct object *o)
o->insertion_point -= ndel;
+ if ( strlen(o->text) == 0 ) o->empty = 1;
+
o->parent->object_seq++;
}
diff --git a/src/objects.h b/src/objects.h
index 15f2618..7f4d39b 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -39,8 +39,7 @@ struct object
enum objtype type;
struct slide *parent;
- /* Position of object, the interpretation of which depends on
- * the type of the object */
+ /* Position of corner of object */
double x;
double y;
diff --git a/src/presentation.c b/src/presentation.c
index 38b50fc..e02f103 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -110,6 +110,26 @@ void remove_object_from_slide(struct slide *s, struct object *o)
}
+struct object *find_object_at_position(struct slide *s, double x, double y)
+{
+ int i;
+ struct object *o = NULL;
+
+ for ( i=0; i<s->num_objects; i++ ) {
+
+ if ( (x>s->objects[i]->x) && (y>s->objects[i]->y)
+ && (x<s->objects[i]->x+s->objects[i]->bb_width)
+ && (y<s->objects[i]->y+s->objects[i]->bb_height) )
+ {
+ o = s->objects[i];
+ }
+
+ }
+
+ return o;
+}
+
+
struct presentation *new_presentation()
{
struct presentation *new;
diff --git a/src/presentation.h b/src/presentation.h
index 528084d..28f324b 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -74,6 +74,7 @@ struct presentation
extern struct presentation *new_presentation(void);
extern int add_object_to_slide(struct slide *s, struct object *o);
extern void remove_object_from_slide(struct slide *s, struct object *o);
-
+extern struct object *find_object_at_position(struct slide *s,
+ double x, double y);
#endif /* PRESENTATION_H */
diff --git a/src/slide_render.c b/src/slide_render.c
index ab656be..cabf916 100644
--- a/src/slide_render.c
+++ b/src/slide_render.c
@@ -51,8 +51,7 @@ static void render_text_object(cairo_t *cr, struct object *o)
o->bb_width = width/PANGO_SCALE;
o->bb_height = height/PANGO_SCALE;
- cairo_move_to(cr, o->x - (width/PANGO_SCALE)/2.0,
- o->y - (height/PANGO_SCALE)/2.0);
+ cairo_move_to(cr, o->x, o->y);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
pango_cairo_show_layout(cr, l);