本文整理汇总了C++中cairo::RefPtr::get_text_extents方法的典型用法代码示例。如果您正苦于以下问题:C++ RefPtr::get_text_extents方法的具体用法?C++ RefPtr::get_text_extents怎么用?C++ RefPtr::get_text_extents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo::RefPtr
的用法示例。
在下文中一共展示了RefPtr::get_text_extents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2:
void
Operation::draw_title(const Glib::RefPtr<Gtk::PrintContext>& print)
{
double pos_x, pos_y;
Cairo::RefPtr<Cairo::Context> cairo = print->get_cairo_context();
DICOM::SummaryInfo* info = const_cast<DICOM::SummaryInfo*>(&dicom_info_);
DICOM::StudyInfo* study = info->get_study_info();
// Show Institution Name
cairo->set_font_size(title_font_size_);
Cairo::TextExtents cur_ext, prev_ext;
cairo->get_text_extents( study->get_institution_name(), cur_ext);
pos_x = (width_ - cur_ext.width) / 2.;
pos_y = cur_ext.height + OFFSET;
cairo->move_to( pos_x, pos_y);
cairo->show_text(study->get_institution_name());
// Show Institution Address
prev_ext = cur_ext;
cairo->set_font_size(subtitle_font_size_);
cairo->get_text_extents( study->get_institution_address(), cur_ext);
pos_x = -(prev_ext.width + prev_ext.x_bearing +
cur_ext.width + cur_ext.x_bearing) / 2.;
pos_y = cur_ext.height + OFFSET;
cairo->rel_move_to( pos_x, pos_y);
cairo->show_text(study->get_institution_address());
// Show Study Description
prev_ext = cur_ext;
cairo->set_font_size(title_font_size_);
cairo->get_text_extents( study->get_description(), cur_ext);
pos_x = -(prev_ext.width + prev_ext.x_bearing +
cur_ext.width + cur_ext.x_bearing) / 2.;
pos_y = cur_ext.height + OFFSET;
cairo->rel_move_to( pos_x, pos_y);
cairo->show_text(study->get_description());
pos_x = -(width_ + cur_ext.width) / 2.;
pos_y = cur_ext.height + OFFSET;
cairo->rel_move_to( pos_x, pos_y);
cairo->stroke_preserve();
}
示例3: 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();
}
示例4: label
void NodeRenderer::label(const Cairo::RefPtr<Cairo::Context>& cr,
std::list<shared_ptr<Label> >& labels,
AssetCache& cache)
{
// nothing to print
if (s->text.str().size() == 0 || s->font_size <= 0)
return;
cr->save();
cr->set_font_size(s->font_size);
cr->set_font_face(cache.getFont(
s->font_family.str(),
s->font_style == Style::STYLE_ITALIC ? Cairo::FONT_SLANT_ITALIC : Cairo::FONT_SLANT_NORMAL,
s->font_weight == Style::WEIGHT_BOLD ? Cairo::FONT_WEIGHT_BOLD : Cairo::FONT_WEIGHT_NORMAL
));
Cairo::TextExtents textSize;
cr->get_text_extents(s->text.str(), textSize);
addLabel(labels, location + FloatPoint(0.0, s->text_offset), textSize);
cr->restore();
}
示例5: 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();
}
}
}
}
示例6: draw_centered_text
void cairo::draw_centered_text( const Cairo::RefPtr<Cairo::Context>& cr, const std::string& utf8, const cairo_coord_t& pos )
{
cr->save();
Cairo::TextExtents texts;
cr->get_text_extents( utf8, texts );
cr->move_to( pos[0] - texts.width/2. - texts.x_bearing , pos[1] );
cr->show_text( utf8 );
cr->restore();
}
示例7: 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();
}
}
示例8: renderLabels
void renderLabels(Cairo::RefPtr<Cairo::Context> cr, std::vector<std::pair<string, FloatPoint> >& toPlace) {
cr->save();
cr->set_source_rgba(0.0, 0.0, 0.0, 0.5);
Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(DEFAULT_FONT, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_face(font);
cr->set_font_size(120.0);
cr->set_line_width(2.0);
Cairo::TextExtents textSize;
std::list<shared_ptr<Label> > labels;
int i = 0;
std::vector<shared_ptr<Style>> styles;
for (auto& pair : toPlace)
{
string& text = pair.first;
cr->get_text_extents(text, textSize);
shared_ptr<Style> s = boost::make_shared<Style>();
s->text = text;
styles.push_back(s);
FloatPoint center = pair.second + FloatPoint(textSize.width/2.0, textSize.height/2.0);
FloatRect owner = FloatRect(center.x, center.y, center.x, center.y);
FloatPoint origin = pair.second - FloatPoint(textSize.x_bearing, textSize.y_bearing);
shared_ptr<Label> l = boost::make_shared<Label>(FloatRect(pair.second, textSize.width, textSize.height), owner, s->text, s.get(), origin);
cr->rectangle(l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
cr->stroke();
labels.push_back(l);
}
std::vector<shared_ptr<Label> > placed;
placeLabels(labels, placed);
for (auto& l: placed)
{
cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);
cr->move_to(l->box.minX, l->box.maxY);
cr->show_text(l->style->text.str());
cr->fill();
cr->set_source_rgba(1.0, 0.0, 0.0, 0.5);
cr->rectangle(l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
cr->fill();
}
cr->restore();
}
示例9: label
void NodeRenderer::label(const Cairo::RefPtr<Cairo::Context>& cr,
std::list<shared_ptr<Label> >& labels)
{
// nothing to print
if (s->text.str().size() == 0 || s->font_size <= 0)
return;
cr->save();
cr->set_font_size(s->font_size);
Cairo::TextExtents textSize;
cr->get_text_extents(s->text.str(), textSize);
addLabel(labels, location, textSize);
cr->restore();
}
示例10: determineColor
void guiRenderer2D::drawMatrices(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height, bool screenshot) {
cr->scale(m_scaleFactor, m_scaleFactor); // Scale sensor to fit the active window
cr->translate(m_offsetX, m_offsetY); // Center figure on drawable/surface
cr->set_line_width(0.25);
for(uint m = 0; m < m_frameManager->getNumMatrices(); m++) {
matrixInfo &matrix = m_frameManager->getMatrixInfo(m);
// TSFrame* tsFrame = m_frameManager->getCurrentFrame();
TSFrame* tsFrame = m_frameManager->getCurrentFilteredFrame();
for(uint y = 0; y < matrix.cells_y; y++) {
for(uint x = 0; x < matrix.cells_x; x++) {
bool maskedStatic = m_frameManager->getStaticMask(m, x, y);
bool maskedDynamic = m_frameManager->getDynamicMask(m, x, y);
uint cellID = matrix.texel_offset + y * matrix.cells_x + x;
float value = tsFrame->cells[cellID];
if(maskedStatic) {
RGB color = determineColor(value);
// Draw sensor cell rectangle
cr->rectangle(m_rectangleTopLeftX[cellID], m_rectangleTopLeftY[cellID], m_rectangleWidth[cellID], m_rectangleHeight[cellID]);
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->stroke_preserve(); // Cell outline
if(maskedDynamic) {
if(value > 0.0) {
cr->set_source_rgb(color.r, color.g, color.b); // Active cells
} else {
cr->set_source_rgb(1.0, 1.0, 1.0); // Inactive cells
}
} else {
cr->set_source_rgb(0.8, 0.8, 0.8); // Disabled cells
}
cr->fill();
}
// Highlight selected cells
if(m_frameManager->isSelected(cellID)) {
cr->rectangle(m_rectangleTopLeftX[cellID], m_rectangleTopLeftY[cellID], m_rectangleWidth[cellID], m_rectangleHeight[cellID]);
cr->set_source_rgba(0.0, 1.0, 0.0, 0.5); // Fill active cells
cr->fill();
}
if(screenshot) {
if(maskedStatic) {
// Print values
Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create("LMSans10", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_face(font);
cr->set_font_size(matrix.texel_width/3);
std::ostringstream ss;
ss << value;
std::string valueStr = ss.str();
Cairo::TextExtents te;
cr->get_text_extents(valueStr, te);
cr->move_to(m_matrixCellCenterX[cellID]-te.width/2, m_matrixCellCenterY[cellID]+te.height/2);
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->show_text(valueStr);
}
}
}
}
if(!screenshot) {
{
// Print Matrix IDs
Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create("LMSans10", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_face(font);
cr->set_font_size(matrix.cells_x*matrix.texel_width);
std::ostringstream ss;
ss << m;
std::string idString = ss.str();
Cairo::TextExtents te;
cr->get_text_extents(idString, te);
cr->move_to(m_newCenterX[m]-te.width/2, m_newCenterY[m]+te.height/2);
cr->set_source_rgba(0.3, 0.3, 0.3, 0.3);
cr->show_text(idString);
}
}
}
}
示例11: 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();
}
示例12: 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) {
//.........这里部分代码省略.........
示例13: on_expose_event
bool CalibrationArea::on_expose_event(GdkEventExpose *event)
{
// check that screensize did not change
if (display_width != get_width() ||
display_height != get_height()) {
set_display_size(get_width(), get_height());
}
Glib::RefPtr<Gdk::Window> window = get_window();
if (window) {
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
cr->save();
cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
cr->clip();
// Print the text
cr->set_font_size(font_size);
double text_height = -1;
double text_width = -1;
Cairo::TextExtents extent;
for (int i = 0; i != help_lines; i++) {
cr->get_text_extents(help_text[i], extent);
text_width = std::max(text_width, extent.width);
text_height = std::max(text_height, extent.height);
}
text_height += 2;
double x = (display_width - text_width) / 2;
double y = (display_height - text_height) / 2 - 60;
cr->set_line_width(2);
cr->rectangle(x - 10, y - (help_lines*text_height) - 10,
text_width + 20, (help_lines*text_height) + 20);
// Print help lines
y -= 3;
for (int i = help_lines-1; i != -1; i--) {
cr->get_text_extents(help_text[i], extent);
cr->move_to(x + (text_width-extent.width)/2, y);
cr->show_text(help_text[i]);
y -= text_height;
}
cr->stroke();
// Draw the points
for (int i = 0; i <= calibrator->get_numclicks(); i++) {
// set color: already clicked or not
if (i < calibrator->get_numclicks())
cr->set_source_rgb(1.0, 1.0, 1.0);
else
cr->set_source_rgb(0.8, 0.0, 0.0);
cr->set_line_width(1);
cr->move_to(X[i] - cross_lines, Y[i]);
cr->rel_line_to(cross_lines*2, 0);
cr->move_to(X[i], Y[i] - cross_lines);
cr->rel_line_to(0, cross_lines*2);
cr->stroke();
cr->arc(X[i], Y[i], cross_circle, 0.0, 2.0 * M_PI);
cr->stroke();
}
// Draw the clock background
cr->arc(display_width/2, display_height/2, clock_radius/2, 0.0, 2.0 * M_PI);
cr->set_source_rgb(0.5, 0.5, 0.5);
cr->fill_preserve();
cr->stroke();
cr->set_line_width(clock_line_width);
cr->arc(display_width/2, display_height/2, (clock_radius - clock_line_width)/2,
3/2.0*M_PI, (3/2.0*M_PI) + ((double)time_elapsed/(double)max_time) * 2*M_PI);
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->stroke();
// Draw the message (if any)
if (message != NULL) {
// Frame the message
cr->set_font_size(font_size);
Cairo::TextExtents extent;
cr->get_text_extents(this->message, extent);
text_width = extent.width;
text_height = extent.height;
x = (display_width - text_width) / 2;
y = (display_height - text_height + clock_radius) / 2 + 60;
cr->set_line_width(2);
cr->rectangle(x - 10, y - text_height - 10,
text_width + 20, text_height + 25);
// Print the message
cr->move_to(x, y);
cr->show_text(this->message);
cr->stroke();
}
cr->restore();
}
//.........这里部分代码省略.........
示例14: 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();
}
示例15: 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();
}