Began to implement dual/multiple view

This commit is contained in:
Moritz Lipp 2011-03-18 18:40:20 +01:00
parent 6689a3422a
commit dd97387715
8 changed files with 110 additions and 61 deletions

View File

@ -46,9 +46,10 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
return; return;
} }
// FIXME
/* get current adjustment values */ /* get current adjustment values */
gdouble lower = gtk_adjustment_get_value(adjustment); /*gdouble lower = gtk_adjustment_get_value(adjustment);*/
gdouble upper = lower + gtk_adjustment_get_page_size(adjustment); /*gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);*/
/* find page that fits */ /* find page that fits */
for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++)
@ -60,14 +61,16 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
continue; continue;
} }
double begin = page->offset; /*double begin = page->offset;*/
double end = page->offset + page->height; /*double end = page->offset + page->height;*/
if ( ( (begin >= lower) && (end <= upper) ) /* page is in viewport */ /*if ( ( (begin >= lower) && (end <= upper) ) [> page is in viewport <]*/
|| ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */ /*|| ( (begin <= lower) && (end >= lower) && (end <= upper) ) [> end of the page is in viewport <]*/
|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */ /*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/
) { /*) {*/
if (page_id < 5) {
render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]); render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]);
} }
/*}*/
} }
} }

View File

@ -18,7 +18,9 @@ config_load_default(void)
/* zathura settings */ /* zathura settings */
int_value = 10; int_value = 10;
girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL); girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL);
int_value = 2;
girara_setting_add(Zathura.UI.session, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL);
/* define default shortcuts */ /* define default shortcuts */
girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL);

View File

@ -239,16 +239,12 @@ zathura_document_open(const char* path, const char* password)
goto error_free; goto error_free;
} }
double offset = 0;
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) {
zathura_page_t* page = zathura_page_get(document, page_id); zathura_page_t* page = zathura_page_get(document, page_id);
if (!page) { if (!page) {
goto error_free; goto error_free;
} }
page->offset = offset;
offset += page->height;
document->pages[page_id] = page; document->pages[page_id] = page;
} }
@ -389,8 +385,9 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id)
zathura_page_t* page = document->functions.page_get(document, page_id); zathura_page_t* page = document->functions.page_get(document, page_id);
if (page) { if (page) {
page->number = page_id; page->number = page_id;
page->rendered = false; page->rendered = false;
page->event_box = gtk_event_box_new();
g_static_mutex_init(&(page->lock)); g_static_mutex_init(&(page->lock));
} }

View File

@ -142,11 +142,11 @@ typedef struct zathura_page_s
{ {
double height; /**> Page height */ double height; /**> Page height */
double width; /**> Page width */ double width; /**> Page width */
double offset; /**> Page offset */
unsigned int number; /**> Page number */ unsigned int number; /**> Page number */
zathura_document_t* document; /**> Document */ zathura_document_t* document; /**> Document */
void* data; /**> Custom data */ void* data; /**> Custom data */
bool rendered; /**> Page has been rendered */ bool rendered; /**> Page has been rendered */
GtkWidget* event_box; /**> Widget wrapper */
GStaticMutex lock; /**> Lock */ GStaticMutex lock; /**> Lock */
} zathura_page_t; } zathura_page_t;

View File

@ -20,10 +20,8 @@ render_job(void* data)
girara_list_remove(render_thread->list, page); girara_list_remove(render_thread->list, page);
g_mutex_unlock(render_thread->lock); g_mutex_unlock(render_thread->lock);
gdk_threads_enter();
render(page); render(page);
printf("Rendered %d\n", page->number); printf("Rendered %d\n", page->number);
gdk_threads_leave();
} }
return NULL; return NULL;
@ -131,48 +129,33 @@ render_page(render_thread_t* render_thread, zathura_page_t* page)
bool bool
render(zathura_page_t* page) render(zathura_page_t* page)
{ {
gdk_threads_enter();
g_static_mutex_lock(&(page->lock)); g_static_mutex_lock(&(page->lock));
zathura_image_buffer_t* buffer = zathura_page_render(page); zathura_image_buffer_t* buffer = zathura_page_render(page);
if (!buffer) { if (!buffer) {
g_static_mutex_unlock(&(page->lock)); g_static_mutex_unlock(&(page->lock));
printf("error: rendering failed\n"); printf("error: rendering failed\n");
gdk_threads_leave();
return false; return false;
} }
/* add new page */ /* create drawing area */
GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); /*GtkWidget* drawing_area = gtk_drawing_area_new();*/
GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page->number);
g_list_free(list);
if (!widget) { /*[> remove old image <]*/
g_static_mutex_unlock(&(page->lock)); /*GtkWidget* widget = gtk_bin_get_child(GTK_BIN(page->event_box));*/
printf("error: page container does not exist\n"); /*if (widget != NULL) {*/
// TODO: zathura_image_buffer_free(image); /*g_object_unref(widget);*/
return false; /*}*/
}
/* child packaging information */ /*[> set new image <]*/
gboolean expand; /*gtk_box_pack_start(GTK_BOX(page->event_box), drawing_area, TRUE, TRUE, 0);*/
gboolean fill;
guint padding;
GtkPackType pack_type;
gtk_box_query_child_packing(GTK_BOX(Zathura.UI.page_view), widget, &expand, &fill, &padding, &pack_type); zathura_image_buffer_free(buffer);
/* delete old widget */
gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget);
/* add new widget */
// TODO: gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0);
/* set old packaging values */
// TODO: gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type);
/* reorder child */
// TODO: gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number);
g_static_mutex_unlock(&(page->lock)); g_static_mutex_unlock(&(page->lock));
gdk_threads_leave();
return true; return true;
} }

