69 const uint FALLBACK_FONT_SIZE_px = 12.5;
70 const uint POINT_PER_INCH = 72;
72 const double BASE_WIDTH_PER_EM = 0.5;
74 const double ORG = 0.0;
75 const double PHI = (1.0 + sqrt(5)) / 2.0;
76 const double PHI_MAJOR = PHI - 1.0;
77 const double PHI_MINOR = 2.0 - PHI;
78 const double PHISQUARE = 1.0 + PHI;
79 const double PHI_MINSQ = 5.0 - 3*PHI;
81 const double BAR_WIDTH = PHI_MINOR;
82 const double BAR_LEFT = -BAR_WIDTH;
83 const double LIN_WIDTH = PHI_MINSQ;
84 const double LIN_LEFT = PHI_MAJOR - LIN_WIDTH;
86 const double SQUARE_TIP_X = PHISQUARE - PHI_MINOR;
87 const double SQUARE_TIP_Y = -PHISQUARE;
88 const double SQUARE_MINOR = 1.0;
90 const double ARC_O_XC = -(3.0 + PHI);
91 const double ARC_O_YC = -6.8541019662496847;
92 const double ARC_O_R = 8.0574801069408135;
93 const double ARC_O_TIP = 0.5535743588970450;
94 const double ARC_O_END = 1.0172219678978512;
96 const double ARC_I_XC = -2.5;
97 const double ARC_I_YC = -7.3541019662496883;
98 const double ARC_I_R = 6.6978115661011230;
99 const double ARC_I_TIP = 0.7853981633974485;
100 const double ARC_I_END = 1.2490457723982538;
109 Pango::FontDescription font = style->get_font (Gtk::STATE_FLAG_NORMAL);
110 auto sizeSpec = double(font.get_size()) / PANGO_SCALE;
112 if (sizeSpec <=0)
return FALLBACK_FONT_SIZE_px;
113 if (not font.get_size_is_absolute())
115 auto screen = style->get_screen();
116 if (not screen)
return FALLBACK_FONT_SIZE_px;
117 double dpi = screen->get_resolution();
118 sizeSpec *= dpi / POINT_PER_INCH;
152 auto required = 2*PHISQUARE + style->get_padding().get_top()
153 + style->get_padding().get_bottom();
154 auto maxScale = givenHeight / (required);
155 return min (maxScale,
baseWidth (style));
167 +style->get_padding().get_right()
168 +style->get_padding().get_left()
176 return ceil (PHISQUARE *
baseWidth (style)
177 +style->get_padding().get_right()
178 +style->get_padding().get_left()
188 return style->get_padding().get_left()
198 return style->get_padding().get_top()
199 - scale * SQUARE_TIP_Y;
210 - (style->get_padding().get_bottom()
211 - scale * SQUARE_TIP_Y);
212 auto minHeight = PHISQUARE*scale + style->get_padding().get_top();
213 return max (lowerAnchor, minHeight);
226 drawCap (CairoC cox, Gdk::RGBA colour,
double ox,
double oy,
double scale,
bool upside=
true)
229 cox->translate (ox,oy);
230 cox->scale (scale, upside? scale:-scale);
231 cox->set_source_rgba(colour.get_red()
234 ,colour.get_alpha());
237 cox->move_to(BAR_LEFT, ORG);
238 cox->arc_negative(ARC_O_XC,ARC_O_YC,ARC_O_R, ARC_O_END, ARC_O_TIP);
241 cox->arc (ARC_I_XC,ARC_I_YC,ARC_I_R, ARC_I_TIP, ARC_I_END);
251 drawBar (CairoC cox, Gdk::RGBA colour,
double leftX,
double upperY,
double lowerY,
double scale)
254 cox->translate (leftX, upperY);
255 cox->scale (scale, scale);
256 cox->set_source_rgba(colour.get_red()
259 ,colour.get_alpha());
261 double height = max (0.0, (lowerY - upperY)/scale);
262 cox->rectangle(BAR_LEFT, -SQUARE_MINOR, BAR_WIDTH, height + 2*SQUARE_MINOR);
263 cox->rectangle(LIN_LEFT, ORG, LIN_WIDTH, height);
279 ,
double leftX,
double upperY,
double lowerY,
double width,
double scale
280 ,std::vector<uint> connectors)
282 double limit = lowerY - upperY;
283 double line = leftX + scale*(LIN_LEFT + LIN_WIDTH/2);
284 double rad = scale * PHI_MAJOR;
287 cox->translate (line, upperY);
289 cox->set_source_rgb(1 - 0.2*(colour.get_red())
290 ,1 - 0.2*(colour.get_green())
291 ,1 - 0.5*(1 - colour.get_blue()) );
293 for (uint off : connectors)
296 cox->move_to(rad,off);
297 cox->arc ( 0,off, rad, 0, 2 * M_PI);
301 cox->fill_preserve();
302 cox->set_source_rgba(colour.get_red()
305 ,colour.get_alpha());
306 cox->set_line_width(scale*LIN_WIDTH*PHI_MAJOR);
310 cox->translate(rad,0);
312 double len = width-line-rad-1;
314 double arr = len * PHI_MINOR;
315 double bas = scale * PHI_MINOR;
316 for (uint off : connectors)
319 cox->move_to(ORG,off);
320 cox->line_to(arr,off);
322 cox->move_to(arr,off-bas);
323 cox->line_to(len,off);
324 cox->line_to(arr,off+bas);
327 cox->set_miter_limit(20);
328 cox->fill_preserve();
341 StaveBracketWidget::~StaveBracketWidget() { }
343 StaveBracketWidget::StaveBracketWidget ()
347 get_style_context()->add_class (CLASS_fork_bracket);
348 this->property_expand() =
false;
366 bool event_is_handled = _Base::on_draw (cox);
368 StyleC style = this->get_style_context();
369 auto colour = style->get_color (Gtk::STATE_FLAG_NORMAL);
370 int height = this->get_allocated_height();
371 int width = this->get_width();
377 drawCap (cox, colour, left, upper, scale,
true);
378 drawCap (cox, colour, left, lower, scale,
false);
379 drawBar (cox, colour, left, upper, lower, scale);
380 connect (cox, colour, left, upper, lower, width, scale, connectors_);
382 return event_is_handled;
390 return Gtk::SizeRequestMode::SIZE_REQUEST_WIDTH_FOR_HEIGHT;
401 StyleC style = this->get_style_context();
406 StaveBracketWidget::get_preferred_width_vfunc (
int& minimum_width,
int& natural_width)
const 408 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.