Beispiel #1
0
    void onDraw(SkCanvas* canvas) override {
        SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
        SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
        if (surface.get()) {
            SkCanvas* surfCanvas = surface->getCanvas();

            draw_content(surfCanvas);
            SkBitmap bitmap;

            // test peekPixels
            {
                SkImageInfo info;
                size_t rowBytes;
                const void* addr = surfCanvas->peekPixels(&info, &rowBytes);
                if (addr && bitmap.installPixels(info, const_cast<void*>(addr), rowBytes)) {
                    canvas->drawBitmap(bitmap, 0, 0, NULL);
                }
            }

            // test ROCanvasPixels
            canvas->translate(120, 0);
            SkAutoROCanvasPixels ropixels(surfCanvas);
            if (ropixels.asROBitmap(&bitmap)) {
                canvas->drawBitmap(bitmap, 0, 0, NULL);
            }

            // test Surface
            canvas->translate(120, 0);
            surface->draw(canvas, 0, 0, NULL);
        }
    }
Beispiel #2
0
void show_popup(RESULT *result)
{
	gchar *text=NULL;
	GtkTextIter iter;
	CANVAS canvas;
	DRAW_TEXT l_text;
	gint length;
	gchar *euc_str;

	g_assert(result->type == RESULT_TYPE_EB);

	LOG(LOG_DEBUG, "IN : show_popup()");

	text = ebook_get_text(result->data.eb.book_info,
			      result->data.eb.pos_text.page, 
			      result->data.eb.pos_text.offset);
	if(text == NULL)
		return;

	// Prevent the window from growing.
	//if(text[strlen(text)-1] == '\n')
	//text[strlen(text)-1] = '\0';

	if(popup == NULL){
		create_popup_window();
	}

	// Program aborts if you enable this line.
	//gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_view), NULL);

	clear_text_buffer();

	gtk_text_buffer_get_start_iter (text_buffer, &iter);

	length = strlen(text);
	if(text[length-1] == '\n'){
		text[length-1] = '\0';
		length --;
	}

	l_text.text = text;
	l_text.length = length;

	canvas.buffer = text_buffer;
	canvas.iter = &iter;
	canvas.indent = 0;

	if(result->word != NULL){
		euc_str = iconv_convert("utf-8", "euc-jp", result->word);
		draw_content(&canvas, &l_text, result->data.eb.book_info, NULL, euc_str);
		g_free(euc_str);
	} else {
		draw_content(&canvas, &l_text, result->data.eb.book_info, NULL, NULL);
	}

	gtk_text_buffer_get_start_iter (text_buffer, &iter);
	gtk_text_buffer_place_cursor(text_buffer, &iter);

	if(bshow_popup_title){
		gchar title[256];
		sprintf(title, "%d of %d", 
			g_list_index(search_result, current_in_result->data) + 1,
			g_list_length(search_result));

		gtk_label_set_text(GTK_LABEL(title_label), title);

	}

	gtk_adjustment_set_value(
		gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(popup_scroll)), 0);

	gtk_adjustment_set_value(
		gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(popup_scroll)), 0);


	gtk_window_present(GTK_WINDOW(popup));

	g_free(text);
	set_current_result(result);

	gtk_timeout_add(10, scroll_to_top, NULL);

	LOG(LOG_DEBUG, "OUT : show_popup()");

}