From 6e0616d35b3359ef6610696b1a0300cec809f0fb Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 13 Apr 2010 00:22:56 +0200 Subject: [PATCH] Draw marked area This commit draws an rectangle in the marked area. --- config.def.h | 1 + zathura.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/config.def.h b/config.def.h index e471ca3..6181d03 100644 --- a/config.def.h +++ b/config.def.h @@ -41,6 +41,7 @@ static const char recolor_darkcolor[] = "#353535"; static const char recolor_lightcolor[] = "#DBDBDB"; static const char search_highlight[] = "#9FBC00"; +static const char select_text[] = "#000000"; /* statusbar */ static const char DEFAULT_TEXT[] = "[No Name]"; diff --git a/zathura.c b/zathura.c index ba65abd..5948654 100644 --- a/zathura.c +++ b/zathura.c @@ -185,6 +185,7 @@ struct GdkColor recolor_darkcolor; GdkColor recolor_lightcolor; GdkColor search_highlight; + GdkColor select_text; PangoFontDescription *font; } Style; @@ -203,6 +204,12 @@ struct int adjust_mode; } Global; + struct + { + gdouble x; + gdouble y; + } SelectPoint; + struct { char* filename; @@ -250,6 +257,7 @@ struct GStaticMutex pdflib_lock; GStaticMutex pdf_obj_lock; GStaticMutex search_lock; + GStaticMutex select_lock; } Lock; struct @@ -408,6 +416,7 @@ init_zathura() g_static_mutex_init(&(Zathura.Lock.pdflib_lock)); g_static_mutex_init(&(Zathura.Lock.search_lock)); g_static_mutex_init(&(Zathura.Lock.pdf_obj_lock)); + g_static_mutex_init(&(Zathura.Lock.select_lock)); /* look */ gdk_color_parse(default_fgcolor, &(Zathura.Style.default_fg)); @@ -429,6 +438,7 @@ init_zathura() gdk_color_parse(recolor_darkcolor, &(Zathura.Style.recolor_darkcolor)); gdk_color_parse(recolor_lightcolor, &(Zathura.Style.recolor_lightcolor)); gdk_color_parse(search_highlight, &(Zathura.Style.search_highlight)); + gdk_color_parse(select_text, &(Zathura.Style.select_text)); Zathura.Style.font = pango_font_description_from_string(font); /* other */ @@ -3334,12 +3344,34 @@ cb_view_button_pressed(GtkWidget* widget, GdkEventButton* event, gpointer data) if(!Zathura.PDF.document) return FALSE; + /* clean page */ + draw(Zathura.PDF.page_number); + g_static_mutex_lock(&(Zathura.Lock.select_lock)); + Zathura.SelectPoint.x = event->x; + Zathura.SelectPoint.y = event->y; + g_static_mutex_unlock(&(Zathura.Lock.select_lock)); + return TRUE; } gboolean cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data) { + if(!Zathura.PDF.document) + return FALSE; + + g_static_mutex_lock(&(Zathura.Lock.select_lock)); + cairo_t *cairo = cairo_create(Zathura.PDF.surface); + cairo_set_source_rgba(cairo, Zathura.Style.select_text.red, Zathura.Style.select_text.green, + Zathura.Style.select_text.blue, TRANSPARENCY); + + cairo_rectangle(cairo, event->x, event->y, (Zathura.SelectPoint.x - event->x), + (Zathura.SelectPoint.y - event->y)); + cairo_fill(cairo); + g_static_mutex_unlock(&(Zathura.Lock.select_lock)); + gtk_widget_queue_draw(Zathura.UI.drawing_area); + + return TRUE; }