Beispiel #1
0
static void do_links(fz_link *link, int xofs, int yofs)
{
    fz_rect r;
    float x, y;

    x = ui.x;
    y = ui.y;

    xofs -= page_tex.x;
    yofs -= page_tex.y;

    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    while (link)
    {
        r = link->rect;
        fz_transform_rect(&r, &page_ctm);

        if (x >= xofs + r.x0 && x < xofs + r.x1 && y >= yofs + r.y0 && y < yofs + r.y1)
        {
            ui.hot = link;
            if (!ui.active && ui.down)
                ui.active = link;
        }

        if (ui.hot == link || showlinks)
        {
            if (ui.active == link && ui.hot == link)
                glColor4f(0, 0, 1, 0.4f);
            else if (ui.hot == link)
                glColor4f(0, 0, 1, 0.2f);
            else
                glColor4f(0, 0, 1, 0.1f);
            glRectf(xofs + r.x0, yofs + r.y0, xofs + r.x1, yofs + r.y1);
        }

        if (ui.active == link && !ui.down)
        {
            if (ui.hot == link)
            {
                if (fz_is_external_link(ctx, link->uri))
                    open_browser(link->uri);
                else
                {
                    jump_to_page(fz_resolve_link(ctx, doc, link->uri, NULL, NULL));
                    ui_needs_update = 1;
                }
            }
        }

        link = link->next;
    }

    glDisable(GL_BLEND);
}
Beispiel #2
0
static void do_links(fz_link *link, int xofs, int yofs)
{
	fz_rect r;
	float x, y;

	x = ui.x;
	y = ui.y;

	xofs -= page_tex.x;
	yofs -= page_tex.y;

	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);

	while (link)
	{
		r = link->rect;
		fz_transform_rect(&r, &page_ctm);

		if (x >= xofs + r.x0 && x < xofs + r.x1 && y >= yofs + r.y0 && y < yofs + r.y1)
		{
			ui.hot = link;
			if (!ui.active && ui.down)
				ui.active = link;
		}

		if (ui.hot == link || showlinks)
		{
			if (ui.active == link && ui.hot == link)
				glColor4f(0, 0, 1, 0.4f);
			else if (ui.hot == link)
				glColor4f(0, 0, 1, 0.2f);
			else
				glColor4f(0, 0, 1, 0.1f);
			glRectf(xofs + r.x0, yofs + r.y0, xofs + r.x1, yofs + r.y1);
		}

		if (ui.active == link && !ui.down)
		{
			if (ui.hot == link)
			{
				if (link->dest.kind == FZ_LINK_GOTO)
					jump_to_page(link->dest.ld.gotor.page);
				else if (link->dest.kind == FZ_LINK_URI)
					open_browser(link->dest.ld.uri.uri);
			}
			ui_needs_update = 1;
		}

		link = link->next;
	}

	glDisable(GL_BLEND);
}
Beispiel #3
0
static int do_outline_imp(fz_outline *node, int end, int x0, int x1, int x, int y)
{
	int h = 0;
	int p = currentpage;
	int n = end;

	while (node)
	{
		if (node->dest.kind == FZ_LINK_GOTO)
		{
			p = node->dest.ld.gotor.page;

			if (ui.x >= x0 && ui.x < x1 && ui.y >= y + h && ui.y < y + h + ui.lineheight)
			{
				ui.hot = node;
				if (!ui.active && ui.down)
				{
					ui.active = node;
					jump_to_page(p);
					ui_needs_update = 1; /* we changed the current page, so force a redraw */
				}
			}

			n = end;
			if (node->next && node->next->dest.kind == FZ_LINK_GOTO)
			{
				n = node->next->dest.ld.gotor.page;
			}
			if (currentpage == p || (currentpage > p && currentpage < n))
			{
				glColor4f(0.9f, 0.9f, 0.9f, 1.0f);
				glRectf(x0, y + h, x1, y + h + ui.lineheight);
			}
		}

		glColor4f(0, 0, 0, 1);
		ui_draw_string(ctx, x, y + h + ui.baseline, node->title);
		h += ui.lineheight;
		if (node->down)
			h += do_outline_imp(node->down, n, x0, x1, x + ui.lineheight, y + h);

		node = node->next;
	}
	return h;
}
Beispiel #4
0
static void do_app(void)
{
    if (ui.key == KEY_F4 && ui.mod == GLFW_MOD_ALT)
        quit();

    if (ui.down || ui.middle || ui.right || ui.key)
        showinfo = 0;

    if (!ui.focus && ui.key)
    {
        switch (ui.key)
        {
        case 'q':
            quit();
            break;
        case 'm':
            if (number == 0)
                push_history();
            else if (number > 0 && number < nelem(marks))
                marks[number] = currentpage;
            break;
        case 't':
            if (number == 0)
            {
                if (history_count > 0)
                    pop_history();
            }
            else if (number > 0 && number < nelem(marks))
            {
                jump_to_page(marks[number]);
            }
            break;
        case 'T':
            if (number == 0)
            {
                if (future_count > 0)
                    pop_future();
            }
            break;
        case 'N':
            search_dir = -1;
            if (search_hit_page == currentpage)
                search_page = currentpage + search_dir;
            else
                search_page = currentpage;
            if (search_page >= 0 && search_page < fz_count_pages(ctx, doc))
            {
                search_hit_page = -1;
                if (search_needle)
                    search_active = 1;
            }
            break;
        case 'n':
            search_dir = 1;
            if (search_hit_page == currentpage)
                search_page = currentpage + search_dir;
            else
                search_page = currentpage;
            if (search_page >= 0 && search_page < fz_count_pages(ctx, doc))
            {
                search_hit_page = -1;
                if (search_needle)
                    search_active = 1;
            }
            break;
        case 'f':
            toggle_fullscreen();
            break;
        case 'w':
            shrinkwrap();
            break;
        case 'r':
            reload();
            break;
        case 'o':
            toggle_outline();
            break;
        case 'W':
            auto_zoom_w();
            break;
        case 'H':
            auto_zoom_h();
            break;
        case 'Z':
            auto_zoom();
            break;
        case 'z':
            currentzoom = number > 0 ? number : DEFRES;
            break;
        case '<':
            currentpage -= 10 * fz_maxi(number, 1);
            break;
        case '>':
            currentpage += 10 * fz_maxi(number, 1);
            break;
        case ',':
        case KEY_PAGE_UP:
            currentpage -= fz_maxi(number, 1);
            break;
        case '.':
        case KEY_PAGE_DOWN:
            currentpage += fz_maxi(number, 1);
            break;
        case 'b':
            number = fz_maxi(number, 1);
            while (number--) smart_move_backward();
            break;
        case ' ':
            number = fz_maxi(number, 1);
            while (number--) smart_move_forward();
            break;
        case 'g':
            jump_to_page(number - 1);
            break;
        case 'G':
            jump_to_page(fz_count_pages(ctx, doc) - 1);
            break;
        case '+':
            currentzoom = zoom_in(currentzoom);
            break;
        case '-':
            currentzoom = zoom_out(currentzoom);
            break;
        case '[':
            currentrotate += 90;
            break;
        case ']':
            currentrotate -= 90;
            break;
        case 'l':
            showlinks = !showlinks;
            break;
        case 'i':
            showinfo = !showinfo;
            break;
        case '/':
            search_dir = 1;
            showsearch = 1;
            search_input.p = search_input.text;
            search_input.q = search_input.end;
            break;
        case '?':
            search_dir = -1;
            showsearch = 1;
            search_input.p = search_input.text;
            search_input.q = search_input.end;
            break;
        case KEY_UP:
            scroll_y -= 10;
            break;
        case KEY_DOWN:
            scroll_y += 10;
            break;
        case KEY_LEFT:
            scroll_x -= 10;
            break;
        case KEY_RIGHT:
            scroll_x += 10;
            break;
        }

        if (ui.key >= '0' && ui.key <= '9')
            number = number * 10 + ui.key - '0';
        else
            number = 0;

        currentpage = fz_clampi(currentpage, 0, fz_count_pages(ctx, doc) - 1);
        currentzoom = fz_clamp(currentzoom, MINRES, MAXRES);
        while (currentrotate < 0) currentrotate += 360;
        while (currentrotate >= 360) currentrotate -= 360;

        if (search_hit_page != currentpage)
            search_hit_page = -1; /* clear highlights when navigating */

        ui_needs_update = 1;

        ui.key = 0; /* we ate the key event, so zap it */
    }
}
Beispiel #5
0
static void run_main_loop(void)
{
    glViewport(0, 0, window_w, window_h);
    glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, window_w, window_h, 0, -1, 1);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    ui_begin();

    if (search_active)
    {
        float start_time = glfwGetTime();

        if (ui.key == KEY_ESCAPE)
            search_active = 0;

        /* ignore events during search */
        ui.key = ui.mod = 0;
        ui.down = ui.middle = ui.right = 0;

        while (glfwGetTime() < start_time + 0.2)
        {
            search_hit_count = fz_search_page_number(ctx, doc, search_page, search_needle,
                               search_hit_bbox, nelem(search_hit_bbox));
            if (search_hit_count)
            {
                search_active = 0;
                search_hit_page = search_page;
                jump_to_page(search_hit_page);
                break;
            }
            else
            {
                search_page += search_dir;
                if (search_page < 0 || search_page == fz_count_pages(ctx, doc))
                {
                    search_active = 0;
                    break;
                }
            }
        }

        /* keep searching later */
        if (search_active)
            ui_needs_update = 1;
    }

    do_app();

    canvas_w = window_w - canvas_x;
    canvas_h = window_h - canvas_y;

    do_canvas();

    if (showinfo)
        do_info();

    if (showoutline)
        do_outline(outline, canvas_x);

    if (showsearch)
    {
        int state = ui_input(canvas_x, 0, canvas_x + canvas_w, ui.lineheight+4, &search_input);
        if (state == -1)
        {
            ui.focus = NULL;
            showsearch = 0;
        }
        else if (state == 1)
        {
            ui.focus = NULL;
            showsearch = 0;
            search_page = -1;
            if (search_needle)
            {
                fz_free(ctx, search_needle);
                search_needle = NULL;
            }
            if (search_input.end > search_input.text)
            {
                search_needle = fz_strdup(ctx, search_input.text);
                search_active = 1;
                search_page = currentpage;
            }
        }
        ui_needs_update = 1;
    }

    if (search_active)
    {
        char buf[256];
        sprintf(buf, "Searching page %d of %d.", search_page + 1, fz_count_pages(ctx, doc));
        ui_label_draw(canvas_x, 0, canvas_x + canvas_w, ui.lineheight+4, buf);
    }

    ui_end();

    glfwSwapBuffers(window);

    ogl_assert(ctx, "swap buffers");
}