View File

@ -88,9 +88,10 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t)
unsigned int number_of_pages = Zathura.document->number_of_pages; unsigned int number_of_pages = Zathura.document->number_of_pages;
if (t > 0 && t <= number_of_pages) { if (t > 0 && t <= number_of_pages) {
GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); // TODO: Calculate offset
unsigned int offset = Zathura.document->pages[t - 1]->offset * Zathura.document->scale; /*GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view));*/
gtk_adjustment_set_value(adjustment, offset); /*unsigned int offset = Zathura.document->pages[t - 1]->offset * Zathura.document->scale;*/
/*gtk_adjustment_set_value(adjustment, offset);*/
} }
} }

View File

@ -100,19 +100,14 @@ document_open(const char* path, const char* password)
Zathura.document = document; Zathura.document = document;
/* create blank pages */ /* init view */
for (unsigned int i = 0; i < document->number_of_pages; i++) create_blank_pages();
{
/* create blank page */
GtkWidget* image = page_blank(document->pages[i]->width, document->pages[i]->height);
if (!image) { /* view mode */
goto error_free; int* value = girara_setting_get(Zathura.UI.session, "pages-per-row");
} int pages_per_row = (value) ? *value : 1;
free(value);
/* pack to page view */ page_view_set_mode(pages_per_row);
gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 1);
}
girara_set_view(Zathura.UI.session, Zathura.UI.page_view); girara_set_view(Zathura.UI.session, Zathura.UI.page_view);
@ -190,6 +185,62 @@ error_out:
return false; return false;
} }
void
page_view_set_mode(unsigned int pages_per_row)
{
gdk_threads_enter();
/* empty page view */
GList* container = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view));
for (GList* child = container; child; child = g_list_next(child)) {
gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), child->data);
}
GtkWidget* row = NULL;
/* create blank pages */
for (unsigned int i = 0; i < Zathura.document->number_of_pages; i++)
{
if (i % pages_per_row == 0) {
row = gtk_hbox_new(FALSE, 0);
}
/* pack row */
gtk_box_pack_start(GTK_BOX(row), Zathura.document->pages[i]->event_box, FALSE, FALSE, 1);
/* pack row to page view */
if ((i + 1) % pages_per_row == 0) {
gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), row, FALSE, FALSE, 1);
}
}
gtk_widget_show_all(Zathura.UI.page_view);
gdk_threads_leave();
}
void
create_blank_pages()
{
/* create blank pages */
for (unsigned int i = 0; i < Zathura.document->number_of_pages; i++)
{
zathura_page_t* page = Zathura.document->pages[i];
g_static_mutex_lock(&(page->lock));
/* create blank page */
GtkWidget* image = page_blank(page->width, page->height);
if (!image) {
g_static_mutex_unlock(&(page->lock));
continue;
}
/* pack to page view */
gtk_container_add(GTK_CONTAINER(page->event_box), image);
g_static_mutex_unlock(&(page->lock));
}
}
/* main function */ /* main function */
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {

View File

@ -80,4 +80,16 @@ bool document_close();
*/ */
bool page_set(unsigned int page_id); bool page_set(unsigned int page_id);
/**
* Builds the box structure to show the rendered pages
*
* @param pages_per_row Number of shown pages per row
*/
void page_view_set_mode(unsigned int pages_per_row);
/**
* Create blank pages
*/
void create_blank_pages();
#endif // ZATHURA_H #endif // ZATHURA_H