本文整理汇总了C++中cairo::RefPtr::fill_preserve方法的典型用法代码示例。如果您正苦于以下问题:C++ RefPtr::fill_preserve方法的具体用法?C++ RefPtr::fill_preserve怎么用?C++ RefPtr::fill_preserve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo::RefPtr
的用法示例。
在下文中一共展示了RefPtr::fill_preserve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
/** Drawing event handler. */
virtual bool
on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
switch (_curShape) {
case SHAPE_RECTANGLE:
cr->rectangle(20, 20, 200, 100);
cr->set_source_rgb(0, 0.8, 0);
cr->fill_preserve();
break;
case SHAPE_ELLIPSE:
cr->arc(150, 100, 90, 0, 2 * 3.14);
cr->set_source_rgb(0.8, 0, 0);
cr->fill_preserve();
break;
case SHAPE_TRIANGLE:
cr->move_to(40, 40);
cr->line_to(200, 40);
cr->line_to(120, 160);
cr->line_to(40, 40);
cr->set_source_rgb(0.8, 0, 0.8);
cr->fill_preserve();
cr->set_line_cap(Cairo::LINE_CAP_ROUND);
cr->set_line_join(Cairo::LINE_JOIN_ROUND);
break;
}
cr->set_line_width(3);
cr->set_source_rgb(0, 0, 0);
cr->stroke();
return true;
}
示例2:
bool
ButtonWidget::on_expose_event(GdkEventExpose* event)
{
Gtk::DrawingArea::on_expose_event(event);
Glib::RefPtr<Gdk::Window> window = get_window();
if(window)
{
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
int w = get_allocation().get_width() - 10;
int h = get_allocation().get_height() - 10;
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->set_line_width(1.0);
cr->translate(5, 5);
cr->rectangle(0, 0, w, h);
if (down)
cr->fill_preserve();
cr->stroke();
if (down)
cr->set_source_rgb(1.0, 1.0, 1.0);
// FIXME: There are better ways to center text
if (name.size() == 2)
cr->move_to(w/2-6, h/2+3);
else
cr->move_to(w/2-4, h/2+3);
cr->show_text(name);
}
return true;
}
示例3: drawRoundedRectangle
void GraphicalItem::drawRoundedRectangle(
const Cairo::RefPtr<Cairo::Context>& context,
int x, int y,
int width, int height,
double aspect,
double corner_radius,
double red, double green, double blue)
{
double radius = corner_radius / aspect;
double degrees = M_PI / 180.0;
context->begin_new_sub_path();
context->arc(x + width - radius, y + radius, radius,
-90 * degrees, 0 * degrees);
context->arc(x + width - radius, y + height - radius,
radius, 0 * degrees, 90 * degrees);
context->arc(x + radius, y + height - radius, radius,
90 * degrees, 180 * degrees);
context->arc(x + radius, y + radius, radius,
180 * degrees, 270 * degrees);
context->close_path();
context->set_source_rgb(red, green, blue);
context->fill_preserve();
setColor(Settings::settings().getForegroundColor(), context);
context->stroke();
}
示例4:
static void
skillgui_cairo_render_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
int arrow_at_end, int filled)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
__tt.ping_start(__ttc_bezier);
++__num_bezier;
#endif
//printf("Bezier\n");
SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
obj_state_t *obj = job->obj;
skillgui_cairo_set_penstyle(cairo, job);
cairo->move_to(A[0].x, -A[0].y);
for (int i = 1; i < n; i += 3)
cairo->curve_to(A[i].x, -A[i].y, A[i + 1].x, -A[i + 1].y,
A[i + 2].x, -A[i + 2].y);
if (filled) {
skillgui_cairo_set_color(cairo, &(obj->fillcolor));
cairo->fill_preserve();
}
skillgui_cairo_set_color(cairo, &(obj->pencolor));
cairo->stroke();
#ifdef USE_GVPLUGIN_TIMETRACKER
__tt.ping_end(__ttc_bezier);
#endif
}
示例5: on_expose_event
bool on_expose_event(GdkEventExpose* ev) {
Glib::RefPtr< Gdk::Window > window = get_window();
if (window) {
Cairo::RefPtr< Cairo::Context > ctx = window->create_cairo_context();
Gtk::Allocation alloc = get_allocation();
const int height = alloc.get_height();
const int width = alloc.get_width();
ctx->scale(width, height); //escala para que ocupe siempre toda la pantalla. Notar que es ancho y después alto.
ctx->set_line_width(ANCHO_LINEA);
// contorno
ctx->move_to(0.0, 1.0); // muevo hacia el punto inicial, que arbitrariamente elegí que fuera el de la izquierda abajo
ctx->line_to(0.0, 0.0); // línea hacia el punto de arriba a la izquierda
ctx->line_to(1.0, 0.0); // línea hacia el punto de arriba a la derecha
ctx->line_to(1.0, 1.0); // línea hacia el punto de abajo a la derecha
ctx->close_path(); // cierro el camino
ctx->save(); // salvo porque voy a cambiar el color
ctx->set_source_rgb(1.0, 1.0, 1.0); // seteo el color al blanco
ctx->fill_preserve(); // relleno todo el cuadrado, preservando el camino para dibujar el contorno
ctx->restore();
ctx->stroke(); // pinto el camino en negro
// triángulo azul de abajo
ctx->move_to(0.0, 1.0); // muevo hacia el punto inicial, que arbitrariamente elegí que fuera el de la izquierda
ctx->line_to(0.5, 0.5); // línea hacia el punto del medio
ctx->line_to(1.0, 1.0); // línea hacia el punto de abajo a la derecha
ctx->close_path(); // cierro el camino
ctx->save(); // salvo porque voy a cambiar el color
ctx->set_source_rgb(0.0, 0.0, 1.0); // seteo el color al azul
ctx->fill_preserve(); // relleno todo triángulo, preservando el camino para dibujar el contorno
ctx->restore();
ctx->stroke(); // pinto el camino en negro
// triángulo azul de arriba
ctx->move_to(0.0, 0.0); // muevo hacia el punto inicial, que arbitrariamente elegí que fuera el de la izquierda
ctx->line_to(0.5, 0.5); // línea hacia el punto del medio
ctx->line_to(1.0, 0.0); // línea hacia el punto de arriba a la derecha
ctx->close_path(); // cierro el camino
ctx->save(); // salvo porque voy a cambiar el color
ctx->set_source_rgb(0.0, 0.0, 1.0); // seteo el color al azul
ctx->fill_preserve(); // relleno todo triángulo, preservando el camino para dibujar el contorno
ctx->restore();
ctx->stroke(); // pinto el camino en negro
}
return true;
}
示例6: on_draw
virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
if(!drawing)
{
sort(objects.begin(), objects.end(), PlaneObjectColection::compare);
}
drawing=1;
unsigned int i;
unsigned int j;
cr->set_line_width(2);
Coordenate temp;
for(i=0; i<objects.size(); i++)
{
if(objects[i].get_num_nodos()<2 || objects[i].z>=camera.z) continue;
cr->save();
temp=get_draw_location(objects[i].get_nodo_position(0), width, height, 26.5/M_PI);
cr->line_to(temp.x, temp.y);
cr->move_to(temp.x, temp.y);
for(j=1; j<objects[i].get_num_nodos(); j++)
{
temp=get_draw_location(objects[i].get_nodo_position(j), width, height, 26.5/M_PI);
cr->line_to(temp.x, temp.y);
}
temp=get_draw_location(objects[i].get_nodo_position(0), width, height, 26.5/M_PI);
cr->line_to(temp.x, temp.y);
temp=get_draw_location(objects[i].get_nodo_position(1), width, height, 26.5/M_PI);
cr->line_to(temp.x, temp.y);
cr->set_source_rgba(double(objects[i].fill_color.red)/255, double(objects[i].fill_color.green)/255, double(objects[i].fill_color.blue)/255, double(objects[i].fill_color.alpha)/255);
cr->fill_preserve();
cr->set_source_rgba(double(objects[i].line_color.red)/255, double(objects[i].line_color.green)/255, double(objects[i].line_color.blue)/255, double(objects[i].line_color.alpha)/255);
cr->stroke();
cr->restore();
}
return 1;
}
示例7: draw_bar
// ----------------------------------------------------------------------------
// -- Function : draw_bar(cr)
// --
// -- Takes : cr = point to a cairo reference
// --
// -- Purpose : Assumes value is already between 1 and 0! Draws the bar
// on the provided cairo reference.
void BarWidget::draw_bar(Cairo::RefPtr<Cairo::Context> cr)
{
// Get our bar coords
Size size = get_avail_rect();
Size* s = &size;
// Draw the bg first
cr->set_line_width(bar_bg_border_width);
cr->rectangle(s->x, s->y, s->width, s->height);
// -- bg border
if (draw_bar_bg_border)
{
bar_bg_border_color->set_source(cr);
cr->stroke_preserve();
}
// -- bg
if (draw_bar_bg)
{
bar_bg_color->set_source(cr);
cr->fill_preserve();
}
// Clear the path
cr->begin_new_path();
// -- Now we're drawing the value bar
// Modify the size by our value / percent
// If we're horz, modify the width.
// If we're vert, modify the height.
if (vertical)
s->height = s->height * m_value;
else
s->width = s->width * m_value;
// New path, draw!
cr->set_line_width(bar_border_width);
cr->rectangle(s->x, s->y, s->width, s->height);
// -- bar border
if (draw_bar_border)
{
bar_border_color->set_source(cr);
cr->stroke_preserve();
}
// -- Draw the bar
bar_color->set_source(cr);
cr->fill();
// clean up
cr->begin_new_path();
s = nullptr;
}
示例8: renderShields
//! Only renders the shield background, the text is rendered in renderLabels
void Renderer::renderShields(const Cairo::RefPtr<Cairo::Context>& cr,
std::vector<shared_ptr<Shield> >& shields) const
{
cr->save();
cr->set_line_join(Cairo::LINE_JOIN_ROUND);
for (auto& shield : shields)
{
const Style* s = shield->style;
double x0, y0, height, width;
double border = ceil(s->shield_frame_width/2.0 + s->shield_casing_width);
x0 = shield->shield.minX + border;
y0 = shield->shield.minY + border;
width = shield->shield.getWidth() - 2*border;
height = shield->shield.getHeight() - 2*border;
if ((int) s->shield_frame_width % 2 == 1) {
x0 -= 0.5;
y0 -= 0.5;
}
if (s->shield_shape == Style::ShieldShape::ROUNDED) {
cr->arc(x0 + height/2.0, y0 + height/2.0,
height/2.0, boost::math::constants::pi<double>()/2.0, 3.0*boost::math::constants::pi<double>()/2.0);
cr->arc(x0 + width - height/2.0, y0 + height/2.0,
height/2.0, 3.0*boost::math::constants::pi<double>()/2.0, boost::math::constants::pi<double>()/2.0);
cr->close_path();
} else
cr->rectangle(x0, y0, width, height);
// shield casing
if (s->shield_casing_width > 0) {
cr->set_source_color(s->shield_casing_color),
cr->set_line_width(s->shield_frame_width + s->shield_casing_width * 2.0);
cr->stroke_preserve();
}
// shield background
cr->set_source_color(s->shield_color),
cr->fill_preserve();
// shield frame
cr->set_source_color(s->shield_frame_color),
cr->set_line_width(s->shield_frame_width);
cr->stroke();
}
cr->restore();
}
示例9: if
void BezierPath::Invocation::draw(const Cairo::RefPtr<Cairo::Context> & cr)
{
if (!path) return;
//Execute the bezier path.
path->execute(cr);
//Stroke, fill or do both.
if (stroke && fill) {
cr->fill_preserve();
cr->stroke();
}
else if (stroke) cr->stroke();
else if (fill) cr->fill();
}
示例10: DrawRoundedRectangle
void NodeSurface::DrawRoundedRectangle(
Cairo::RefPtr<Cairo::Context> refCairo,
double x,
double y,
double width,
double height,
double radius,
double red,
double green,
double blue,
bool selected )
{
refCairo->save();
if ( (radius > height/2.0) || (radius > width/2.0) )
{
radius = std::min<double>(height / 2, width / 2);
}
refCairo->move_to( x, y + radius );
refCairo->arc( x + radius, y + radius, radius, sk_pi, -sk_pi / 2.0 );
refCairo->line_to( x + width - radius, y );
refCairo->arc( x + width - radius, y + radius, radius, -sk_pi / 2.0, 0 );
refCairo->line_to( x + width, y + height - radius );
refCairo->arc( x + width - radius, y + height - radius, radius, 0, sk_pi / 2.0 );
refCairo->line_to( x + radius, y + height );
refCairo->arc( x + radius, y + height - radius, radius, sk_pi / 2.0, sk_pi );
refCairo->close_path();
refCairo->set_source_rgb( red, green, blue );
refCairo->fill_preserve();
if ( selected == true )
{
refCairo->set_source_rgb( 1.0, 0.0, 0.0 );
refCairo->set_line_width( 2 );
refCairo->stroke();
}
else
{
refCairo->set_source_rgb( 0.0, 0.0, 0.0 );
refCairo->set_line_width( 1 );
refCairo->stroke();
}
refCairo->restore();
}
示例11: draw_wheel_pos
void enigma_rotor_window::draw_wheel_pos(Cairo::RefPtr<Cairo::Context> cr, gunichar new_pos)
{
wheel_pos = new_pos;
const char *trans_2 = "00000000011111111112222222";
const char *trans_1 = "12345678901234567890123456";
int win_size = ((int)(padded_size)) - 1;
cr->save();
// Draw background of rotor window as a rectangle filled with the rotor background colour
cr->set_source_rgb(rotor_r, rotor_g, rotor_b);
cr->rectangle(x - win_size / 2, y - win_size / 2, win_size, win_size); // Set path
cr->fill_preserve(); // Fill everyting inside the path and preserve the path
// Draw black border around the path, i.e. the rectangle that represents the rotor window
cr->set_line_width(1.0);
cr->set_source_rgb(BLACK);
cr->stroke();
cr->restore();
cr->save();
// Set colour in which to draw the rotor position
if (!is_greek)
cr->set_source_rgb(BLACK); // Default is black
else
cr->set_source_rgb(RED); // The greek wheel on M4 has red markings
if (!is_numeric)
{
// rotor position is displayed as character A-Z
print_char(cr, x, y, new_pos, font_size_char);
}
else
{
// rotor position is displayed as a number 01, 02, ..., 26
print_char(cr, x - char_width_numeric / 2, y, trans_2[new_pos - 'A'], font_size_numeric);
print_char(cr, x + char_width_numeric / 2, y, trans_1[new_pos - 'A'], font_size_numeric);
}
cr->restore();
}
示例12: drawRectangle
void GraphicalItem::drawRectangle(const Cairo::RefPtr<Cairo::Context>& context,
int x, int y,
int width, int height,
double red, double green, double blue)
{
context->begin_new_sub_path();
context->move_to(x, y);
context->line_to(x + width, y);
context->line_to(x + width, y + height);
context->line_to(x, y + height);
context->line_to(x, y);
context->close_path();
context->set_source_rgb(red, green, blue);
context->fill_preserve();
setColor(Settings::settings().getForegroundColor(), context);
context->stroke();
}
示例13: on_expose_event
bool CPagePreview::on_expose_event(GdkEventExpose *event)
{
std::cout << "Fired!\n";
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();
double border = 0.05;
double offset = 2.0;
// draw a neat shadow
cr->set_source_rgba(0.0,0.0,0.0,0.4);
cr->begin_new_path();
cr->move_to( width*border+offset,height*border+offset );
cr->line_to( width*(1.0-border)+offset,height*border+offset );
cr->line_to( width*(1.0-border)+offset,height*(1.0-border)+offset );
cr->line_to( width*border+offset,height*(1.0-border)+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( 1.0 );
cr->begin_new_sub_path();
cr->move_to( width*border-offset,height*border-offset );
cr->line_to( width*(1.0-border)-offset,height*border-offset );
cr->line_to( width*(1.0-border)-offset,height*(1.0-border)-offset );
cr->line_to( width*border-offset,height*(1.0-border)-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();
// and the image preview
ImagePixbuf->render_to_drawable( get_window(),
get_style()->get_black_gc(),
0,
0,
(width-ImagePixbuf->get_width())/2,
(height-ImagePixbuf->get_height())/2,
ImagePixbuf->get_width(), //image->get_width(),
ImagePixbuf->get_height(), //image->get_height(),
Gdk::RGB_DITHER_NONE,0,0 ); // */
return true;
}
}
示例14: Exception
/** Draw laser segments as produced by leg tracker application.
* @param itf either Laser360Interface or Laser720Interface
* @param window Gdk window
* @param cr Cairo context to draw to. It is assumed that possible transformations
* have been setup before.
*/
void
LaserDrawingArea::draw_segments(const fawkes::Interface* itf,
Glib::RefPtr<Gdk::Window> &window,
const Cairo::RefPtr<Cairo::Context> &cr)
{
size_t nd = __laser_segmentation_if->maxlenof_distances();
const float nd_factor = 360.0 / nd;
float *distances;
const fawkes::Laser360Interface* itf360 = NULL;
const fawkes::Laser720Interface* itf720 = NULL;
if ((itf360 = dynamic_cast<const fawkes::Laser360Interface*>(itf))) {
distances = itf360->distances();
} else if ((itf720 = dynamic_cast<const fawkes::Laser720Interface*>(itf))) {
distances = itf720->distances();
} else {
throw fawkes::Exception("Interface is neither Laser360Interface nor Laser720Interface");
}
cr->save();
/* DRAW SEGMENTS (draw the segment interiors again with other color*/
if( __laser_segmentation_if && __laser_segmentation_if->has_writer()){
if(!__break_drawing)
__laser_segmentation_if->read();
float * segmentations = __laser_segmentation_if->distances();
size_t nd = __laser_segmentation_if->maxlenof_distances();
// cr->set_source_rgba(0,0,0,0.5);
cr->set_source_rgb(1,1,0);
if ( __draw_mode == MODE_POINTS ) {
for (size_t i = 0; i < nd; i += __resolution) {
if( segmentations[i]==0) continue; // dont draw the segment borders
if ( distances[i] == 0 || ! std::isfinite(distances[i])) continue;
float anglerad = deg2rad(i * nd_factor);
cr->move_to(0, 0);
cr->line_to(distances[i] * sin(anglerad),
distances[i] * -cos(anglerad));
}
cr->stroke();
} else {//if ( __draw_mode == MODE_LINES ) {
float radius = 4 / __zoom_factor;
for (size_t i = 0; i < nd; i += __resolution) {
if( segmentations[i]==0) continue; // dont draw the segment borders
if ( distances[i] == 0 ) continue;
float anglerad = deg2rad(i * nd_factor);
float x = distances[i] * sin(anglerad);
float y = distances[i] * -cos(anglerad);
// circles replaced by rectangles, they are a *lot* faster
//cr->move_to(x, y);
//cr->arc(x, y, radius, 0, 2*M_PI);
cr->rectangle(x, y, radius, radius);
}
cr->fill_preserve();
cr->stroke();
}
/*else {
cr->move_to(0, - distances[0]);
for (size_t i = __resolution; i <= nd + __resolution; i += __resolution) {
if ( distances[i] == 0 ) continue;
float anglerad = deg2rad(i % 360);
cr->line_to(distances[i % 360] * sin(anglerad),
distances[i % 360] * -cos(anglerad));
}
cr->stroke();
}
*/
}
cr->restore();
}
示例15: if
/** Expose event handler.
* @param event event info structure.
* @return signal return value
*/
bool
LaserDrawingArea::on_expose_event(GdkEventExpose* event)
#endif
{
// This is where we draw on the window
Glib::RefPtr<Gdk::Window> window = get_window();
if(window) {
Gtk::Allocation allocation = get_allocation();
if(__first_draw)
{
__first_draw = false;
const int width = allocation.get_width();
const int height = allocation.get_height();
// coordinates for the center of the window
__xc = width / 2;
__yc = height / 2;
}
#if GTK_VERSION_LT(3,0)
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
#endif
cr->set_line_width(1.0);
cr->set_source_rgb(1, 1, 1);
#if GTK_VERSION_LT(3,0)
// 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->fill_preserve();
cr->clip();
#else
cr->paint();
#endif
cr->set_source_rgb(0, 0, 0);
//cr->set_source_rgba(0,0,0,1);
// __last_xc += __translation_x;
// __last_yc += __translation_y;
cr->translate(__xc, __yc);
cr->save();
if (! __connected) {
Cairo::TextExtents te;
std::string t = "Not connected to BlackBoard";
cr->set_source_rgb(1, 0, 0);
cr->set_font_size(20);
cr->get_text_extents(t, te);
cr->move_to(- te.width / 2, -te.height / 2);
cr->show_text(t);
} else if ( __laser_ifs.empty() ) {
Cairo::TextExtents te;
std::string t = "No interface opened";
cr->set_source_rgb(1, 0, 0);
cr->set_font_size(20);
cr->get_text_extents(t, te);
cr->move_to(- te.width / 2, -te.height / 2);
cr->show_text(t);
} else if (! all_laser_ifs_have_writer() ) {
Cairo::TextExtents te;
std::string t = "No writer for ";
for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
it != __laser_ifs.end(); ++it) {
fawkes::Interface* itf = it->first;
if (!itf->has_writer()) {
t += itf->uid();
t += ' ';
}
}
cr->set_source_rgb(1, 0, 0);
cr->set_font_size(20);
cr->get_text_extents(t, te);
cr->move_to(- te.width / 2, -te.height / 2);
cr->show_text(t);
} else {
if (! __break_drawing) {
for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
it != __laser_ifs.end(); ++it) {
fawkes::Interface* laser_if = it->first;
laser_if->read();
}
}
for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
it != __laser_ifs.end(); ++it) {
const fawkes::Interface* laser_if = it->first;
const Color& color = it->second;
cr->save();
cr->set_source_rgb(color.r, color.g, color.b);
draw_beams(laser_if, window, cr);
cr->restore();
}
if (__robot_drawer) __robot_drawer->draw_robot(window, cr);
for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
it != __laser_ifs.end(); ++it) {
//.........这里部分代码省略.........