本文整理汇总了C++中cairo::RefPtr类的典型用法代码示例。如果您正苦于以下问题:C++ RefPtr类的具体用法?C++ RefPtr怎么用?C++ RefPtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RefPtr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: agget
static void
skillgui_cairo_render_textpara(GVJ_t *job, pointf p, textpara_t *para)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
__tt.ping_start(__ttc_text);
++__num_text;
#endif
SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
obj_state_t *obj = job->obj;
Cairo::FontWeight weight = Cairo::FONT_WEIGHT_NORMAL;
Cairo::FontSlant slant = Cairo::FONT_SLANT_NORMAL;
char *fontweight = NULL;
char *fontslant = NULL;
if (obj->type == CLUSTER_OBJTYPE) {
fontweight = agget(obj->u.sg, (char *)"fontweight");
fontslant = agget(obj->u.sg, (char *)"fontslant");
} else if (obj->type == ROOTGRAPH_OBJTYPE) {
fontweight = agget(obj->u.g, (char *)"fontweight");
fontslant = agget(obj->u.g, (char *)"fontslant");
} else if (obj->type == NODE_OBJTYPE) {
fontweight = agget(obj->u.n, (char *)"fontweight");
fontslant = agget(obj->u.n, (char *)"fontslant");
} else if (obj->type == EDGE_OBJTYPE) {
fontweight = agget(obj->u.e, (char *)"fontweight");
fontslant = agget(obj->u.e, (char *)"fontslant");
}
if (fontweight && (strcmp(fontweight, "bold") == 0)) {
weight = Cairo::FONT_WEIGHT_BOLD;
p.x -= 8;
}
if (fontslant && (strcmp(fontslant, "italic") == 0)) {
slant = Cairo::FONT_SLANT_ITALIC;
}
double offsetx = 0.0;
double offsety = 0.0;
double rotate = 0.0;
if ( (obj->type == EDGE_OBJTYPE) && (strcmp(para->str, obj->headlabel) == 0) ) {
char *labelrotate = agget(obj->u.e, (char *)"labelrotate");
if (labelrotate && (strlen(labelrotate) > 0)) {
rotate = fawkes::deg2rad(atof(labelrotate));
}
char *labeloffsetx = agget(obj->u.e, (char *)"labeloffsetx");
if (labeloffsetx && (strlen(labeloffsetx) > 0)) {
offsetx = atof(labeloffsetx);
}
char *labeloffsety = agget(obj->u.e, (char *)"labeloffsety");
if (labeloffsety && (strlen(labeloffsety) > 0)) {
offsety = atof(labeloffsety);
}
}
//__tt.ping_start(__ttc_text_1);
Cairo::Matrix old_matrix;
cairo->get_matrix(old_matrix);
if (__fontname) {
cairo->select_font_face(__fontname, slant, weight);
} else {
cairo->select_font_face(para->fontname, slant, weight);
}
cairo->set_font_size(para->fontsize);
//cairo->set_font_options ( Cairo::FontOptions() );
//cairo->set_line_width(1.0);
Cairo::TextExtents extents;
cairo->get_text_extents(para->str, extents);
if (para->just == 'r') {
p.x -= extents.width;
} else if (para->just != 'l') {
p.x -= extents.width / 2.0;
}
cairo->move_to(p.x + offsetx, -p.y + offsety);
cairo->rotate(rotate);
skillgui_cairo_set_color(cairo, &(obj->pencolor));
cairo->text_path( para->str );
cairo->fill();
cairo->set_matrix(old_matrix);
//__tt.ping_end(__ttc_text_5);
#ifdef USE_GVPLUGIN_TIMETRACKER
__tt.ping_end(__ttc_text);
#endif
}
开发者ID:timn,项目名称:ros-skillgui,代码行数:90,代码来源:gvplugin_skillgui_cairo.cpp
示例2: refresh
void ValidationPanel::refresh()
{
// update the label
crn::StringUTF8 lab = "<span font_desc=\"" + Config::GetFont() + "\">" + title + "</span>";
lab += " (";
lab += nelem;
lab += ")";
auto *labw = get_label_widget();
auto *llab = dynamic_cast<Gtk::Label*>(labw);
if (llab)
llab->set_markup(lab.CStr());
else
set_label(lab.CStr());
if (/*(positions.size() != elements.size()) ||*/ (dispw <= 0) || (disph <= 0) || locked)
return;
Glib::RefPtr<Gdk::Window> win = da.get_window();
if (win)
{
// if the drawing area is fully created
// create a buffer
Glib::RefPtr<Gdk::Pixmap> pm = Gdk::Pixmap::create(win, dispw, disph);
// clear the buffer
pm->draw_rectangle(da_gc, true, 0, 0, dispw, disph);
int offset = -int(scroll.get_value());
Cairo::RefPtr<Cairo::Context> cc = pm->create_cairo_context();
// draw the words
for (const ValidationPanel::ElementList::value_type &el : elements)
{
if (!el.second.empty())
{
int by = positions[el.second.begin()->first].Y;
int ey = by;
for (const ValidationPanel::ElementCluster::value_type &w : el.second)
{
int y = positions[w.first].Y + w.second.img->get_height();
if (y > ey) ey = y;
}
if ((el.first == elements.rbegin()->first) && (ey < disph))
{
// fill till the end of the display
ey = disph;
}
ValidationPanel::set_color(cc, el.first);
cc->rectangle(0, by + offset, dispw, ey - by);
cc->fill();
}
for (const ValidationPanel::ElementCluster::value_type &w : el.second)
{
Glib::RefPtr<Gdk::Pixbuf> wpb = w.second.img;
pm->draw_pixbuf(da_gc, wpb, 0, 0, positions[w.first].X, positions[w.first].Y + offset, w.second.img->get_width(), w.second.img->get_height(), Gdk::RGB_DITHER_NONE, 0, 0);
}
}
// draw the mark
if (mark.size() > 1)
{
cc->set_source_rgb(1.0, 0, 0);
cc->move_to(mark.front().X, mark.front().Y + offset);
for (size_t tmp = 1; tmp < mark.size(); ++tmp)
{
cc->line_to(mark[tmp].X, mark[tmp].Y + offset);
}
cc->stroke();
}
// copy pixmap to drawing area
win->draw_drawable(da_gc, pm, 0, 0, 0, 0);
}
}
开发者ID:Liris-Pleiad,项目名称:oriflamms,代码行数:77,代码来源:OriValidationPanel.cpp
示例3: on_draw
// main drawing routine
bool Draw::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
int num_cells = b.num_bowls + 2;
double inv_num_cells = 1.0 / num_cells;
Gtk::Allocation alloc = get_allocation();
Pango::FontDescription font("Monospace");
font.set_size(std::min(alloc.get_width(), alloc.get_height()) * .1 * Pango::SCALE);
cr->set_source_rgb(0.0, 0.0, 0.0);
// draw bg
draw_img(cr, bg_board, 0.0, 0.0, alloc.get_width() / (bg_board->get_width() - .5),
alloc.get_height() / (bg_board->get_height() - .5));
// draw bg for left store
draw_img(cr, bg_store, 0.0, 0.0, alloc.get_width() / (bg_store->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bg_store->get_height() - .5));
// l store beads
for(auto & j: b.l_store.beads)
{
draw_img(cr, bead_imgs[j.color_i], alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
alloc.get_width() / (bead_imgs[j.color_i]->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bead_imgs[j.color_i]->get_height() - .5) * .5);
draw_img(cr, bead_s_img, alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
alloc.get_width() / (bead_s_img->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bead_s_img->get_height() - .5) * .5);
}
// draw # for left store
draw_num(cr, font, b.l_store.beads.size(), alloc.get_width() * .5 * inv_num_cells,
alloc.get_height() * .5);
// draw bg for right store
draw_img(cr, bg_store, alloc.get_width() * (1.0 - inv_num_cells), 0,
alloc.get_width() / (bg_store->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bg_store->get_height() - .5));
// r store beads
for(auto & j: b.r_store.beads)
{
draw_img(cr, bead_imgs[j.color_i], alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
alloc.get_width() / (bead_imgs[j.color_i]->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bead_imgs[j.color_i]->get_height() - .5) * .5);
draw_img(cr, bead_s_img, alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
alloc.get_width() / (bead_s_img->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bead_s_img->get_height() - .5) * .5);
}
// draw # for right store
draw_num(cr, font, b.r_store.beads.size(), alloc.get_width() * (1.0 - .5 * inv_num_cells),
alloc.get_height() * .5);
// draw bowls
for(size_t i = 0; i < b.top_row.size(); ++i)
{
// draw upper row hint
if(hint_player == PLAYER_2 && show_hint && hint_i == (int)i)
{
draw_img(cr, hint_img, alloc.get_width() * (i + 1) * inv_num_cells, 0.0,
alloc.get_width() / (hint_img->get_width() - .5) * inv_num_cells,
alloc.get_height() / (hint_img->get_height() - .5) * .5);
}
// upper row bgs
draw_img(cr, bg_bowl, alloc.get_width() * (i + 1) * inv_num_cells, 0,
alloc.get_width() / (bg_bowl->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bg_bowl->get_height() - .5) * .5);
// upper row beads
for(auto & j: b.top_row[i].beads)
{
draw_img(cr, bead_imgs[j.color_i], alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
alloc.get_width() / (bead_imgs[j.color_i]->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bead_imgs[j.color_i]->get_height() - .5) * .5);
draw_img(cr, bead_s_img, alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
alloc.get_width() / (bead_s_img->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bead_s_img->get_height() - .5) * .5);
}
// upper row txt
draw_num(cr, font, b.top_row[i].beads.size(), alloc.get_width() * (2 * i + 3) * .5 * inv_num_cells,
alloc.get_height() * .25);
// draw lower row hint
if(hint_player == PLAYER_1 && show_hint && hint_i == (int)i)
{
draw_img(cr, hint_img, alloc.get_width() * (i + 1) * inv_num_cells, .5 * alloc.get_height(),
alloc.get_width() / (hint_img->get_width() - .5) * inv_num_cells,
alloc.get_height() / (hint_img->get_height() - .5) * .5);
}
// lower row bgs
draw_img(cr, bg_bowl, alloc.get_width() * (i + 1) * inv_num_cells, .5 * alloc.get_height(),
alloc.get_width() / (bg_bowl->get_width() - .5) * inv_num_cells,
alloc.get_height() / (bg_bowl->get_height() - .5) * .5);
// lower row beads
//.........这里部分代码省略.........
开发者ID:mattvchandler,项目名称:mancala,代码行数:101,代码来源:draw.cpp
示例4: generate
void OutputFile::generate() {
unsigned E=es.size();
bool cleanupRoutes=false;
if(routes==NULL) {
cleanupRoutes=true;
routes = new vector<straightener::Route*>(E);
for(unsigned i=0;i<E;i++) {
straightener::Route* r=new straightener::Route(2);
r->xs[0]=rs[es[i].first]->getCentreX();
r->ys[0]=rs[es[i].first]->getCentreY();
r->xs[1]=rs[es[i].second]->getCentreX();
r->ys[1]=rs[es[i].second]->getCentreY();
(*routes)[i]=r;
}
}
#if defined (CAIRO_HAS_SVG_SURFACE) && defined (CAIRO_HAS_PDF_SURFACE)
double width,height,r=2;
if(rects) r=rs[0]->width()/2;
double xmin=DBL_MAX, ymin=xmin;
double xmax=-DBL_MAX, ymax=xmax;
for (unsigned i=0;i<rs.size();i++) {
double x=rs[i]->getCentreX(), y=rs[i]->getCentreY();
xmin=min(xmin,x);
ymin=min(ymin,y);
xmax=max(xmax,x);
ymax=max(ymax,y);
}
xmax+=2*r;
ymax+=2*r;
xmin-=2*r;
ymin-=2*r;
width=xmax-xmin;
height=ymax-ymin;
Cairo::RefPtr<Cairo::Context> cr;
openCairo(cr,width,height);
/* set background colour
cr->save(); // save the state of the context
cr->set_source_rgb(0.86, 0.85, 0.47);
cr->paint(); // fill image with the color
cr->restore(); // color is back to black now
*/
cr->set_line_width(1.);
cr->set_font_size(8);
cr->save();
if(rc) for(Clusters::const_iterator c=rc->clusters.begin();c!=rc->clusters.end();c++) {
draw_cluster_boundary(cr,**c,xmin,ymin);
}
if(curvedEdges)
draw_curved_edges(cr,es,xmin,ymin);
else
draw_edges(cr,*routes,xmin,ymin);
Cairo::TextExtents te;
for (unsigned i=0;i<rs.size();i++) {
if(!rects) {
double x=rs[i]->getCentreX()-xmin, y=rs[i]->getCentreY()-ymin;
cr->arc(x,y,r, 0.0, 2.0 * M_PI);
cr->fill();
} else {
double x=rs[i]->getMinX()-xmin+0.5, y=rs[i]->getMinY()-ymin+0.5;
std::string str;
if(labels.size()==rs.size()) {
str=labels[i];
} else {
std::stringstream s; s<<i;
str=s.str();
}
cr->get_text_extents(str,te);
/*
double llx = x-te.width/2.-1;
double lly = y-te.height/2.-1;
cr->rectangle(llx,lly,te.width+2,te.height+2);
*/
cr->rectangle(x,y,
rs[i]->width()-1,rs[i]->height()-1);
cr->stroke_preserve();
cr->save();
cr->set_source_rgba(245./255., 233./255., 177./255., 0.6);
cr->fill();
cr->restore();
if(labels.size()==rs.size()) {
cr->move_to(x-te.x_bearing+te.width/2.,y-te.y_bearing+te.height/2.);
cr->show_text(str);
}
cr->stroke();
}
}
cr->show_page();
std::cout << "Wrote file \"" << fname << "\"" << std::endl;
#else
std::cout <<
"WARNING: cola::OutputFile::generate(): No SVG file produced." <<
std::endl <<
" You must have cairomm (and cairo with SVG support) " <<
//.........这里部分代码省略.........
开发者ID:amolenaar,项目名称:adaptagrams,代码行数:101,代码来源:output_svg.cpp
示例5: on_expose_event
bool Canvas::on_expose_event(GdkEventExpose * evt) {
Glib::RefPtr<Gdk::Window> window = get_window();
if (!window) return false; // no window yet?
if (!seen_first_expose_event) {
seen_first_expose_event = true;
main->controlsWindow().starting_position();
}
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
if (!surface) return true; // Haven't rendered yet? Nothing we can do
if (evt) {
cr->rectangle(evt->area.x, evt->area.y, evt->area.width, evt->area.height);
cr->clip();
}
cr->set_source(surface, 0, 0);
cr->paint();
if (main->dragrect.is_active() && main->dragrect.surface_valid()) {
cr->save();
cr->set_source(main->dragrect.get_surface(), 0, 0);
cr->paint();
cr->restore();
}
if (main->hud_active()) {
Cairo::RefPtr<Cairo::Surface>& sfc = main->get_hud_surface();
if (sfc)
cr->set_source(sfc, 0, 0); // TODO HUD position
cr->paint();
}
return true;
}
开发者ID:crazyscot,项目名称:brot2,代码行数:35,代码来源:Canvas.cpp
示例6: if
bool studio::Widget_Preview::redraw(const Cairo::RefPtr<Cairo::Context> &cr)
{
//And render the drawing area
Glib::RefPtr<Gdk::Pixbuf> pxnew, px = currentbuf;
cairo_surface_t* cs;
bool use_cairo= preview->get_use_cairo();
if(use_cairo)
{
if(current_surface)
cs=cairo_surface_reference(current_surface);
else
return true;
}
int dw = draw_area.get_width();
int dh = draw_area.get_height();
if(use_cairo && !cs)
return true;
else if(!use_cairo && !px)
return true;
//made not need this line
//if ( draw_area.get_height() == 0 || px->get_height() == 0 || px->get_width() == 0)
// return true;
//figure out the scaling factors...
float sx, sy;
float q = 1 / preview->get_zoom();
int nw, nh;
int w,h;
// grab the source dimensions
if(use_cairo)
{
w=cairo_image_surface_get_width(cs);
h=cairo_image_surface_get_height(cs);
}
else
{
w=px->get_width();
h=px->get_height();
}
Gtk::Entry* entry = zoom_preview.get_entry();
String str(entry->get_text());
Glib::ustring text = str;
const char *c = text.c_str();
if (text == _("Fit") || text == "fit")
{
sx = dw / (float)w;
sy = dh/ (float)h;
//synfig::info("widget_preview redraw: now to scale the bitmap: %.3f x %.3f",sx,sy);
//round to smallest scale (fit entire thing in window without distortion)
if(sx > sy) sx = sy;
//cleanup previous size request
draw_area.set_size_request();
}
//limit zoom level from 0.01 to 10 times
else if (atof(c) > 1000)
{
sx = sy = 10 * q;
}
else if (atof(c) <= 0 )
{
sx = sy = 0 ;
draw_area.set_size_request(0, 0);
}
else sx = sy = atof(c) / 100 * q;
//scale to a new pixmap and then copy over to the window
nw = (int)(w * sx);
nh = (int)(h * sx);
if(nw == 0 || nh == 0)return true;
if(!use_cairo)
pxnew = px->scale_simple(nw, nh, Gdk::INTERP_NEAREST);
//except "Fit" or "fit", we need to set size request for scrolled window
if (text != _("Fit") && text != "fit")
{
draw_area.set_size_request(nw, nh);
dw = draw_area.get_width();
dh = draw_area.get_height();
}
//synfig::info("Now to draw to the window...");
//copy to window
Glib::RefPtr<Gdk::Window> wind = draw_area.get_window();
if(!wind) synfig::warning("The destination window is broken...");
if(!use_cairo)
{
//.........这里部分代码省略.........
开发者ID:Permutatrix,项目名称:synfig,代码行数:101,代码来源:preview.cpp
示例7: draw_cluster_boundary
void OutputFile::draw_cluster_boundary(Cairo::RefPtr<Cairo::Context> const &cr,
Cluster &c,
const double xmin,
const double ymin) {
c.computeBoundary(rs);
cr->save();
// background
cr->set_source_rgb(0.7, 0.7, 224./255.);
cr->move_to(c.hullX[0]-xmin,c.hullY[0]-ymin);
for(unsigned i=1;i<c.hullX.size();i++) {
cr->line_to(c.hullX[i]-xmin,c.hullY[i]-ymin);
}
cr->line_to(c.hullX[0]-xmin,c.hullY[0]-ymin);
cr->fill();
cr->restore();
// outline
cr->move_to(c.hullX[0]-xmin,c.hullY[0]-ymin);
for(unsigned i=1;i<c.hullX.size();i++) {
cr->line_to(c.hullX[i]-xmin,c.hullY[i]-ymin);
}
cr->line_to(c.hullX[0]-xmin,c.hullY[0]-ymin);
cr->stroke();
}
开发者ID:amolenaar,项目名称:adaptagrams,代码行数:23,代码来源:output_svg.cpp
示例8: on_draw
bool PhotoPreview::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) {
if (!Image)
return false;
int Width,Height;
Gtk::Allocation Allocation = get_allocation();
Width=Allocation.get_width();
Height=Allocation.get_height();
if (Width<=1 || Height<=1)
return false;
/* Scale the photo */
Glib::RefPtr<Gdk::Pixbuf> Scaled;
/* Preserve aspect ratio */
double ImageAspectRatio,PreviewAspectRatio;
PreviewAspectRatio=(float)Width/Height;
ImageAspectRatio=(float)Image->get_width()/Image->get_height();
if (ImageAspectRatio<PreviewAspectRatio) {
Width=Height*ImageAspectRatio;
} else {
Height=Width/ImageAspectRatio;
}
Scaled=Image->scale_simple(
Width,
Height,
Gdk::INTERP_BILINEAR);
if (Cfg->GetFlipPreview())
Scaled=Scaled->flip();
Gdk::Cairo::set_source_pixbuf(cr, Scaled,
(Allocation.get_width()/2)-(Scaled->get_width()/2),
(Allocation.get_height()/2)-(Scaled->get_height()/2)
);
cr->paint();
double TimeLeft=Util::TimeDiff(&PhotoTime,NULL);
double MinDim=get_width();
if (get_height()<MinDim)
MinDim=get_height();
if (Overlay.length()==0 && TimeLeft>0) {
double TotalTime=Cfg->GetCountdownCount()*(Cfg->GetCountdownTimeout()/1000.0);
unsigned int Whole=floor(Cfg->GetCountdownCount()*TimeLeft/TotalTime);
float Frac=(Cfg->GetCountdownCount()*TimeLeft/TotalTime)-Whole;
Cairo::RefPtr<Cairo::Context> Context = get_window()->create_cairo_context();
Context->set_source_rgba(1.0, 1.0, 1.0,0.5);
Context->translate(get_width()/2.0,get_height()/2.0);
/* Draw the fractional portion of the countdown */
Context->save();
Context->rotate(M_PI/2.0);
Context->arc(0.0,0.0,MinDim/4.0,0,Frac*2*M_PI);
Context->fill();
Context->restore();
/* Draw the Whole portion of the countdown */
Context->save();
Context->set_font_size(MinDim/2.0);
char StrBuf[1024];
snprintf(StrBuf,sizeof(StrBuf),"%d",Whole+1);
Cairo::TextExtents Extents;
Context->get_text_extents(StrBuf,Extents);
Context->translate(-Extents.width/2.0,Extents.height/2.0);
Context->show_text(StrBuf);
Context->stroke();
Context->restore();
}
if (Overlay.length()) {
Cairo::RefPtr<Cairo::Context> Context = get_window()->create_cairo_context();
Context->set_source_rgba(1.0, 1.0, 1.0,0.5);
Context->translate(get_width()/2.0,get_height()/2.0);
Context->save();
Context->set_font_size(MinDim/2.0);
Cairo::TextExtents Extents;
Context->get_text_extents(Overlay,Extents);
Context->translate(-Extents.width/2.0,Extents.height/2.0);
Context->show_text(Overlay);
Context->stroke();
Context->restore();
}
return true;
}
开发者ID:adsllc,项目名称:muenstercam,代码行数:93,代码来源:PhotoPreview.cpp
示例9: icon
void NodeRenderer::icon(const Cairo::RefPtr<Cairo::Context>& cr, IconCache& cache)
{
// path to icon not set
if (s->icon.str().size() == 0 || s->icon_width == 0.0 || s->icon_height == 0.0)
return;
cr->save();
Cairo::RefPtr<Cairo::ImageSurface> image = cache.getIcon(s->icon.str());
double width = s->icon_width < 0 ? image->get_width() : s->icon_width;
double height = s->icon_height < 0 ? image->get_height() : s->icon_height;
double x0 = floor(location.x - width/2.0);
double y0 = floor(location.y - height/2.0);
cr->translate(x0, y0);
cr->scale(width / image->get_width(),
height / image->get_height());
cr->set_source(image, 0, 0);
cr->paint();
cr->restore();
}
开发者ID:DennisOSRM,项目名称:alacarte,代码行数:21,代码来源:node_renderer.cpp
示例10: on_draw
/**
* Render the Preview
* @param Cairo::Context cr
* @return Gtk::Window::on_draw(cr)
*/
bool Preview::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
Configuration::Theme theme = Configuration::getTheme();
if (theme.forPreview().enabled()) {
cr->set_source_rgba(
theme.forPreview().background().red,
theme.forPreview().background().green,
theme.forPreview().background().blue,
theme.forPreview().background().alpha);
Utilities::RoundedRectangle(cr, 0, 0, this->get_width(), this->get_height(),
theme.forPreview().roundedRatious());
cr->fill();
}
if (!m_isActive) {
return Gtk::Window::on_draw(cr);
}
if (m_previewtems.size() < 1) {
this->hideMe();
return Gtk::Window::on_draw(cr);
}
int idx = 0;
for (DockItem* item : m_previewtems) {
if (item->m_window == NULL || item->m_xid == 0 || !item->visible)
continue;
int pos_x = 20 + (m_previewWidth * idx);
int pos_y = 16;
int pos_width = m_previewWidth - DEF_PREVIEW_LEFT_MARGING;
int pos_height = 20;
cr->set_source_rgba(
theme.forPreview().foreground().red,
theme.forPreview().foreground().green,
theme.forPreview().foreground().blue,
theme.forPreview().foreground().alpha);
cr->set_line_width(theme.forPreview().lineWith());
if (item->m_imageLoadedRequired)
cr->set_line_width(theme.forPreview().lineWith() + 0.5);
if (theme.getPreviewBinaryValue() == 0) {
Utilities::RoundedRectangle(cr,
DEF_PREVIEW_LEFT_MARGING + (m_previewWidth * idx),
16, m_previewWidth,
m_previewHeight - DEF_PREVIEW_RIGHT_MARGING,
theme.forPreview().roundedRatious());
cr->stroke();
} else {
cr->set_line_width(theme.forPreview().lineWith());
int pos_x = DEF_PREVIEW_LEFT_MARGING + (m_previewWidth * idx);
int y_pos = 16;
int width = m_previewWidth;
int height = m_previewHeight;
int value = theme.getPreviewBinaryValue();
/* Vertical Left*/
int bit = CHECK_BIT(value, 3);
if (bit == 1) {
cr->set_line_width(theme.forPreview().lineWith());
cr->move_to(pos_x, y_pos);
cr->line_to(pos_x, y_pos);
cr->line_to(pos_x, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
cr->stroke();
}
/* Top */
bit = CHECK_BIT(value, 2);
if (bit == 1) {
cr->set_line_width(theme.forPreview().lineWith());
cr->move_to(pos_x, y_pos);
cr->line_to(pos_x, y_pos);
cr->line_to(pos_x + (m_previewWidth), y_pos);
cr->stroke();
}
/* Right vertical */
bit = CHECK_BIT(value, 1);
//.........这里部分代码省略.........
开发者ID:yoosamui,项目名称:DockLight,代码行数:101,代码来源:Preview.cpp
示例11: color
bool
ColorSlider::on_draw(const Cairo::RefPtr<Cairo::Context> &cr)
{
Color color(color_);
static const slider_color_func jump_table[int(TYPE_END)] =
{
slider_color_TYPE_R,
slider_color_TYPE_G,
slider_color_TYPE_B,
slider_color_TYPE_Y,
slider_color_TYPE_U,
slider_color_TYPE_V,
slider_color_TYPE_HUE,
slider_color_TYPE_SAT,
slider_color_TYPE_A,
};
slider_color_func color_func(jump_table[int(type)]);
float amount;
switch(type)
{
case TYPE_R: amount=color.get_r(); break;
case TYPE_G: amount=color.get_g(); break;
case TYPE_B: amount=color.get_b(); break;
case TYPE_Y: amount=color.get_y(); break;
case TYPE_U: amount=color.get_u()+0.5; break;
case TYPE_V: amount=color.get_v()+0.5; break;
case TYPE_HUE: amount=Angle::rot(color.get_uv_angle()).get(); amount-=floor(amount); break;
case TYPE_SAT: amount=color.get_s()*2.0; break;
case TYPE_A: amount=color.get_a(); break;
default: amount=0; break;
}
if(use_colorspace_gamma() && (type<TYPE_U))
amount=gamma_in(amount);
const int height(get_height());
const int width(get_width());
Gdk::Rectangle ca(0,0,width,height);
const Color bg1(0.75, 0.75, 0.75);
const Color bg2(0.5, 0.5, 0.5);
int i;
for(i=width-1;i>=0;i--)
{
color_func(color,
(use_colorspace_gamma() && type<TYPE_U)
? gamma_out(float(i)/float(width))
: (float(i)/float(width)));
const Color c1(
colorconv_apply_gamma(
Color::blend(color,bg1,1.0).clamped() ));
const Color c2(
colorconv_apply_gamma(
Color::blend(color,bg2,1.0).clamped() ));
assert(c1.is_valid());
assert(c2.is_valid());
if((i*2/height)&1)
{
cr->set_source_rgb(c1.get_r(), c1.get_g(), c1.get_b());
cr->rectangle(ca.get_x()+i, ca.get_y(), 1, height/2);
cr->fill();
cr->set_source_rgb(c2.get_r(), c2.get_g(), c2.get_b());
cr->rectangle(ca.get_x()+i, ca.get_y()+height/2, 1, height/2);
cr->fill();
}
else
{
cr->set_source_rgb(c2.get_r(), c2.get_g(), c2.get_b());
cr->rectangle(ca.get_x()+i, ca.get_y(), 1, height/2);
cr->fill();
cr->set_source_rgb(c1.get_r(), c1.get_g(), c1.get_b());
cr->rectangle(ca.get_x()+i, ca.get_y()+height/2, 1, height/2);
cr->fill();
}
}
get_style_context()->render_arrow(
cr,
1.5*M_PI,
(int(amount*width)-height/2),
0,
height
);
cr->set_source_rgb(1, 1, 1);
cr->rectangle(ca.get_x()+1, ca.get_y()+1, width-3, height-3);
cr->stroke();
cr->set_source_rgb(0, 0, 0);
cr->rectangle(ca.get_x(), ca.get_y(), width-1, height-1);
cr->stroke();
return true;
}
开发者ID:jottoprimo,项目名称:synfig,代码行数:99,代码来源:widget_coloredit.cpp
示例12: draw
void DependencyArrow::draw(const Cairo::RefPtr<Cairo::Context>& context) const
{
// the way to compute the (tcx, tcy) single control point of the
// quadratic
double dX = mControlPoint.getX() - mOrigin->getX();
double dY = mControlPoint.getY() - mOrigin->getY();
double d1 = std::sqrt(dX * dX + dY * dY);
double d = d1;
dX = mDestination->getX() - mControlPoint.getX();
dY = mDestination->getY() - mControlPoint.getY();
d += std::sqrt(dX * dX + dY * dY);
double t = d1/d;
double t1 = 1.0 - t;
double tSq = t * t;
double denom = 2.0 * t * t1;
double tcx = (mControlPoint.getX() - t1 * t1 * mOrigin->getX() -
tSq * mDestination->getX()) / denom;
double tcy = (mControlPoint.getY() - t1 * t1 * mOrigin->getY() -
tSq * mDestination->getY()) / denom;
// from the single point of the quadratic to the both of the cubic
double tcxq1 = mOrigin->getX() + 2. * (tcx - mOrigin->getX()) / 3.;
double tcyq1 = mOrigin->getY() + 2. * (tcy - mOrigin->getY()) / 3.;
double tcxq2 = mDestination->getX() +
2. * (tcx - mDestination->getX()) / 3.;
double tcyq2 = mDestination->getY() +
2. * (tcy - mDestination->getY()) / 3.;
// and now to draw,
std::valarray< double > dashes(2);
double angle = atan2 (mDestination->getY() - tcyq2,
mDestination->getX() - tcxq2) + M_PI;
double x1 = mDestination->getX() + 9 * std::cos(angle - 0.35);
double y1 = mDestination->getY() + 9 * std::sin(angle - 0.35);
double x2 = mDestination->getX() + 9 * std::cos(angle + 0.35);
double y2 = mDestination->getY() + 9 * std::sin(angle + 0.35);
dashes[0] = 8.0;
dashes[1] = 3.0;
context->save();
context->set_line_width(1);
context->move_to(mDestination->getX(), mDestination->getY());
context->line_to(x1,y1);
context->line_to(x2,y2);
context->line_to(mDestination->getX(), mDestination->getY());
context->fill();
context->set_dash(dashes,0.);
context->move_to(mOrigin->getX(), mOrigin->getY());
context->curve_to(tcxq1, tcyq1, tcxq2, tcyq2, mDestination->getX(),
mDestination->getY());
context->stroke();
context->restore();
}
开发者ID:GG31,项目名称:packages,代码行数:57,代码来源:DependencyArrow.cpp
示例13: close
static void
draw_page (GtkPrintOperation */*operation*/,
GtkPrintContext *context,
gint /*page_nr*/,
gpointer user_data)
{
struct workaround_gtkmm *junk = (struct workaround_gtkmm*)user_data;
//printf("%s %d\n",__FUNCTION__, page_nr);
if (junk->_tab->as_bitmap()) {
// Render as exported PNG
gdouble width = sp_document_width(junk->_doc);
gdouble height = sp_document_height(junk->_doc);
gdouble dpi = junk->_tab->bitmap_dpi();
std::string tmp_png;
std::string tmp_base = "inkscape-print-png-XXXXXX";
int tmp_fd;
if ( (tmp_fd = Inkscape::IO::file_open_tmp (tmp_png, tmp_base)) >= 0) {
close(tmp_fd);
guint32 bgcolor = 0x00000000;
Inkscape::XML::Node *nv = sp_repr_lookup_name (junk->_doc->rroot, "sodipodi:namedview");
if (nv && nv->attribute("pagecolor"))
bgcolor = sp_svg_read_color(nv->attribute("pagecolor"), 0xffffff00);
if (nv && nv->attribute("inkscape:pageopacity"))
bgcolor |= SP_COLOR_F_TO_U(sp_repr_get_double_attribute (nv, "inkscape:pageopacity", 1.0));
sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0,
width, height,
(unsigned long)(width * dpi / PX_PER_IN),
(unsigned long)(height * dpi / PX_PER_IN),
dpi, dpi, bgcolor, NULL, NULL, true, NULL);
// This doesn't seem to work:
//context->set_cairo_context ( Cairo::Context::create (Cairo::ImageSurface::create_from_png (tmp_png) ), dpi, dpi );
//
// so we'll use a surface pattern blat instead...
//
// but the C++ interface isn't implemented in cairomm:
//context->get_cairo_context ()->set_source_surface(Cairo::ImageSurface::create_from_png (tmp_png) );
//
// so do it in C:
{
Cairo::RefPtr<Cairo::ImageSurface> png = Cairo::ImageSurface::create_from_png (tmp_png);
cairo_t *cr = gtk_print_context_get_cairo_context (context);
cairo_matrix_t m;
cairo_get_matrix(cr, &m);
cairo_scale(cr, PT_PER_IN / dpi, PT_PER_IN / dpi);
// FIXME: why is the origin offset??
cairo_set_source_surface(cr, png->cobj(), -16.0, -16.0);
cairo_paint(cr);
cairo_set_matrix(cr, &m);
}
// Clean up
unlink (tmp_png.c_str());
}
else {
g_warning(_("Could not open temporary PNG for bitmap printing"));
}
}
else {
// Render as vectors
Inkscape::Extension::Internal::CairoRenderer renderer;
Inkscape::Extension::Internal::CairoRenderContext *ctx = renderer.createContext();
// ctx->setPSLevel(CAIRO_PS_LEVEL_3);
ctx->setTextToPath(false);
ctx->setFilterToBitmap(true);
ctx->setBitmapResolution(72);
cairo_t *cr = gtk_print_context_get_cairo_context (context);
cairo_surface_t *surface = cairo_get_target(cr);
/**
Call cairo_win32_printing_surface directly as a workaround until GTK uses this call.
When GTK uses cairo_win32_printing_surface this automatically reverts.
*/
#ifdef WIN32
if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_WIN32) {
HDC dc = cairo_win32_surface_get_dc (surface);
surface = _cairo_win32_printing_surface_create (dc);
}
#endif
bool ret = ctx->setSurfaceTarget (surface, true); if (ret) {
ret = renderer.setupDocument (ctx, junk->_doc, TRUE, NULL);
if (ret) {
renderer.renderItem(ctx, junk->_base);
ret = ctx->finish();
}
else {
g_warning(_("Could not set up Document"));
}
}
else {
g_warning(_("Failed to set CairoRenderContext"));
}
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:
示例14: on_expose_event
bool AdvEnvGUIScope::on_expose_event(GdkEventExpose* event)
{
Glib::RefPtr<Gdk::Window> window = get_window();
if (window)
{
float len, x, y, xscale, yscale;
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
cr->set_line_width(2.0);
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->paint();
cr->set_source_rgb(0.0, 0.8, 0.0);
cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
cr->clip();
cr->move_to(width, height);
len = m_valueDelay + m_valueAttackTime1 + m_valueAttackTime2 + m_valueAttackTime3 + m_valueAttackTime4 + m_valueReleaseTime1 + m_valueReleaseTime2 + m_valueReleaseTime3 + SUSTAIN_LEN;
xscale = (float) width / len;
yscale = (float) (height - 6);
x = m_valueDelay * xscale;
cr->line_to((int) x, height);
x += m_valueAttackTime1 * xscale;
y = m_valueAttackLevel1 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueAttackTime2 * xscale;
y = m_valueAttackLevel2 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueAttackTime3 * xscale;
y = m_valueAttackLevel3 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueAttackTime4 * xscale;
y = m_valueSustain * yscale;
cr->line_to((int) x, height - (int) y);
x += SUSTAIN_LEN * xscale;
cr->line_to((int) x, height - (int) y);
x += m_valueReleaseTime1 * xscale;
y = m_valueReleaseLevel1 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueReleaseTime2 * xscale;
y = m_valueReleaseLevel2 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueReleaseTime3 * xscale;
cr->line_to((int) x, height);
x = m_valueDelay * xscale;
cr->line_to((int) x, height);
cr->stroke();
}
return true;
}
开发者ID:harryhaaren,项目名称:avw.lv2,代码行数:58,代码来源:advenv_gui_scope.cpp
示例15: DrawNodeText
void NodeSurface::DrawNodeText(
Cairo::RefPtr<Cairo::Context> refCairo,
TopologyNode* pNode,
int x,
int y )
{
refCairo->save();
// Set the font parameters
refCairo->select_font_face(
"monospace",
Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_BOLD );
refCairo->set_font_size( 24 );
// Set draw color to black
refCairo->set_source_rgb(0.0, 0.0, 0.0);
char idCaption[128];
TopologyNode::NodeType nodeType = pNode->GetNodeType();
switch (nodeType)
{
case TopologyNode::COMPUTER:
sprintf( idCaption, "PC" );
break;
case TopologyNode::BUS:
{
refCairo->set_font_size( 18 );
InterfaceType interfaceType = pNode->GetInterfaceType();
switch (interfaceType)
{
case INTERFACE_IEEE1394:
sprintf( idCaption, "1394 Bus" );
break;
case INTERFACE_USB2:
sprintf( idCaption, "USB Bus" );
break;
case INTERFACE_GIGE:
sprintf( idCaption, "GigE Bus" );
break;
default:
sprintf( idCaption, "Bus" );
break;
}
}
break;
case TopologyNode::CAMERA:
sprintf( idCaption, "ID: %d", pNode->GetDeviceId() );
break;
case TopologyNode::NODE:
sprintf( idCaption, "Node" );
break;
}
Cairo::TextExtents textExtents;
refCairo->get_text_extents( idCaption, textExtents );
refCairo->move_to( x - (textExtents.width / 2) , y + (textExtents.height / 2) );
refCairo->show_text( idCaption );
refCairo->restore();
}
开发者ID:Vaa3D,项目名称:vaa3d_tools,代码行数:66,代码来源:NodeSurface.cpp
示例16: on_expose_event
bool CPagePreview::on_expose_event(GdkEventExpose *event)
{
Glib::RefPtr<Gdk::Window> window = get_window();
if(window)
{
// get the cairo context amd allocation
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
// coordinates for the center of the window
int xc, yc;
xc = width / 2;
yc = height / 2;
// clip to the area indicated by the expose event so that we only redraw
// the portion of the window that needs to be redrawn
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
cr->clip();
// draw a neat shadow
cr->set_source_rgba(0.0,0.0,0.0,0.4);
cr->begin_new_path();
cr->move_to( xborder+offset,yborder+offset );
cr->line_to( width-xborder+offset,yborder+offset );
cr->line_to( width-xborder+offset,height-yborder+offset );
cr->line_to( xborder+offset,height-yborder+offset );
cr->close_path();
cr->fill();
// draw the page outline
cr->set_source_rgb(0.0,0.0,0.0); // black
cr->set_line_width( 2.0 );
cr->begin_new_path();
cr->move_to( xborder-offset,yborder-offset );
cr->line_to( width-xborder-offset,yborder-offset );
cr->line_to( width-xborder-offset,height-yborder-offset );
cr->line_to( xborder-offset,height-yborder-offset );
cr->close_path();
cr->stroke_preserve();
// fill the page with white
cr->save();
cr->set_source_rgb(1.0,1.0,1.0); // white
cr->fill_preserve();
cr->restore();
// draw the page margin
cr->set_source_rgb( 0.8,0.8,0.8 ); // light grey
cr->set_line_width( 1.0 );
cr->begin_new_path();
cr->move_to( uleft.x, uleft.y );
cr->line_to( lright.x, uleft.y );
cr->line_to( lright.x, lright.y );
cr->line_to( uleft.x, lright.y );
cr->close_path();
cr->stroke();
// and the image preview
ImagePixbuf->render_to_drawable( get_window(),
get_style()->get_black_gc(),
0,
0,
xpos,
ypos,
ImagePixbuf->get_width(), //image->get_width(),
ImagePixbuf->get_height(), //image->get_height(),
Gdk::RGB_DITHER_NONE,0,0 ); // */
return true;
}
}
开发者ID:BackupTheBerlios,项目名称:gimmage-svn,代码行数:75,代码来源:PagePreview.cpp
|
请发表评论