Commit ca35db2d authored by Moritz Lipp's avatar Moritz Lipp
Browse files

Added drawing area

parent 890d6b32
......@@ -16,6 +16,35 @@ cb_destroy(GtkWidget* widget, gpointer data)
return TRUE;
}
gboolean
cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data)
{
// FIXME: Split up
zathura_page_t* page = zathura_page_get(Zathura.document, Zathura.document->current_page_number);
if(!page) {
goto error_out;
}
cairo_surface_t* surface = zathura_page_render(page);
if(!surface) {
zathura_page_free(page);
fprintf(stderr, "error: rendering failed\n");
goto error_out;
}
cairo_surface_destroy(surface);
zathura_page_free(page);
gtk_widget_set_size_request(Zathura.UI.drawing_area, page->width, page->height);
gtk_widget_queue_draw(Zathura.UI.drawing_area);
return true;
error_out:
return false;
}
void
buffer_changed(girara_session_t* session)
{
......
......@@ -7,6 +7,7 @@
#include <girara.h>
gboolean cb_destroy(GtkWidget* widget, gpointer data);
gboolean cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data);
void buffer_changed(girara_session_t* session);
#endif // CALLBACKS_H
......@@ -191,7 +191,7 @@ djvu_page_form_fields_get(zathura_page_t* page)
cairo_surface_t*
djvu_page_render(zathura_page_t* page)
{
if(Zathura.document || !page || !page->data || !page->document) {
if(!Zathura.document || !page || !page->data || !page->document) {
return NULL;
}
......
......@@ -245,7 +245,8 @@ pdf_page_form_fields_get(zathura_page_t* page)
cairo_surface_t*
pdf_page_render(zathura_page_t* page)
{
if(Zathura.document || !page || !page->data || !page->document) {
if(!Zathura.document || !page || !page->data || !page->document) {
printf("die\n");
return NULL;
}
......
......@@ -11,34 +11,49 @@ bool
init_zathura()
{
if(!(Zathura.UI.session = girara_session_create())) {
return false;
goto error_out;
}
if(!girara_session_init(Zathura.UI.session)) {
return false;
goto error_out;
}
Zathura.UI.statusbar.file = NULL;
Zathura.UI.statusbar.buffer = NULL;
Zathura.UI.statusbar.page_number = NULL;
Zathura.UI.drawing_area = NULL;
/* UI */
Zathura.UI.statusbar.file = girara_statusbar_item_add(Zathura.UI.session, TRUE, TRUE, TRUE, NULL);
if(!Zathura.UI.statusbar.file) {
girara_session_destroy(Zathura.UI.session);
return false;
goto error_free;
}
Zathura.UI.statusbar.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL);
if(!Zathura.UI.statusbar.buffer) {
girara_session_destroy(Zathura.UI.session);
return false;
goto error_free;
}
Zathura.UI.statusbar.page_number = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL);
if(!Zathura.UI.statusbar.page_number) {
girara_session_destroy(Zathura.UI.session);
return false;
goto error_free;
}
girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, "[No Name]");
Zathura.UI.drawing_area = gtk_drawing_area_new();
if(!Zathura.UI.drawing_area) {
goto error_free;
}
gtk_widget_show(Zathura.UI.drawing_area);
g_signal_connect(G_OBJECT(Zathura.UI.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL);
/* set view */
if(!girara_set_view(Zathura.UI.session, Zathura.UI.drawing_area)) {
goto error_free;
}
/* signals */
g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL);
......@@ -49,6 +64,18 @@ init_zathura()
config_load_default();
return true;
error_free:
if(Zathura.UI.drawing_area) {
g_object_unref(Zathura.UI.drawing_area);
}
girara_session_destroy(Zathura.UI.session);
error_out:
return false;
}
bool
......@@ -90,11 +117,11 @@ bool
page_set(unsigned int page_id)
{
if(!Zathura.document) {
return false;
goto error_out;
}
if(page_id >= Zathura.document->number_of_pages) {
return false;
goto error_out;
}
Zathura.document->current_page_number = page_id;
......@@ -104,6 +131,10 @@ page_set(unsigned int page_id)
g_free(page_number);
return true;
error_out:
return false;
}
/* main function */
......
......@@ -35,6 +35,8 @@ struct
girara_statusbar_item_t* file; /**> file statusbar entry */
girara_statusbar_item_t* page_number; /**> page number statusbar entry */
} statusbar;
GtkWidget *drawing_area;
} UI;
zathura_document_t* document; /**> The current document */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment