Exemplo n.º 1
0
	void shuaxin__(){
	    Glib::RefPtr<Gdk::Window> w = da_->get_window();
	    if (w) {
	    	Gtk::Allocation a = da_->get_allocation();
	        Gdk::Rectangle r(0, 0,a.get_width(),a.get_height());
	        w->invalidate_rect(r, false);
	    }
	}
Exemplo n.º 2
0
OSG::ImageRecPtr takeSnapshot() {
    Gtk::DrawingArea* drawArea = 0;
    VRGuiBuilder()->get_widget("glarea", drawArea);
    Glib::RefPtr<Gdk::Drawable> src = drawArea->get_window(); // 24 bits per pixel ( src->get_depth() )
    int w = drawArea->get_width();
    int h = drawArea->get_height();
    w -= w%4; h -= h%4;
    //cout << "PIC FORMAT " << w << " " << h << " " << src->get_depth() << endl;
    Glib::RefPtr<Gdk::Image> img = Glib::wrap( gdk_drawable_get_image(src->gobj(), 0, 0, w, h) );
    Glib::RefPtr<Gdk::Pixbuf> pxb = Glib::wrap( gdk_pixbuf_get_from_image(NULL, img->gobj(), src->get_colormap()->gobj(), 0,0,0,0,w,h) );

    OSG::ImageRecPtr res = OSG::Image::create();
    //Image::set(pixFormat, width, height, depth, mipmapcount, framecount, framedelay, data, type, aloc, sidecount);
    res->set(OSG::Image::OSG_RGB_PF, w, h, 1, 0, 1, 0, (const unsigned char*)pxb->get_pixels(), OSG::Image::OSG_UINT8_IMAGEDATA, true, 1);
    return res;
}
Exemplo n.º 3
0
	bool keyi__(){
	    Glib::RefPtr<Gdk::Window> w = da_->get_window();
	    if(!w)
	    	return false;
	    if(!cr_)
	    	return false;
	    return true;
	}
Exemplo n.º 4
0
void saveSnapshot(string path) {
    Gtk::DrawingArea* drawArea = 0;
    VRGuiBuilder()->get_widget("glarea", drawArea);
    Glib::RefPtr<Gdk::Drawable> src = drawArea->get_window();
    int smin = min(drawArea->get_width(), drawArea->get_height());
    int u = max(0.0, drawArea->get_width()*0.5 - smin*0.5);
    int v = max(0.0, drawArea->get_height()*0.5 - smin*0.5);
    Glib::RefPtr<Gdk::Pixbuf> pxb = Gdk::Pixbuf::create( src, u, v, smin, smin);
    pxb = pxb->scale_simple(128, 128, Gdk::INTERP_HYPER);
    pxb->save(path, "png");
}
Exemplo n.º 5
0
bool area___::expose_evt__(GdkEventExpose* event){
	if(code_.size()>0){
		Glib::RefPtr<Gdk::Window> window=da_->get_window();
		if(window){
			cr_ = window->create_cairo_context();
			if(event){
				cr_->rectangle(event->area.x, event->area.y,
						event->area.width, event->area.height);
				cr_->clip();
			}

#ifdef debug_
			test__();
#else
			char buf[32];
			l2s__((long)this,buf);
			d_(sh_,on_,code_.c_str(),NULL,3,ht_->name__(),"重绘",buf);
#endif
		}
		return true;
	}
	return false;
}
Exemplo n.º 6
0
	void huaju__(char*buf){
	    Glib::RefPtr<Gdk::Window> w = da_->get_window();
	    if (w) {
	    	cr_ = w->create_cairo_context();
	    }
	}
Exemplo n.º 7
0
	void get_height__(char*buf){
	    cpy__(buf,da_->get_allocation().get_height(),32);
	}
Exemplo n.º 8
0
	void get_width__(char*buf){
	    cpy__(buf,da_->get_allocation().get_width(),32);
	}
Exemplo n.º 9
0
void area___::test__(){
	int width, height;
	width=da_->get_allocation().get_width();
	height=da_->get_allocation().get_height();

	double m_radius=0.42;
	double m_line_width=0.05;

	// scale to unit square and translate (0, 0) to be (0.5, 0.5), i.e.
	// the center of the window
	cr_->scale(width, height);
	cr_->translate(0.5, 0.5);
	cr_->set_line_width(m_line_width);

	cr_->save();
	cr_->set_source_rgba(0.337, 0.612, 0.117, 0.9);   // green
	cr_->paint();
	cr_->restore();
	cr_->arc(0, 0, m_radius, 0, 2 * M_PI);
	cr_->save();
	cr_->set_source_rgba(1.0, 1.0, 1.0, 0.8);
	cr_->fill_preserve();
	cr_->restore();
	cr_->stroke_preserve();
	cr_->clip();

	//clock ticks
	for (int i = 0; i < 12; i++)
	{
		double inset = 0.05;

		cr_->save();
		cr_->set_line_cap(Cairo::LINE_CAP_ROUND);

		if(i % 3 != 0)
		{
			inset *= 0.8;
			cr_->set_line_width(0.03);
		}

		cr_->move_to(
				(m_radius - inset) * cos (i * M_PI / 6),
				(m_radius - inset) * sin (i * M_PI / 6));
		cr_->line_to (
				m_radius * cos (i * M_PI / 6),
				m_radius * sin (i * M_PI / 6));
		cr_->stroke();
		cr_->restore(); // stack-pen-size
	}

	// store the current time
	time_t rawtime;
	time(&rawtime);
	struct tm * timeinfo = localtime (&rawtime);

	// compute the angles of the indicators of our clock
	double minutes = timeinfo->tm_min * M_PI / 30;
	double hours = timeinfo->tm_hour * M_PI / 6;
	double seconds= timeinfo->tm_sec * M_PI / 30;
	cout<<timeinfo->tm_min<<","<<timeinfo->tm_hour<<","<<timeinfo->tm_sec<<endl;

	cr_->save();
	cr_->set_line_cap(Cairo::LINE_CAP_ROUND);

	// draw the seconds hand
	cr_->save();
	cr_->set_line_width(m_line_width / 3);
	cr_->set_source_rgba(0.7, 0.7, 0.7, 0.8); // gray
	cr_->move_to(0, 0);
	cr_->line_to(sin(seconds) * (m_radius * 0.9),
			-cos(seconds) * (m_radius * 0.9));
	cr_->stroke();
	cr_->restore();

	// draw the minutes hand
	cr_->set_source_rgba(0.117, 0.337, 0.612, 0.9);   // blue
	cr_->move_to(0, 0);
	cr_->line_to(sin(minutes + seconds / 60) * (m_radius * 0.8),
			-cos(minutes + seconds / 60) * (m_radius * 0.8));
	cr_->stroke();

	// draw the hours hand
	cr_->set_source_rgba(0.337, 0.612, 0.117, 0.9);   // green
	cr_->move_to(0, 0);
	cr_->line_to(sin(hours + minutes / 12.0) * (m_radius * 0.5),
			-cos(hours + minutes / 12.0) * (m_radius * 0.5));
	cr_->stroke();
	cr_->restore();

	// draw a little dot in the middle
	cr_->arc(0, 0, m_line_width / 3.0, 0, 2 * M_PI);
	cr_->fill();
}