Int getDistanceArea(Area a, Area b) { InitAreaA; InitAreaB; NormaliseArea(ax, ay, aw, ah); NormaliseArea(bx, by, bw, bh); if (overlapArea(a, b) == SUCCEED) answer(ZERO); if (ay+ah < by) { if (bx+bw < ax) answer(toInt(distance(bx+bw, by, ax, ay+ah))); if (bx > ax+aw) answer(toInt(distance(ax+aw, ay+ah, bx, by))); answer(toInt(by-(ay+ah))); } if (by+bh < ay) { if (ax+aw < bx) answer(toInt(distance(ax+aw, ay, bx, by+bh))); if (bx+bw < ax) answer(toInt(distance(bx+bw, by+bh, ax, ay))); answer(toInt(ay-(by+bh))); } if (ax+aw < bx) answer(toInt(bx-(ax+aw))); answer(toInt(ax-(bx+bw))); }
status intersectionArea(Area a, Area b) { int x, y, w, h; Name orientation; InitAreaA; InitAreaB; orientation = OrientationArea(aw, ah); NormaliseArea(ax, ay, aw, ah); NormaliseArea(bx, by, bw, bh); x = (ax > bx ? ax : bx); y = (ay > by ? ay : by); w = (ax + aw < bx + bw ? ax + aw : bx + bw) - x; h = (ay + ah < by + bh ? ay + ah : by + bh) - y; if (w < 0 || h < 0) fail; OrientateArea(x, y, w, h, orientation); assign(a, x, toInt(x)); assign(a, y, toInt(y)); assign(a, w, toInt(w)); assign(a, h, toInt(h)); succeed; }
static status unionArea(Area a, Area b) { int x, y, w, h; Name orientation; if ( b->w == ZERO && b->h == ZERO ) succeed; if ( a->w == ZERO && a->h == ZERO ) { copyArea(a, b); return normaliseArea(a); } { InitAreaA; InitAreaB; orientation = OrientationArea(aw, ah); NormaliseArea(ax, ay, aw, ah); NormaliseArea(bx, by, bw, bh); x = (ax < bx ? ax : bx); y = (ay < by ? ay : by); w = (ax + aw > bx + bw ? ax + aw : bx + bw) - x; h = (ay + ah > by + bh ? ay + ah : by + bh) - y; OrientateArea(x, y, w, h, orientation); assign(a, x, toInt(x)); assign(a, y, toInt(y)); assign(a, w, toInt(w)); assign(a, h, toInt(h)); } succeed; }
static status equalArea(Area a, Area b) { InitAreaA; InitAreaB; NormaliseArea(ax, ay, aw, ah); NormaliseArea(bx, by, bw, bh); if (ax == bx && ay == by && aw == bw && ah == bh) succeed; fail; }
static Int getNearSidesArea(Area a, Area b, Int distance) { int d=valInt(distance); int a_top, a_center, a_bottom, a_left, a_middle, a_right; int b_top, b_center, b_bottom, b_left, b_middle, b_right; register unsigned long mask; InitAreaA; InitAreaB; NormaliseArea(ax, ay, aw, ah); NormaliseArea(bx, by, bw, bh); a_top = ay; a_bottom = ay+ah-1; a_center = (a_top+a_bottom+1)/2; a_left = ax; a_right = ax+aw-1; a_middle = (a_left+a_right+1)/2; b_top = by; b_bottom = by+bh-1; b_center = (b_top+b_bottom+1)/2; b_left = bx; b_right = bx+bw-1; b_middle = (b_left+b_right+1)/2; mask = 0; NEAR(a_top, b_top, d, mask, 01); NEAR(a_top, b_center, d, mask, 02); NEAR(a_top, b_bottom, d, mask, 04); NEAR(a_center, b_top, d, mask, 010); NEAR(a_center, b_center, d, mask, 020); NEAR(a_center, b_bottom, d, mask, 040); NEAR(a_bottom, b_top, d, mask, 0100); NEAR(a_bottom, b_center, d, mask, 0200); NEAR(a_bottom, b_bottom, d, mask, 0400); NEAR(a_left, b_left, d, mask, 01000); NEAR(a_left, b_middle, d, mask, 02000); NEAR(a_left, b_right, d, mask, 04000); NEAR(a_middle, b_left, d, mask, 010000); NEAR(a_middle, b_middle, d, mask, 020000); NEAR(a_middle, b_right, d, mask, 040000); NEAR(a_right, b_left, d, mask, 0100000); NEAR(a_right, b_middle, d, mask, 0200000); NEAR(a_right, b_right, d, mask, 0400000); answer(toInt(mask)); }
status overlapArea(Area a, Area b) { InitAreaA; InitAreaB; NormaliseArea(ax, ay, aw, ah); NormaliseArea(bx, by, bw, bh); if (by >= ay+ah || by+bh <= ay || bx >= ax+aw || bx+bw <= ax) fail; succeed; }
status insideArea(Area a, Area b) { InitAreaA; InitAreaB; NormaliseArea(ax, ay, aw, ah); NormaliseArea(bx, by, bw, bh); if (bx < ax) fail; if (bx+bw > ax+aw-1) fail; if (by < ay) fail; if (by+bh > ay+ah-1) fail; succeed; }
static Area getNormalisedArea(Area a) { InitAreaA; NormaliseArea(ax, ay, aw, ah); answer(answerObject(ClassArea, toInt(ax), toInt(ay), toInt(aw), toInt(ah), EAV)); }
status RedrawAreaButton(Button b, Area a) { int x, y, w, h; int defb; int rm = 0; /* right-margin */ PceWindow sw; int kbf; /* Button has keyboard focus */ int obhf; /* Other button has focus */ int focus; int swapbg = FALSE; int up; int flags = 0; Elevation z; if ( b->look == NAME_winMenuBar || b->look == NAME_gtkMenuBar ) return RedrawMenuBarButton(b, a); if ( b->active == OFF ) flags |= LABEL_INACTIVE; up = (b->status == NAME_active || b->status == NAME_inactive); defb = (b->default_button == ON); initialiseDeviceGraphical(b, &x, &y, &w, &h); NormaliseArea(x, y, w, h); if ( (sw = getWindowGraphical((Graphical)b)) ) { kbf = (sw->keyboard_focus == (Graphical) b); obhf = (!kbf && instanceOfObject(sw->keyboard_focus, ClassButton)); focus = (sw->input_focus == ON); } else kbf = obhf = focus = FALSE; /* should not happen */ if ( !ws_draw_button_face((DialogItem)b, x, y, w, h, up, defb, kbf && focus) ) draw_generic_button_face(b, x, y, w, h, up, defb, kbf && focus); if ( b->look == NAME_openLook && b->status == NAME_preview && !((z = getClassVariableValueObject(b, NAME_elevation)) && notNil(z)) ) { swapbg = TRUE; r_swap_background_and_foreground(); } if ( notNil(b->popup) && !instanceOfObject(b->label, ClassImage) ) rm = draw_button_popup_indicator(b, x, y, w, h, up); RedrawLabelDialogItem(b, accelerator_code(b->accelerator), x, y, w-rm, h, NAME_center, NAME_center, flags); if ( swapbg ) r_swap_background_and_foreground(); return RedrawAreaGraphical(b, a); }
static status normaliseArea(Area a) { if ( valInt(a->w) < 0 || valInt(a->h) < 0 ) { InitAreaA; NormaliseArea(ax, ay, aw, ah); ExitAreaA; } succeed; }
static status inArea(Area a, Int x, Int y) { InitAreaA; NormaliseArea(ax, ay, aw, ah); if (valInt(x) >= ax && valInt(x) <= ax+aw && valInt(y) >= ay && valInt(y) <= ay+ah) succeed; fail; }
static status RedrawAreaCircle(Circle c, Area a) { int x, y, w, h; initialiseDeviceGraphical(c, &x, &y, &w, &h); NormaliseArea(x, y, w, h); r_thickness(valInt(c->pen)); r_dash(c->texture); r_ellipse(x, y, w, h, c->fill_pattern); return RedrawAreaGraphical(c, a); }
static status RedrawMenuBarButton(Button b, Area a) { int x, y, w, h; Any ofg = NIL; int flags = 0; initialiseDeviceGraphical(b, &x, &y, &w, &h); NormaliseArea(x, y, w, h); if ( b->status == NAME_preview ) { Elevation e; if ( b->look == NAME_gtkMenuBar && (e = getClassVariableValueObject(b, NAME_previewElevation)) && notNil(e) ) { r_3d_box(x, y, w, h, 0, e, TRUE); } else /* if ( b->look == NAME_winMenuBar ) */ { Any fg = getClassVariableValueObject(b, NAME_selectedForeground); Any bg = getClassVariableValueObject(b, NAME_selectedBackground); if ( !fg ) fg = WHITE_COLOUR; if ( !bg ) bg = BLACK_COLOUR; r_fill(x, y, w, h, bg); ofg = r_colour(fg); } } if ( b->active == OFF ) flags |= LABEL_INACTIVE; RedrawLabelDialogItem(b, accelerator_code(b->accelerator), x, y, w, h, NAME_center, NAME_center, flags); if ( notNil(ofg) ) r_colour(ofg); succeed; }
static status RedrawAreaSlider(Slider s, Area a) { int x, y, w, h; int ny, vx, vy, lx, ly, sx, sy, hx, hy; int vv; int bw = (s->look == NAME_x ? BAR_WIDTH : OL_BOX_WIDTH); float lv = convert_value(s->low); float hv = convert_value(s->high); float dv = convert_value(s->displayed_value); int lflags = (s->active == ON ? 0 : LABEL_INACTIVE); if ( dv < lv ) dv = lv; else if ( dv > hv ) dv = hv; if ( hv > lv ) vv = rfloat(((float) (valInt(s->width) - bw) * (dv - lv)) / (hv - lv)); else vv = 0; initialiseDeviceGraphical(s, &x, &y, &w, &h); NormaliseArea(x, y, w, h); r_thickness(valInt(s->pen)); r_dash(s->texture); compute_slider(s, &ny, &vx, &vy, &lx, &ly, &sx, &sy, &hx, &hy); r_clear(x, y, w, h); if ( s->show_label == ON ) { int ex = valInt(getExFont(s->label_font)); RedrawLabelDialogItem(s, accelerator_code(s->accelerator), x, y+ny, vx-ex, 0, s->label_format, NAME_top, lflags); } if ( s->look == NAME_motif ) { int by = y+sy+(SLIDER_HEIGHT-OL_BAR_HEIGHT)/2; int ex = x + sx + valInt(s->width); Elevation z = getClassVariableValueObject(s, NAME_elevation); r_3d_box(x+sx, by, vv, OL_BAR_HEIGHT, 0, z, FALSE); r_3d_box(x+sx+vv+bw, by, ex-(x+sx+vv+bw), OL_BAR_HEIGHT, 0, z, FALSE); r_3d_box(x+sx+vv, y+sy, bw, SLIDER_HEIGHT, 0, z, TRUE); } else if ( s->look == NAME_openLook ) { int by = y+sy+(SLIDER_HEIGHT-OL_BAR_HEIGHT)/2; int ly2 = by+OL_BAR_HEIGHT-1; int ex = x + sx + valInt(s->width); r_fill(x+sx, by+1, 1, OL_BAR_HEIGHT-2, BLACK_IMAGE); r_fill(x+sx+1, by, vv-2, OL_BAR_HEIGHT, BLACK_IMAGE); r_line(x+sx+1+vv+bw, by, ex-2, by); r_line(x+sx+1+vv+bw, ly2, ex-2, ly2); r_line(ex-1, by+1, ex-1, ly2-1); r_shadow_box(x+sx+vv, y+sy, bw, SLIDER_HEIGHT, 0, 1, NIL); } else { r_fill(x+sx, y+sy, vv, SLIDER_HEIGHT, GREY50_IMAGE); r_box(x+sx, y+sy, valInt(s->width), SLIDER_HEIGHT, 0, NIL); r_fill(x+sx+vv, y+sy, bw, SLIDER_HEIGHT, BLACK_IMAGE); } if ( s->show_value == ON ) { char buf[100]; string str; buf[0] = '['; format_value(s, &buf[1], s->displayed_value); strcat(buf, "]"); str_set_ascii(&str, buf); str_label(&str, 0, s->value_font, x+vx, y+vy, 0, 0, NAME_left, NAME_top, lflags); format_value(s, buf, s->low); str_set_ascii(&str, buf); str_label(&str, 0, s->value_font, x+lx, y+ly, 0, 0, NAME_left, NAME_top, lflags); format_value(s, buf, s->high); str_set_ascii(&str, buf); str_label(&str, 0, s->value_font, x+hx, y+hy, 0, 0, NAME_left, NAME_top, lflags); } return RedrawAreaGraphical(s, a); }