Tweaking corner case when box is small

This commit is contained in:
Dave Davenport 2017-02-08 19:48:15 +01:00
parent 1d6b1494e9
commit ef4d09be1f

View file

@ -108,36 +108,38 @@ void widget_draw ( widget *widget, cairo_t *d )
}
// Store current state.
cairo_save ( d );
int margin_left = distance_get_pixel ( widget->margin.left, ORIENTATION_HORIZONTAL );
int margin_top = distance_get_pixel ( widget->margin.top, ORIENTATION_VERTICAL );
int margin_right = distance_get_pixel ( widget->margin.right, ORIENTATION_HORIZONTAL );
int margin_bottom = distance_get_pixel ( widget->margin.bottom, ORIENTATION_VERTICAL );
const int margin_left = distance_get_pixel ( widget->margin.left, ORIENTATION_HORIZONTAL );
const int margin_top = distance_get_pixel ( widget->margin.top, ORIENTATION_VERTICAL );
const int margin_right = distance_get_pixel ( widget->margin.right, ORIENTATION_HORIZONTAL );
const int margin_bottom = distance_get_pixel ( widget->margin.bottom, ORIENTATION_VERTICAL );
const int left = distance_get_pixel ( widget->border.left, ORIENTATION_HORIZONTAL );
const int right = distance_get_pixel ( widget->border.right, ORIENTATION_HORIZONTAL );
const int top = distance_get_pixel ( widget->border.top, ORIENTATION_VERTICAL );
const int bottom = distance_get_pixel ( widget->border.bottom, ORIENTATION_VERTICAL );
int radius_bl = distance_get_pixel ( widget->border_radius.left, ORIENTATION_HORIZONTAL );
int radius_tr = distance_get_pixel ( widget->border_radius.right, ORIENTATION_HORIZONTAL );
int radius_tl = distance_get_pixel ( widget->border_radius.top, ORIENTATION_VERTICAL );
int radius_br = distance_get_pixel ( widget->border_radius.bottom, ORIENTATION_VERTICAL );
int left = distance_get_pixel ( widget->border.left, ORIENTATION_HORIZONTAL );
int right = distance_get_pixel ( widget->border.right, ORIENTATION_HORIZONTAL );
int top = distance_get_pixel ( widget->border.top, ORIENTATION_VERTICAL );
int bottom = distance_get_pixel ( widget->border.bottom, ORIENTATION_VERTICAL );
if ( ( radius_bl + radius_tl ) > ( widget->h - margin_top - margin_bottom ) ) {
int j = ( widget->h - margin_top - margin_bottom ) / 2.0;
double vspace = widget->h - margin_top - margin_bottom - top/2.0 - bottom/2.0;
double hspace = widget->w - margin_left - margin_right -left/2.0 -right/2.0;
if ( ( radius_bl + radius_tl ) > ( vspace ) ) {
int j = floor ( ( vspace ) / 2.0);
radius_bl = MIN ( radius_bl, j );
radius_tl = MIN ( radius_tl, j );
}
if ( ( radius_br + radius_tr ) > ( widget->h - margin_top - margin_bottom ) ) {
int j = ( widget->h - margin_top - margin_bottom ) / 2.0;
if ( ( radius_br + radius_tr ) > ( vspace ) ) {
int j = floor ( ( vspace ) / 2.0 );
radius_br = MIN ( radius_br, j );
radius_tr = MIN ( radius_tr, j );
}
if ( ( radius_tl + radius_tr ) > ( widget->w - margin_left - margin_right ) ) {
int j = ( widget->w - margin_left - margin_right ) / 2.0;
if ( ( radius_tl + radius_tr ) > ( hspace ) ) {
int j = floor ( ( hspace ) / 2.0 );
radius_tr = MIN ( radius_tr, j );
radius_tl = MIN ( radius_tl, j );
}
if ( ( radius_bl + radius_br ) > ( widget->w - margin_left - margin_right ) ) {
int j = ( widget->w - margin_left - margin_right ) / 2.0;
if ( ( radius_bl + radius_br ) > ( hspace ) ) {
int j = floor ( ( hspace ) / 2.0 );
radius_br = MIN ( radius_br, j );
radius_bl = MIN ( radius_bl, j );
}
@ -213,13 +215,13 @@ void widget_draw ( widget *widget, cairo_t *d )
cairo_fill( d );
}
}
if ( right > 0 ) {
double offset = (radius_tr > 0 )? top/2.0:0;
cairo_set_line_width ( d, right );
distance_get_linestyle ( widget->border.right, d );
cairo_move_to ( d, widget->w - margin_right - right / 2.0, margin_top + radius_tr +offset );
offset = ( radius_br > 0 )? bottom/2.0:0;
cairo_line_to ( d, widget->w - margin_right - right / 2.0, widget->h - margin_bottom - radius_br - offset );
if ( top > 0 ) {
double offset = (radius_tl > 0 ) ? (left/2.0):0;
cairo_set_line_width ( d, top );
distance_get_linestyle ( widget->border.top, d );
cairo_move_to ( d, margin_left + radius_tl+offset, margin_top + top / 2.0 );
offset = (radius_tr > 0 )? right/2.0:0;
cairo_line_to ( d, widget->w - margin_right - radius_tr-offset, margin_top + top / 2.0 );
cairo_stroke ( d );
}
if ( radius_tr > 0 ) {
@ -244,44 +246,13 @@ void widget_draw ( widget *widget, cairo_t *d )
cairo_fill( d );
}
}
if ( top > 0 ) {
double offset = (radius_tl > 0 ) ? (left/2.0):0;
cairo_set_line_width ( d, top );
distance_get_linestyle ( widget->border.top, d );
cairo_move_to ( d, margin_left + radius_tl+offset, margin_top + top / 2.0 );
offset = (radius_tr > 0 )? right/2.0:0;
cairo_line_to ( d, widget->w - margin_right - radius_tr-offset, margin_top + top / 2.0 );
cairo_stroke ( d );
}
if ( radius_bl > 0 ) {
distance_get_linestyle ( widget->border.left, d );
if ( bottom == left ) {
cairo_set_line_width ( d, left );
cairo_arc ( d, margin_left + left / 2.0 + radius_bl, widget->h - margin_bottom - radius_bl - left / 2.0, radius_bl, 0.5 * M_PI, 1.0 * M_PI );
cairo_stroke ( d );
}
else {
cairo_set_line_width ( d, 0 );
double minof = ceil(MIN ( left/2.0, bottom/2.0));
double radius_outer = radius_bl+minof;
double radius_inner = radius_bl-minof;
cairo_arc ( d , margin_left+radius_outer, widget->h - margin_bottom - radius_outer, radius_outer, 0.5*M_PI,M_PI);
cairo_line_to ( d , margin_left, widget->h- margin_bottom-radius_bl-ceil(bottom/2.0));
cairo_line_to ( d , margin_left+left, widget->h - margin_bottom-radius_bl-ceil(bottom/2.0));
cairo_arc_negative ( d , margin_left+left+radius_inner, widget->h - margin_bottom-bottom-radius_inner, radius_inner, M_PI, 0.5*M_PI);
cairo_line_to ( d , margin_left+radius_bl+ceil(left/2.0), widget->h - margin_bottom-bottom);
cairo_line_to ( d , margin_left+radius_bl+ceil(left/2.0), widget->h - margin_bottom );
cairo_close_path ( d );
cairo_fill ( d );
}
}
if ( bottom > 0 ) {
double offset = (radius_bl > 0 )? (left/2.0):0;
cairo_set_line_width ( d, bottom );
distance_get_linestyle ( widget->border.bottom, d );
cairo_move_to ( d, margin_left + radius_bl + offset, widget->h - bottom / 2.0 - margin_bottom );
offset = ( radius_br > 0)? (right/2.0):0;
cairo_line_to ( d, widget->w - margin_right - radius_br-offset, widget->h - bottom / 2.0 - margin_bottom );
if ( right > 0 ) {
double offset = (radius_tr > 0 )? top/2.0:0;
cairo_set_line_width ( d, right );
distance_get_linestyle ( widget->border.right, d );
cairo_move_to ( d, widget->w - margin_right - right / 2.0, margin_top + radius_tr +offset );
offset = ( radius_br > 0 )? bottom/2.0:0;
cairo_line_to ( d, widget->w - margin_right - right / 2.0, widget->h - margin_bottom - radius_br - offset );
cairo_stroke ( d );
}
if ( radius_br > 0 ) {
@ -306,6 +277,37 @@ void widget_draw ( widget *widget, cairo_t *d )
cairo_fill ( d );
}
}
if ( bottom > 0 ) {
double offset = (radius_bl > 0 )? (left/2.0):0;
cairo_set_line_width ( d, bottom );
distance_get_linestyle ( widget->border.bottom, d );
cairo_move_to ( d, margin_left + radius_bl + offset, widget->h - bottom / 2.0 - margin_bottom );
offset = ( radius_br > 0)? (right/2.0):0;
cairo_line_to ( d, widget->w - margin_right - radius_br-offset, widget->h - bottom / 2.0 - margin_bottom );
cairo_stroke ( d );
}
if ( radius_bl > 0 ) {
distance_get_linestyle ( widget->border.left, d );
if ( bottom == left ) {
cairo_set_line_width ( d, left );
cairo_arc ( d, margin_left + left / 2.0 + radius_bl, widget->h - margin_bottom - radius_bl - left / 2.0, radius_bl, 0.5 * M_PI, 1.0 * M_PI );
cairo_stroke ( d );
}
else {
cairo_set_line_width ( d, 0 );
double minof = ceil(MIN ( left/2.0, bottom/2.0));
double radius_outer = radius_bl+minof;
double radius_inner = radius_bl-minof;
cairo_arc ( d , margin_left+radius_outer, widget->h - margin_bottom - radius_outer, radius_outer, 0.5*M_PI,M_PI);
cairo_line_to ( d , margin_left, widget->h- margin_bottom-radius_bl-ceil(bottom/2.0));
cairo_line_to ( d , margin_left+left, widget->h - margin_bottom-radius_bl-ceil(bottom/2.0));
cairo_arc_negative ( d , margin_left+left+radius_inner, widget->h - margin_bottom-bottom-radius_inner, radius_inner, M_PI, 0.5*M_PI);
cairo_line_to ( d , margin_left+radius_bl+ceil(left/2.0), widget->h - margin_bottom-bottom);
cairo_line_to ( d , margin_left+radius_bl+ceil(left/2.0), widget->h - margin_bottom );
cairo_close_path ( d );
cairo_fill ( d );
}
}
cairo_restore ( d );
}
}