mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 18:03:47 +01:00
Fixed rendering
This commit is contained in:
parent
752ca8ec11
commit
5c5df5bf82
14
callbacks.c
14
callbacks.c
@ -44,7 +44,6 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME
|
||||
/* get current adjustment values */
|
||||
gdouble lower = gtk_adjustment_get_value(adjustment);
|
||||
gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);
|
||||
@ -54,11 +53,6 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
|
||||
{
|
||||
zathura_page_t* page = zathura->document->pages[page_id];
|
||||
|
||||
/* check for rendered attribute */
|
||||
if (page->surface != NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
page_offset_t* offset = page_calculate_offset(page);
|
||||
if (offset == NULL) {
|
||||
continue;
|
||||
@ -67,14 +61,14 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
|
||||
double begin = offset->y;
|
||||
double end = offset->y + page->height;
|
||||
|
||||
girara_info("%f %f; %f %f", begin, end, lower, upper);
|
||||
|
||||
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 >= upper) && (begin <= upper) ) /* [> begin of the page is in viewport <] */
|
||||
) {
|
||||
page->visible = true;
|
||||
render_page(zathura->sync.render_thread, page);
|
||||
if (page->surface == NULL) {
|
||||
render_page(zathura->sync.render_thread, page);
|
||||
}
|
||||
} else {
|
||||
page->visible = false;
|
||||
cairo_surface_destroy(page->surface);
|
||||
|
@ -404,6 +404,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id)
|
||||
page->surface = NULL;
|
||||
g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page);
|
||||
|
||||
gtk_widget_set_size_request(page->drawing_area, page->width * document->scale, page->height * document->scale);
|
||||
gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area);
|
||||
|
||||
g_static_mutex_init(&(page->lock));
|
||||
|
26
render.c
26
render.c
@ -24,8 +24,6 @@ render_job(void* data)
|
||||
if (render(render_thread->zathura, page) != true) {
|
||||
girara_error("Rendering failed\n");
|
||||
}
|
||||
|
||||
girara_info("rendered page %d\n", page->number);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -171,7 +169,6 @@ render(zathura_t* zathura, zathura_page_t* page)
|
||||
}
|
||||
|
||||
/* draw to gtk widget */
|
||||
girara_info("surface: %d %p", page->number, surface);
|
||||
page->surface = surface;
|
||||
gtk_widget_set_size_request(page->drawing_area, page_width, page_height);
|
||||
gtk_widget_queue_draw(page->drawing_area);
|
||||
@ -204,7 +201,6 @@ render_all(zathura_t* zathura)
|
||||
gboolean
|
||||
page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data)
|
||||
{
|
||||
girara_info("in expose");
|
||||
zathura_page_t* page = data;
|
||||
if (page == NULL) {
|
||||
return FALSE;
|
||||
@ -220,14 +216,28 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
girara_info("page->num %d page->surface: %p", page->number, page->surface);
|
||||
if (page->surface != NULL) {
|
||||
cairo_set_source_surface(cairo, page->surface, 0, 0);
|
||||
cairo_paint(cairo);
|
||||
} else {
|
||||
/* set background color */
|
||||
cairo_set_source_rgb(cairo, 255, 255, 255);
|
||||
cairo_rectangle(cairo, 0, 0, page->width * page->document->scale, page->height * page->document->scale);
|
||||
cairo_fill(cairo);
|
||||
|
||||
// cairo_surface_destroy(page->surface);
|
||||
// page->surface = NULL;
|
||||
} else if (page->visible) {
|
||||
/* write text */
|
||||
cairo_set_source_rgb(cairo, 0, 0, 0);
|
||||
const char* text = "Loading...";
|
||||
cairo_select_font_face(cairo, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
||||
cairo_set_font_size(cairo, 16.0);
|
||||
cairo_text_extents_t extents;
|
||||
cairo_text_extents(cairo, text, &extents);
|
||||
double x = (page->width * page->document->scale) / 2 - (extents.width / 2 + extents.x_bearing);
|
||||
double y = (page->height * page->document->scale) / 2 - (extents.height / 2 + extents.y_bearing);
|
||||
cairo_move_to(cairo, x, y);
|
||||
cairo_show_text(cairo, text);
|
||||
|
||||
/* render real page */
|
||||
render_page(page->document->zathura->sync.render_thread, page);
|
||||
}
|
||||
cairo_destroy(cairo);
|
||||
|
34
zathura.c
34
zathura.c
@ -112,8 +112,13 @@ zathura_init(int argc, char* argv[])
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
/* callbacks */
|
||||
GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
||||
g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura);
|
||||
GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
||||
g_signal_connect(G_OBJECT(view_hadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura);
|
||||
|
||||
gtk_widget_show(zathura->ui.page_view);
|
||||
gtk_box_set_spacing(GTK_BOX(zathura->ui.page_view), 0);
|
||||
|
||||
/* Put the table in the main window */
|
||||
// gtk_container_add(GTK_CONTAINER (zathura->ui.page_view), table);
|
||||
@ -139,9 +144,6 @@ zathura_init(int argc, char* argv[])
|
||||
/* signals */
|
||||
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL);
|
||||
|
||||
GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
||||
g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura);
|
||||
|
||||
/* girara events */
|
||||
zathura->ui.session->events.buffer_changed = buffer_changed;
|
||||
|
||||
@ -155,6 +157,9 @@ zathura_init(int argc, char* argv[])
|
||||
int* page_padding = girara_setting_get(zathura->ui.session, "page-padding");
|
||||
zathura->global.page_padding = (page_padding) ? *page_padding : 1;
|
||||
|
||||
gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding);
|
||||
gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding);
|
||||
|
||||
/* open document if passed */
|
||||
if (argc > 1) {
|
||||
zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t));
|
||||
@ -251,9 +256,10 @@ document_open(zathura_t* zathura, const char* path, const char* password)
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
/* first page */
|
||||
if (!page_set(zathura, 0)) {
|
||||
goto error_free;
|
||||
/* create blank pages */
|
||||
for (int page_id = 0; page_id < document->number_of_pages; page_id++) {
|
||||
zathura_page_t* page = document->pages[page_id];
|
||||
gtk_widget_realize(page->event_box);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -321,24 +327,12 @@ error_out:
|
||||
void
|
||||
page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row)
|
||||
{
|
||||
/* 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 */
|
||||
|
||||
|
||||
gtk_table_resize(GTK_TABLE(zathura->ui.page_view), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row);
|
||||
for (unsigned int i = 0; i < zathura->document->number_of_pages; i++)
|
||||
{
|
||||
int x = i % pages_per_row;
|
||||
int y = i / pages_per_row;
|
||||
girara_info("x, y, page: %d, %d, %d (%d)", x, y, i, pages_per_row);
|
||||
gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, zathura->global.page_padding, zathura->global.page_padding);
|
||||
gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
|
||||
}
|
||||
|
||||
gtk_widget_show_all(zathura->ui.page_view);
|
||||
|
Loading…
Reference in New Issue
Block a user