本文整理汇总了C++中cairo::RefPtr::select_font_face方法的典型用法代码示例。如果您正苦于以下问题:C++ RefPtr::select_font_face方法的具体用法?C++ RefPtr::select_font_face怎么用?C++ RefPtr::select_font_face使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo::RefPtr
的用法示例。
在下文中一共展示了RefPtr::select_font_face方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sprintf
void Format7DrawingArea::DrawDisabledText(Cairo::RefPtr<Cairo::Context> refCairo)
{
refCairo->save();
// Set the font parameters
refCairo->select_font_face(
"monospace",
Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_BOLD );
refCairo->set_font_size( 10 );
// Set draw color to black
refCairo->set_source_rgb(0.0, 0.0, 0.0);
// Print current cursor position
char cursorPosition[128];
sprintf(
cursorPosition,
"Custom Image is not supported by this camera.");
// Get width / height of widget
int width;
int height;
get_window()->get_size( width, height );
Cairo::TextExtents textExtents;
refCairo->get_text_extents( cursorPosition, textExtents );
refCairo->move_to(
(width/2) - (textExtents.width/2),
(height/2) + textExtents.height + (textExtents.height/2));
refCairo->show_text( cursorPosition );
refCairo->restore();
}
示例2: sprintf
void Format7DrawingArea::DrawImageDimensionsText(
Cairo::RefPtr<Cairo::Context> refCairo,
unsigned int left, unsigned int top, unsigned int width, unsigned int height )
{
refCairo->save();
// Set the font parameters
refCairo->select_font_face(
"monospace",
Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_BOLD );
refCairo->set_font_size( 10 );
// Set draw color to black
refCairo->set_source_rgb(0.0, 0.0, 0.0);
// Get width / height of widget
int widgetWidth = 0;
int widgetHeight = 0;
get_window()->get_size( widgetWidth, widgetHeight );
// Create text for image offset
char imageOffsets[128];
sprintf(
imageOffsets,
"Start: (%d,%d) End: (%d,%d)",
left,
top,
left + width,
top + height );
Cairo::TextExtents offsetExtents;
refCairo->get_text_extents(imageOffsets, offsetExtents);
// Draw the offset text
refCairo->move_to(
(widgetWidth/2) - (offsetExtents.width/2),
(widgetHeight/2) - offsetExtents.height - (offsetExtents.height/2));
refCairo->show_text( imageOffsets );
// Create text for image dimensions
char imageDimensions[128];
sprintf(
imageDimensions,
"Dimensions: %d x %d",
width,
height);
Cairo::TextExtents dimensionsExtents;
refCairo->get_text_extents(imageDimensions, dimensionsExtents);
// Draw the dimensions text
refCairo->move_to(
(widgetWidth/2) - (dimensionsExtents.width/2),
(widgetHeight/2) + dimensionsExtents.height + (dimensionsExtents.height/2));
refCairo->show_text( imageDimensions );
refCairo->restore();
}
示例3: draw
void ICLayerLineString::draw(Cairo::RefPtr<Cairo::Context> cr, double scale,
std::set<int> select, bool DisplayID, double Alpha)
{
std::map<int, ICLayerObject*>::iterator it;
for (it = m_ICLayerObject.begin(); it != m_ICLayerObject.end(); it++)
{
if ((*it).second->selfIdExisting())
{
bool isSelect = false;
if (!select.empty())
{
std::set<int>::iterator it2;
it2 = select.find((*it).first);
if (it2 != select.end() && (*it2) == (*it).first)
{
drawLine(cr, (*it).second->getOGRGeometryObject(), scale, true);
isSelect = true;
} else
drawLine(cr, (*it).second->getOGRGeometryObject(), scale, false);
} else
drawLine(cr, (*it).second->getOGRGeometryObject(), scale, false);
if (DisplayID)
{
Cairo::TextExtents extents;
std::stringstream str;
str << (*it).first;
std::string text = str.str();
cr->select_font_face("Bitstream Vera Sans, Arial", Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_size(12 / scale);
Cairo::FontOptions font_options;
font_options.set_hint_style(Cairo::HINT_STYLE_NONE);
font_options.set_hint_metrics(Cairo::HINT_METRICS_OFF);
font_options.set_antialias(Cairo::ANTIALIAS_GRAY);
cr->set_font_options(font_options);
cr->save();
cr->get_text_extents(text, extents);
cr->move_to((*it).second->getCentroid().first,
(*it).second->getCentroid().second);
cr->scale(1, -1);
if (isSelect)
cr->set_source_rgba(0, 0, 0, Alpha);
cr->show_text(text);
cr->stroke();
cr->restore();
}
}
}
}
示例4: draw
/* Draw the word cairo at NUM_TEXT different angles */
void draw(Cairo::RefPtr<Cairo::Context> cr, int width, int height)
{
int i, x_off, y_off;
Cairo::TextExtents extents;
std::string text("cairo");
cr->select_font_face("Bitstream Vera Sans", Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_size(TEXT_SIZE);
Cairo::FontOptions font_options;
font_options.set_hint_style(Cairo::HINT_STYLE_NONE);
font_options.set_hint_metrics(Cairo::HINT_METRICS_OFF);
font_options.set_antialias(Cairo::ANTIALIAS_GRAY);
cr->set_font_options(font_options);
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->translate(width / 2.0, height / 2.0);
cr->get_text_extents(text, extents);
if (NUM_TEXT == 1)
{
x_off = y_off = 0;
}
else
{
y_off = (int) - floor(0.5 + extents.height / 2.0);
x_off = (int) floor(0.5 + (extents.height + 1.0) / (2.0 * tan (M_PI / NUM_TEXT)));
}
for (i=0; i < NUM_TEXT; i++)
{
cr->save();
cr->rotate(2 * M_PI * i / NUM_TEXT);
cr->set_line_width(1.0);
cr->set_source_rgb(1, 0, 0);
cr->stroke();
cr->move_to(x_off - extents.x_bearing, y_off - extents.y_bearing);
cr->set_source_rgb(0, 0, 0);
cr->show_text("Five Lights!");
cr->restore();
}
}
示例5: draw
void ConsoleWindow::draw(Cairo::RefPtr<Cairo::Context> ctx)
{
ctx->save();
ctx->set_source_rgba(0, 0, 0, 0.8);
ctx->paint();
ctx->set_source_rgba(1, 1, 1, 0.3);
ctx->move_to(0, height - 0.5);
ctx->line_to(width, height - 0.5);
ctx->set_line_width(1);
ctx->stroke();
ctx->restore();
ctx->move_to(10, 16);
ctx->set_source_rgb(1, 1, 1);
ctx->select_font_face("Menlo", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
ctx->set_font_size(13);
ctx->show_text(input);
}
示例6:
void
Operation::on_begin_print(const Glib::RefPtr<Gtk::PrintContext>& print)
{
width_ = print->get_width();
height_ = print->get_height();
//Get a Cairo Context, which is used as a drawing board:
Cairo::RefPtr<Cairo::Context> cairo = print->get_cairo_context();
cairo->select_font_face( "Sans", Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_NORMAL);
//We'll use black letters:
cairo->set_source_rgb( 0, 0, 0);
draw_title(print);
draw_patient_info(print);
draw_study_info(print);
}
示例7: TitleBar
void TitleBar( Cairo::RefPtr<Cairo::Context> cr, float x, float y, float xS, float yS, std::string name, bool active)
{
if ( active )
setColour(cr, COLOUR_GREEN_1 );
else
setColour(cr, COLOUR_GREY_1 );
cr->rectangle(x,y, xS, 15);
cr->set_line_width(2.8);
cr->fill();
cr->select_font_face ("Impact" , Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_size ( 13 );
cr->move_to ( x + 8, y + 13 );
cr->set_source_rgb( 0 / 255.f, 0/255.f , 0/255.f );
cr->show_text ( name );
//std::cout << "LupppWidget::TitleBar() called!" << std::endl;
}
示例8: on_expose_event
bool GMasterReturn::on_expose_event(GdkEventExpose* event)
{
// This is where we draw on the window
Glib::RefPtr<Gdk::Window> window = get_window();
if(window) // Only run if Window does exist
{
// clip to the area indicated by the expose event so that we only redraw
// the portion of the window that needs to be redrawn
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
cr->clip();
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
cr->set_source_rgb(0.1 , 0.1 , 0.1 );
cr->fill();
Dial(cr, true, 35 , 0, value, DIAL_MODE_SEND ); // fader
// Dial text "A"
cr->select_font_face ("Impact" , Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD);
cr->set_font_size ( 20 );
cr->move_to ( 10, 28);
switch ( ID )
{
case 0: setColour(cr, COLOUR_BLUE_1 ); cr->show_text ( "A" ); break;
case 1: setColour(cr, COLOUR_BLUE_1 ); cr->show_text ( "B" ); break;
case 2: setColour(cr, COLOUR_BLUE_1 ); cr->show_text ( "C" ); break;
}
}
return true;
}
示例9: 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 2.0 Bus" );
break;
case INTERFACE_USB3:
sprintf( idCaption, "USB 3.0 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:
PGRGuid blankGuid;
if(pNode->GetGuid() == blankGuid)
sprintf( idCaption, "Node" );
else
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();
}
示例10: DrawRowColGridLabels
void HistogramDrawingArea::DrawRowColGridLabels(
Cairo::RefPtr<Cairo::Context> refCairo,
unsigned int numPixelValues,
unsigned int numValues )
{
// Reserve the outside 10%
float paddedLeft, paddedTop, paddedWidth, paddedHeight;
GetPaddedSize( paddedLeft, paddedTop, paddedWidth, paddedHeight );
refCairo->save();
// Set draw color
refCairo->set_source_rgb(0, 0, 0);
// Set the font parameters
refCairo->select_font_face(
"monospace",
Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_BOLD );
refCairo->set_font_size( 10 );
const int k_numPartitions = 8;
for ( int i=0; i <= k_numPartitions; i++ )
{
const float fraction = i / static_cast<float>(k_numPartitions);
char caption[32];
float dimensionValue = numValues * fraction;
sprintf(
caption,
"%.0f",
dimensionValue );
const float xOffset = paddedLeft + (paddedWidth * fraction);
const float yOffset = paddedTop + paddedHeight + (paddedTop/2);
Cairo::TextExtents textExtents;
refCairo->get_text_extents( caption, textExtents );
refCairo->move_to(
xOffset - (textExtents.width / 2),
yOffset + (textExtents.height / 2) );
refCairo->show_text( caption );
}
for ( int i=1; i <= k_numPartitions; i++ )
{
const float fraction = i / static_cast<float>(k_numPartitions);
char caption[32];
float pixelValue = numPixelValues * fraction;
sprintf(
caption,
"%.0f",
pixelValue );
float yOffset = paddedTop + paddedHeight - (paddedHeight * fraction);
Cairo::TextExtents textExtents;
refCairo->get_text_extents( caption, textExtents );
refCairo->move_to(
(paddedLeft/2) - (textExtents.width / 2),
yOffset + (textExtents.height / 2) );
refCairo->show_text( caption );
}
refCairo->restore();
}
示例11: DrawHistogramGridLabels
void HistogramDrawingArea::DrawHistogramGridLabels( Cairo::RefPtr<Cairo::Context> refCairo )
{
// Reserve the outside 10%
float paddedLeft, paddedTop, paddedWidth, paddedHeight;
GetPaddedSize( paddedLeft, paddedTop, paddedWidth, paddedHeight );
refCairo->save();
// Set draw color
refCairo->set_source_rgb(0, 0, 0);
// Set the font parameters
refCairo->select_font_face(
"monospace",
Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_BOLD );
refCairo->set_font_size( 10 );
const int k_numPartitions = 8;
// Render the x-axis labels
for ( int i=0; i <= k_numPartitions; i++ )
{
const float fraction = i / static_cast<float>(k_numPartitions);
unsigned int maxNumPixelValues = 0;
for ( int j=0; j < ImageStatistics::NUM_STATISTICS_CHANNELS; j++ )
{
unsigned int numPixelValues = 0;
m_histogramStats.GetNumPixelValues(
static_cast<ImageStatistics::StatisticsChannel>(j),
&numPixelValues );
maxNumPixelValues = std::max( numPixelValues, maxNumPixelValues );
}
char caption[32];
float pixelValue;
if ( maxNumPixelValues == 0 )
{
pixelValue = 256 * fraction;
}
else
{
pixelValue = maxNumPixelValues * fraction;
}
sprintf(
caption,
"%.0f",
pixelValue );
const float xOffset = paddedLeft + (paddedWidth * fraction);
const float yOffset = paddedTop + paddedHeight + (paddedTop/2); //height - paddedTop;
Cairo::TextExtents textExtents;
refCairo->get_text_extents( caption, textExtents );
refCairo->move_to(
xOffset - (textExtents.width / 2),
yOffset + (textExtents.height / 2) );
refCairo->show_text( caption );
}
// Render the y-axis labels
for ( int i=1; i < k_numPartitions; i++ )
{
if ( i % 2 != 0 )
{
continue;
}
const float fraction = i / static_cast<float>(k_numPartitions);
float scaleRatio = 100 / static_cast<float>(m_maxVal);
float yOffset = paddedTop + paddedHeight - (paddedHeight * fraction * scaleRatio);
char caption[32];
sprintf(
caption,
"%u%%",
(i*100)/k_numPartitions );
if ( yOffset > paddedTop )
{
Cairo::TextExtents textExtents;
refCairo->get_text_extents( caption, textExtents );
refCairo->move_to(
(paddedLeft / 2) - (textExtents.width / 2),
yOffset + (textExtents.height / 2) );
refCairo->show_text( caption );
}
}
refCairo->restore();
}
示例12: on_expose_event
bool knob::on_expose_event(GdkEventExpose* event)
{
// This is where we draw on the window
Glib::RefPtr<Gdk::Window> window = get_window();
if(window)
{
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height() - (allocation.get_height()/3);
const int height_offset = allocation.get_height()/6;
// coordinates for the center of the window
int xc, yc;
xc = width / 2;
yc = height / 2;
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
cr->set_line_width(6.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->clip();
// background grad
Cairo::RefPtr<Cairo::LinearGradient> back_grad =
Cairo::LinearGradient::create( 0,0,0,allocation.get_height() );
switch (pos_mode)
{
case 0:
back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1);
back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1);
break;
case 1:
back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1);
back_grad->add_color_stop_rgba(1,
(bottom_colour.get_red_p() + top_colour.get_red_p())/2,
(bottom_colour.get_green_p() + top_colour.get_green_p())/2,
(bottom_colour.get_blue_p() + top_colour.get_blue_p())/2,
1);
break;
case 2:
back_grad->add_color_stop_rgba(0,
(bottom_colour.get_red_p() + top_colour.get_red_p())/2,
(bottom_colour.get_green_p() + top_colour.get_green_p())/2,
(bottom_colour.get_blue_p() + top_colour.get_blue_p())/2,
1);
back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1);
break;
}
// fill background
if (rounded<5)
{
rounded_rectangle(cr,rounded, grad_top_colour,
grad_bottom_colour, event->area.x, event->area.y,
event->area.width, event->area.height,pos_mode,
top_colour.to_string(),bottom_colour.to_string() );
}
else
{
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
}
cr->set_source(back_grad);
cr->fill();
// ------------------------------------------------------------------
float cos_x = (allocation.get_width()/5) * (cos(((((1-knob_value)*0.75)-0.3)*2) * M_PI));
float sin_y = (allocation.get_width()/5) * (sin(((((1-knob_value)*0.75)-0.3)*2) * M_PI));
Cairo::RefPtr<Cairo::RadialGradient> grad1 =
Cairo::RadialGradient::create( (allocation.get_width()/2) + sin_y, (allocation.get_height()/2) + cos_x, 0, (allocation.get_width()/2) , (allocation.get_height()/2) ,(allocation.get_width()/2.5));
grad1->add_color_stop_rgba(0,0.4,0.4,0.4,1);
grad1->add_color_stop_rgba(0.5,0.2,0.2,0.2,1);
grad1->add_color_stop_rgba(0.8,0.17,0.17,0.17,1);
grad1->add_color_stop_rgba(1.0,0.0,0.0,0.0,1);
cos_x = (allocation.get_width()/5) * (cos((((knob_value*0.75)-0.61)*2) * M_PI));
sin_y = (allocation.get_width()/5) * (sin((((knob_value*0.75)-0.61)*2) * M_PI));
cr->set_source(grad1);
cr->arc(allocation.get_width()/2, allocation.get_height()/2, (allocation.get_width()/2.5), 0.0, 2 * M_PI);
cr->fill();
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->arc((allocation.get_width()/2) +cos_x, (allocation.get_height()/2)+sin_y, (allocation.get_width()/16), 0.0, 2 * M_PI);
cr->fill();
// draw text label
cr->select_font_face("Bitstream Vera Sans", Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_NORMAL);
//.........这里部分代码省略.........
示例13:
Cairo::RefPtr<Cairo::ImageSurface>
TextSurface::create_cairo_surface(const std::string& text, const TextProperties& text_props,
Cairo::TextExtents& out_text_extents,
Cairo::FontExtents& out_font_extents)
{
{ // get TextExtents and FontExtents
Cairo::RefPtr<Cairo::ImageSurface> tmp_surface = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, 0, 0);
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(tmp_surface);
cr->set_font_size(text_props.get_font_size());
cr->select_font_face(text_props.get_font(), Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
cr->get_text_extents(text, out_text_extents);
cr->get_font_extents(out_font_extents);
}
Cairo::RefPtr<Cairo::ImageSurface>
surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
static_cast<int>(out_text_extents.width + text_props.get_line_width()),
static_cast<int>(out_text_extents.height + text_props.get_line_width()));
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
// set the font
cr->set_font_size(text_props.get_font_size());
cr->select_font_face(text_props.get_font(), Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
if (text_props.get_line_width() != 0)
{
// create path
cr->move_to(-out_text_extents.x_bearing + text_props.get_line_width()/2.0,
-out_text_extents.y_bearing + text_props.get_line_width()/2.0);
cr->text_path(text);
// paint
cr->set_line_width(text_props.get_line_width());
cr->set_line_join(Cairo::LINE_JOIN_ROUND);
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->stroke();
}
// print text
cr->move_to(-out_text_extents.x_bearing + text_props.get_line_width()/2.0,
-out_text_extents.y_bearing + text_props.get_line_width()/2.0);
cr->set_source_rgb(1.0, 1.0, 0.0);
double y = -out_text_extents.y_bearing - out_font_extents.ascent;
// toying around with color gradients
if (false)
{
Cairo::RefPtr<Cairo::LinearGradient> gradient = Cairo::LinearGradient::create(0, y,
0, y + out_font_extents.ascent + out_font_extents.descent);
gradient->add_color_stop_rgb(0.0, 1.0, 1.0, 0.0);
gradient->add_color_stop_rgb(0.5, 1.0, 1.0, 1.0);
gradient->add_color_stop_rgb(0.5, 0.4, 0.4, 0.2);
gradient->add_color_stop_rgb(1.0, 1.0, 1.0, 0.0);
cr->set_source(gradient);
}
cr->show_text(text);
return surface;
}
示例14: 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
}
示例15: draw
void Switch::draw(const Cairo::RefPtr<Cairo::Context>& cr){
cr->save();
cr->translate(parent->xoffset + x, y);
/*
cr->set_source_rgb(200.0/256.0, 200.0/256.0, 215.0/256.0);
cr->set_source_rgb(140.0/256.0, 140.0/256.0, 150.0/256.0);
cr->set_source_rgb(160.0/256.0, 160.0/256.0, 170.0/256.0);
*/
cr->set_source_rgb(200.0/256.0, 200.0/256.0, 215.0/256.0);
cr->arc(0,0, 10, 0.0, 2*M_PI);
cr->fill();
//hole
cr->set_source_rgb(30.0/256.0, 30.0/256.0, 30.0/256.0);
cr->arc(0,0, 7, 0.0, 2*M_PI);
cr->fill();
//handle
const double len = 15.0;
double endx, endy;
if(!vertical){
if(value) {endx = len; endy = 0.0;}
else {endx = -len; endy = 0.0;}
}else{
if(value) {endx = 0.0; endy = len;}
else {endx = 0.0; endy = -len;}
}
cr->set_line_width(6.0);
cr->set_line_cap(Cairo::LINE_CAP_ROUND);
cr->set_source_rgb(1.0,1.0,1.0);
cr->move_to(0.0,0.0);
cr->line_to(endx,endy);
cr->stroke();
cr->set_source_rgb(170.0/256.0, 170.0/256.0, 170.0/256.0);
cr->move_to(endx,endy);
cr->arc(endx,endy,4,0.0,2*M_PI);
cr->fill();
//text
cr->select_font_face("Verdana",Cairo::FONT_SLANT_NORMAL,Cairo::FONT_WEIGHT_BOLD);
cr->set_font_size(10.0);
cr->set_source_rgb(1.0,1.0,1.0);
Cairo::TextExtents tx;
if(!vertical){
cr->get_text_extents(text1,tx);
cr->move_to(-tx.width - 24.0, 3.0 );
cr->show_text(text1);
cr->get_text_extents(text2,tx);
cr->move_to(22.0, 3.0 );
cr->show_text(text2);
}else{
cr->get_text_extents(text1,tx);
cr->move_to(-tx.width/2.0, -22.0 );
cr->show_text(text1);
cr->move_to(-tx.width/2.0, 27.0 );
cr->get_text_extents(text2,tx);
cr->show_text(text2);
}
cr->restore();
}