60 const uint FALLBACK_FONT_SIZE_px = 12.5;
61 const uint POINT_PER_INCH = 72;
63 const double BASE_WIDTH_PER_EM = 0.5;
65 const double ORG = 0.0;
66 const double PHI = (1.0 + sqrt(5)) / 2.0;
67 const double PHI_MAJOR = PHI - 1.0;
68 const double PHI_MINOR = 2.0 - PHI;
69 const double PHISQUARE = 1.0 + PHI;
70 const double PHI_MINSQ = 5.0 - 3*PHI;
72 const double BAR_WIDTH = PHI_MINOR;
73 const double BAR_LEFT = -BAR_WIDTH;
74 const double LIN_WIDTH = PHI_MINSQ;
75 const double LIN_LEFT = PHI_MAJOR - LIN_WIDTH;
77 const double SQUARE_TIP_X = PHISQUARE - PHI_MINOR;
78 const double SQUARE_TIP_Y = -PHISQUARE;
79 const double SQUARE_MINOR = 1.0;
81 const double ARC_O_XC = -(3.0 + PHI);
82 const double ARC_O_YC = -6.8541019662496847;
83 const double ARC_O_R = 8.0574801069408135;
84 const double ARC_O_TIP = 0.5535743588970450;
85 const double ARC_O_END = 1.0172219678978512;
87 const double ARC_I_XC = -2.5;
88 const double ARC_I_YC = -7.3541019662496883;
89 const double ARC_I_R = 6.6978115661011230;
90 const double ARC_I_TIP = 0.7853981633974485;
91 const double ARC_I_END = 1.2490457723982538;
100 Pango::FontDescription font = style->get_font (Gtk::STATE_FLAG_NORMAL);
101 auto sizeSpec = double(font.get_size()) / PANGO_SCALE;
103 if (sizeSpec <=0)
return FALLBACK_FONT_SIZE_px;
104 if (not font.get_size_is_absolute())
106 auto screen = style->get_screen();
107 if (not screen)
return FALLBACK_FONT_SIZE_px;
108 double dpi = screen->get_resolution();
109 sizeSpec *= dpi / POINT_PER_INCH;
143 auto required = 2*PHISQUARE + style->get_padding().get_top()
144 + style->get_padding().get_bottom();
145 auto maxScale = givenHeight / (required);
146 return min (maxScale,
baseWidth (style));
158 +style->get_padding().get_right()
159 +style->get_padding().get_left()
167 return ceil (PHISQUARE *
baseWidth (style)
168 +style->get_padding().get_right()
169 +style->get_padding().get_left()
179 return style->get_padding().get_left()
189 return style->get_padding().get_top()
190 - scale * SQUARE_TIP_Y;
201 - (style->get_padding().get_bottom()
202 - scale * SQUARE_TIP_Y);
203 auto minHeight = PHISQUARE*scale + style->get_padding().get_top();
204 return max (lowerAnchor, minHeight);
217 drawCap (CairoC cox, Gdk::RGBA colour,
double ox,
double oy,
double scale,
bool upside=
true)
220 cox->translate (ox,oy);
221 cox->scale (scale, upside? scale:-scale);
222 cox->set_source_rgba(colour.get_red()
225 ,colour.get_alpha());
228 cox->move_to(BAR_LEFT, ORG);
229 cox->arc_negative(ARC_O_XC,ARC_O_YC,ARC_O_R, ARC_O_END, ARC_O_TIP);
232 cox->arc (ARC_I_XC,ARC_I_YC,ARC_I_R, ARC_I_TIP, ARC_I_END);
242 drawBar (CairoC cox, Gdk::RGBA colour,
double leftX,
double upperY,
double lowerY,
double scale)
245 cox->translate (leftX, upperY);
246 cox->scale (scale, scale);
247 cox->set_source_rgba(colour.get_red()
250 ,colour.get_alpha());
252 double height = max (0.0, (lowerY - upperY)/scale);
253 cox->rectangle(BAR_LEFT, -SQUARE_MINOR, BAR_WIDTH, height + 2*SQUARE_MINOR);
254 cox->rectangle(LIN_LEFT, ORG, LIN_WIDTH, height);
270 ,
double leftX,
double upperY,
double lowerY,
double width,
double scale
271 ,std::vector<uint> connectors)
273 double limit = lowerY - upperY;
274 double line = leftX + scale*(LIN_LEFT + LIN_WIDTH/2);
275 double rad = scale * PHI_MAJOR;
278 cox->translate (line, upperY);
280 cox->set_source_rgb(1 - 0.2*(colour.get_red())
281 ,1 - 0.2*(colour.get_green())
282 ,1 - 0.5*(1 - colour.get_blue()) );
284 for (uint off : connectors)
287 cox->move_to(rad,off);
288 cox->arc ( 0,off, rad, 0, 2 * M_PI);
292 cox->fill_preserve();
293 cox->set_source_rgba(colour.get_red()
296 ,colour.get_alpha());
297 cox->set_line_width(scale*LIN_WIDTH*PHI_MAJOR);
301 cox->translate(rad,0);
303 double len = width-line-rad-1;
305 double arr = len * PHI_MINOR;
306 double bas = scale * PHI_MINOR;
307 for (uint off : connectors)
310 cox->move_to(ORG,off);
311 cox->line_to(arr,off);
313 cox->move_to(arr,off-bas);
314 cox->line_to(len,off);
315 cox->line_to(arr,off+bas);
318 cox->set_miter_limit(20);
319 cox->fill_preserve();
332 StaveBracketWidget::~StaveBracketWidget() { }
334 StaveBracketWidget::StaveBracketWidget ()
338 get_style_context()->add_class (CLASS_fork_bracket);
339 this->property_expand() =
false;
357 bool event_is_handled = _Base::on_draw (cox);
359 StyleC style = this->get_style_context();
360 auto colour = style->get_color (Gtk::STATE_FLAG_NORMAL);
361 int height = this->get_allocated_height();
362 int width = this->get_width();
368 drawCap (cox, colour, left, upper, scale,
true);
369 drawCap (cox, colour, left, lower, scale,
false);
370 drawBar (cox, colour, left, upper, lower, scale);
371 connect (cox, colour, left, upper, lower, width, scale, connectors_);
373 return event_is_handled;
381 return Gtk::SizeRequestMode::SIZE_REQUEST_WIDTH_FOR_HEIGHT;
392 StyleC style = this->get_style_context();
397 StaveBracketWidget::get_preferred_width_vfunc (
int& minimum_width,
int& natural_width)
const 399 StyleC style = this->get_style_context();
Lumiera GTK UI implementation root.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Definition of access keys for uniform UI styling.