FromROSLib 27.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/***************************************************/
/* File   : FromROSLib.c                           */
17
/*                                                 */
18 19 20 21 22 23 24 25 26
/* Purpose: The original Customer browser sources */
/*          used RISC_OSLib heavily and some of    */
/*          the functions used are handy to have   */
/*          around. This source file contains      */
/*          a variety of functions from RISC_OSLib */
/*          with modifications where necessary     */
/*          both to fit into the browser more      */
/*          naturally, and to function better      */
/*          under C release 5.                     */
27
/*                                                 */
28 29
/* Authors: Various for original RISC_OSLib source */
/*          This source adapted by A.D.Hodgkinson  */
30 31
/*                                                 */
/* History: 06-Dec-96: Created.                    */
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
/***************************************************/

#include <stdlib.h>
#include <stdarg.h>

#include "swis.h"

#include "wimp.h"

#include "FromROSLib.h"

/* Statics */

/* Array of length of sequence for vdu codes, */
/* used by the VDU call-based functions.      */

static char Qlen[32] =
{

  1,   /* VDU 0                          */
  2,   /* Next character to printer only */
  1,   /* Printer on                     */
  1,   /* Printer off                    */
  1,   /* Print at text cursor           */
  1,   /* Print at graphics cursor       */
  1,   /* Enable VDU driver              */
  1,   /* Beep                           */
  1,   /* Backspace                      */
  1,   /* Forward space (horizontal tab) */
  1,   /* Line feed                      */
  1,   /* Up a line                      */
  1,   /* Clear (text) screen            */
  1,   /* Carriage return                */
  1,   /* Page mode on                   */
  1,   /* Page mode off                  */
  1,   /* Clear graphics window          */
  2,   /* Define text colour             */
  3,   /* Define graphics colour         */
  6,   /* Define logical colour          */
  1,   /* Restore default palette        */
  1,   /* Disable VDU drivers            */
  2,   /* Select screen mode             */
  10,  /* VDU 23,..                      */
  9,   /* Set graphics window            */
  6,   /* PLOT ...                       */
  1,   /* Restore default windows        */
  1,   /* ESCAPE char - no effect        */
  5,   /* Define text window             */
  5,   /* Define graphics origin         */
  1,   /* Home cursor                    */
  3    /* Tab cursor                     */

};       /* ...and all the rest are 1. */

/* Cached eigen values */

static int wimpt_xeig = 2;
static int wimpt_yeig = 2;

/*************************************************/
/* bbc_modevar()                                 */
/*                                               */
/* Returns the value of a mode variable, or -1   */
/* if there was some error.                      */
/*                                               */
97 98 99 100 101 102 103
/* Parameters: A mode number or -1 for current;  */
/*                                               */
/*             A mode variable (for the SWI call */
/*             OS_ReadModeVariable).             */
/*                                               */
/* Returns:    The value of the variable, or -1  */
/*             if an error occurs.               */
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
/*************************************************/

int bbc_modevar(int mode, int varno)
{
  int result;

  if (_swix(OS_ReadModeVariable,
            _INR(0,1) | _OUT (2),
            mode,
            varno,
            &result)) return -1;

  return result;
}

/*************************************************/
/* bbc_vduvar()                                  */
/*                                               */
/* Returns the value of a VDU variable, or -1 to */
/* flag an error - therefore, if the variable    */
/* may hold -1 as a valid value, you need to use */
/* bbc_vduvars() instead.                        */
/*                                               */
127 128 129 130 131
/* Parameters: A VDU variable number for the     */
/*             SWI call OS_ReadVduVariables.     */
/*                                               */
/* Returns:    The value of the variable, or -1  */
/*             if an error occurs.               */
132 133 134 135 136 137
/*************************************************/

int bbc_vduvar(int varno)
{
   int vars[2];
   int result;
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
   vars[0] = varno;
   vars[1] = -1; /* terminator */

   return _swix(OS_ReadVduVariables,
                _INR(0,1),
                vars,
                &result)
                != NULL ? -1 : result; /* relies on -1 never being valid */
}

/*************************************************/
/* bbc_vduvars()                                 */
/*                                               */
/* Returns values of any number of VDU variables */
/*                                               */
/* Parameters: A pointer to a block holding a    */
/*             list of variable numbers,         */
156 157
/*             termianted by -1;                 */
/*                                               */
158 159 160 161 162
/*             A pointer to a block into which   */
/*             the corresponding variable values */
/*             will be placed. This may be the   */
/*             same block as the one holding the */
/*             variable numbers.                 */
163 164 165 166 167
/*                                               */
/* Returns:    The block holding the variable    */
/*             numbers is updated with the       */
/*             variable values, assuming the     */
/*             call doesn't return an error.     */
168 169 170 171 172 173
/*************************************************/

_kernel_oserror * bbc_vduvars(int * vars, int * values)
{
   return _swix(OS_ReadVduVariables,
                _INR(0,1),
174

175 176 177 178 179 180 181 182 183 184
                (int) vars,
                (int) values);
}

/*************************************************/
/* bbc_vduq()                                    */
/*                                               */
/* Output multiple characters. Runs through an   */
/* assembler routine bbc_vdu for speed.          */
/*                                               */
185 186 187 188 189
/* Parameters: A control character - the number  */
/*             of further characters to expect   */
/*             is defined in the static 'Qlen',  */
/*             defined at the top of this file,  */
/*             and depends on the char given.    */
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
/*************************************************/

_kernel_oserror * bbc_vduq(int c,...)
{
   _kernel_oserror * e;
   va_list           ap;
   int               n;

   e = bbc_vdu(c); /* See FromROSLib.s */

   if ((c >= ' ') || e) return(e);

   va_start(ap, c);
   n = Qlen[c];

   while ((--n) && (!e)) e = bbc_vdu(va_arg(ap,int));

   va_end(ap);

   return(e);
}

/*************************************************/
/* bbc_clg()                                     */
/*                                               */
/* Clears the current graphics window.           */
/*************************************************/

_kernel_oserror * bbc_clg(void)
{
  return (bbc_vdu(BBC_ClearGraph));
}

/*************************************************/
/* bbc_gwindow()                                 */
/*                                               */
/* Defines a graphics window.                    */
/*                                               */
228 229 230 231 232 233 234 235 236 237 238
/* Parameters: X coordinate of bottom left hand  */
/*             corner of graphics window in OS   */
/*             units, inclusive;                 */
/*                                               */
/*             Y coordinate for the same;        */
/*                                               */
/*             X coordinate of top right hand    */
/*             corner of graphics window in OS   */
/*             units, exclusive;                 */
/*                                               */
/*             Y coordinate for the same.        */
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
/*************************************************/

_kernel_oserror * bbc_gwindow(int xmin, int ymin, int xmax, int ymax)
{
  _kernel_oserror * e = bbc_vdu(BBC_DefGraphWindow);

  if (!e) e = bbc_vduw(xmin);
  if (!e) e = bbc_vduw(ymin);
  if (!e) e = bbc_vduw(xmax);
  if (!e) e = bbc_vduw(ymax);

  return e;
}

/*************************************************/
/* bbc_origin()                                  */
/*                                               */
/* Sets the graphics plotting origin.            */
/*                                               */
258 259 260 261
/* Parameters: X coordinate of origin, in OS     */
/*             units;                            */
/*                                               */
/*             Y coordinate for the same.        */
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
/*************************************************/

_kernel_oserror * bbc_origin(int x, int y)
{
   _kernel_oserror * e = bbc_vdu(BBC_DefGraphOrigin);

   if (!e) e = bbc_vduw(x);
   if (!e) e = bbc_vduw(y);

   return e;
}

/*************************************************/
/* bbc_gcol()                                    */
/*                                               */
/* Sets a graphics colour and plotting action.   */
/*                                               */
/* Graphics plotting actions:                    */
/*                                               */
/* P is pixel on screen.                         */
/* N is new colour.                              */
/*                                               */
/* Action  Behaviour                             */
/*                                               */
/* 0       P = N                                 */
/* 1       P |= N (OR)                           */
/* 2       P &= N (AND)                          */
/* 3       P = P ^ N (XOR)                       */
/* 4       P = !P (NOT)                          */
/* 5       P = P (no change to screen colour)    */
/* 6       P &= (!N) (AND NOT)                   */
/* 7       P |= (!N) (OR NOT)                    */
/* 8 -15   As 0-7 but background is transparent  */
/* 16-31   Pattern 1, with action 0 - 15         */
/* 32-47   Pattern 2, with action 0 - 15         */
/* 48-63   Pattern 3, with action 0 - 15         */
/* 64-79   Pattern 4, with action 0 - 15         */
/* 80-95   Large pattern, with action 0 - 15     */
300 301 302 303 304 305 306 307 308 309
/*                                               */
/* Parameters: Plotting action (see above);      */
/*                                               */
/*             Graphics colour (0-127 for the    */
/*             foreground, else background is    */
/*             set to colour - 128). The colour  */
/*             used is ANDed with the maximum    */
/*             number of colours for the screen  */
/*             mode (1,3, 15 or 63 for 2, 4, 16  */
/*             or >=256 colour modes).           */
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
/*************************************************/

_kernel_oserror * bbc_gcol(int a, int b)
{
   _kernel_oserror * e = bbc_vdu(BBC_DefGraphColour);

   if (!e) e = bbc_vdu(a);
   if (!e) e = bbc_vdu(b);

   return e;
}

/*************************************************/
/* bbc_plot()                                    */
/*                                               */
325 326 327 328
/* Plot something on the screen with OS_Plot.    */
/* See PRM volume 1 page 607 for full details.   */
/*                                               */
/* Parameters: Plot number;                      */
329
/*                                               */
330 331 332
/*             X coordinate;                     */
/*                                               */
/*             Y coordinate.                     */
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
/*************************************************/

_kernel_oserror * bbc_plot(int n, int x, int y)
{
  return _swix(OS_Plot,
               _INR(0,2),
               n,
               x,
               y);
}

/*************************************************/
/* bbc_move()                                    */
/*                                               */
/* Move the graphics cursor to absolute coords.  */
/*                                               */
349 350 351 352
/* Parameters: X coordinate to move to, in OS    */
/*             units;                            */
/*                                               */
/*             Y coordinate for the same.        */
353 354 355 356 357 358 359 360 361 362 363 364
/*************************************************/

_kernel_oserror * bbc_move(int x, int y)
{
   return bbc_plot(BBC_MoveCursorAbs, x, y);
}

/*************************************************/
/* bbc_moveby()                                  */
/*                                               */
/* Move the graphics cursor to absolute coords.  */
/*                                               */
365 366 367
/* Parameters: X offset to move by, in OS units; */
/*                                               */
/*             Y coordinate for the same.        */
368 369 370 371 372 373 374 375 376 377 378 379 380 381
/*************************************************/

_kernel_oserror * bbc_moveby(int x, int y)
{
   return bbc_plot(BBC_MoveCursorRel, x, y);
}

/*************************************************/
/* bbc_draw()                                    */
/*                                               */
/* Draws a solid line including both end points  */
/* to absolute coordinates, starting the line at */
/* the current graphics cursor position.         */
/*                                               */
382 383 384 385
/* Parameters: X coordinate to draw to, in OS    */
/*             units;                            */
/*                                               */
/*             Y coordinate for the same.        */
386 387 388 389 390 391 392 393 394 395 396 397 398 399
/*************************************************/

_kernel_oserror * bbc_draw(int x, int y)
{
   return bbc_plot(BBC_SolidBoth + BBC_DrawAbsFore, x, y);
}

/*************************************************/
/* bbc_drawby()                                  */
/*                                               */
/* Draws a solid line including both end points  */
/* to relative coordinates, starting the line at */
/* the current graphics cursor position.         */
/*                                               */
400 401 402
/* Parameters: X offset to draw by, in OS units; */
/*                                               */
/*             Y coordinate for the same.        */
403 404 405 406 407 408 409 410 411 412 413 414
/*************************************************/

_kernel_oserror * bbc_drawby(int x, int y)
{
   return bbc_plot(BBC_SolidBoth + BBC_DrawRelFore, x, y);
}

/*************************************************/
/* bbc_rectangle()                               */
/*                                               */
/* Plots a rectangle outline.                    */
/*                                               */
415 416 417 418 419 420 421 422 423 424 425 426 427
/* Parameters: X coordinate of bottom left hand  */
/*             corner, in OS units;              */
/*                                               */
/*             Y coordinate for the same;        */
/*                                               */
/*             Rectangle width plus one, in OS   */
/*             units - this is added to the X    */
/*             value to produce an *exclusive*   */
/*             top right hand corner coordinate, */
/*             hence for an 8 OS unit wide       */
/*             rectangle, say, you'd pass in 7;  */
/*                                               */
/*             Similarly, the rectangle height.  */
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
/*************************************************/

_kernel_oserror * bbc_rectangle(int x, int y, int w, int h)
{
   _kernel_oserror * e = bbc_move(x,y);

   if (!e) e = bbc_plot(BBC_SolidExFinal + BBC_DrawRelFore,  0,  h);
   if (!e) e = bbc_plot(BBC_SolidExFinal + BBC_DrawRelFore,  w,  0);
   if (!e) e = bbc_plot(BBC_SolidExFinal + BBC_DrawRelFore,  0, -h);
   if (!e) e = bbc_plot(BBC_SolidExFinal + BBC_DrawRelFore, -w,  0);

   return e;
}

/*************************************************/
/* bbc_rectanglefill()                           */
/*                                               */
/* Plots a filled rectangle.                     */
/*                                               */
447
/* Parameters: As bbc_rectangle.                 */
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
/*************************************************/

_kernel_oserror * bbc_rectanglefill(int x, int y, int w, int h)
{
   _kernel_oserror * e = bbc_move(x,y);

   if (!e) e = bbc_plot(BBC_RectangleFill + BBC_DrawRelFore, w, h);

   return e;
}

/*************************************************/
/* bbc_circle()                                  */
/*                                               */
/* Plots a circle outline.                       */
/*                                               */
464 465 466 467 468 469
/* Parameters: X coordinate of midpoint, in OS   */
/*             units;                            */
/*                                               */
/*             Y coordinate for the same;        */
/*                                               */
/*             Radius, in OS units.              */
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
/*************************************************/

_kernel_oserror * bbc_circle(int x, int y, int r)
{
   _kernel_oserror * e = bbc_move(x,y);

   if (!e) e = bbc_plot(BBC_Circle + BBC_DrawAbsFore, x + r, y);

   return e;
}

/*************************************************/
/* bbc_circlefill()                              */
/*                                               */
/* Plots a filled circle.                        */
/*                                               */
486
/* Parameters: As bbc_circle.                    */
487 488 489 490 491 492 493 494 495 496 497
/*************************************************/

_kernel_oserror * bbc_circlefill(int x, int y, int r)
{
   _kernel_oserror * e = bbc_move(x,y);

   if (!e) e = bbc_plot(BBC_CircleFill + BBC_DrawAbsFore, x + r, y);

   return e;
}

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
/*************************************************/
/* bbc_trianglefill()                            */
/*                                               */
/* Plots a filled triangle.                      */
/*                                               */
/* Parameters: X coordinate of one corner, in    */
/*             OS units;                         */
/*                                               */
/*             Y coordinate of one corner, in    */
/*             OS units;                         */
/*                                               */
/*             X coordinate of another corner,   */
/*             in OS units;                      */
/*                                               */
/*             Y coordinate of another corner,   */
/*             in OS units;                      */
/*                                               */
/*             X coordinate of the last corner,  */
/*             in OS units;                      */
/*                                               */
/*             Y coordinate of the last corner,  */
/*             in OS units.                      */
/*************************************************/

_kernel_oserror * bbc_trianglefill(int x1, int y1, int x2, int y2, int x3, int y3)
{
   _kernel_oserror * e = bbc_move(x1, y1);

   if (!e) e = bbc_move(x2, y2);
   if (!e) e = bbc_plot(BBC_TriangleFill + BBC_DrawAbsFore, x3, y3);

   return e;
}

532 533 534 535 536
/*************************************************/
/* bbc_fill()                                    */
/*                                               */
/* Flood-fill an area from absolute              */
/*                                               */
537 538 539 540
/* Parameters: X coordinate to start fill at, in */
/*             OS units;                         */
/*                                               */
/*             Y coordinate for the same.        */
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
/*************************************************/

_kernel_oserror * bbc_fill(int x, int y)
{
   return bbc_plot(BBC_FloodToBack + BBC_DrawAbsFore, x, y);
}

/*************************************************/
/* wimpt_read()                                  */
/*                                               */
/* Finds out the current X and Y eigen values    */
/* (desktop scaling). Screen resolution in dots  */
/* per inch is thus 180 / eigen value.           */
/*                                               */
/* This function is typically called on receipt  */
/* of a ModeChange message.                      */
/*************************************************/

void wimpt_read(void)
{
  wimpt_xeig = 1 << bbc_vduvar(BBC_XEigFactor);
  wimpt_yeig = 1 << bbc_vduvar(BBC_YEigFactor);
}

/*************************************************/
/* wimpt_dx()                                    */
/*                                               */
/* Returns the current X eigen value (Desktop    */
/* scaling). Screen X resolution in dots per     */
/* inch is thus 180/XEig.                        */
/*************************************************/

int wimpt_dx(void)
{
  return wimpt_xeig;
}

/*************************************************/
/* wimpt_dy()                                    */
/*                                               */
/* Returns the current Y eigen value (Desktop    */
/* scaling). Screen Y resolution in dots per     */
/* inch is thus 180/YEig.                        */
/*************************************************/

int wimpt_dy(void)
{
  return wimpt_yeig;
}

/*************************************************/
/* coords_x_toscreen()                           */
/*                                               */
594 595 596 597 598 599
/* Converts a work area X coordinate (0,0 is at  */
/* the top left of the window) to a screen       */
/* coordinate (0,0 is at the bottom left of the  */
/* screen).                                      */
/*                                               */
/* Parameters: The work area X coordinate;       */
600 601 602
/*                                               */
/*             Pointer to WimpRedrawWindowBlock  */
/*             holding details about the window  */
603 604 605 606
/*             that the X coordinate lies in.    */
/*                                               */
/* Returns:    The given value converted to a    */
/*             screen coordinate.                */
607 608 609 610 611 612 613 614 615 616
/*************************************************/

int coords_x_toscreen(int x, WimpRedrawWindowBlock * r)
{
  return (x - r->xscroll + r->visible_area.xmin);
}

/*************************************************/
/* coords_y_toscreen()                           */
/*                                               */
617
/* Converts a work area Y coordinate to a screen */
618 619
/* coordinate.                                   */
/*                                               */
620 621
/* Parameters: The work area Y coordinate;       */
/*                                               */
622 623
/*             Pointer to WimpRedrawWindowBlock  */
/*             holding details about the window  */
624 625 626 627
/*             that the Y coordinate lies in.    */
/*                                               */
/* Returns:    The given value converted to a    */
/*             screen coordinate.                */
628 629 630 631 632 633 634 635 636 637 638 639 640 641
/*************************************************/

int coords_y_toscreen(int y, WimpRedrawWindowBlock * r)
{
  return (y - r->yscroll + r->visible_area.ymax);
}

/*************************************************/
/* coords_box_toscreen()                         */
/*                                               */
/* Converts the contents of a BBox representing  */
/* a rectangle in the work area of a window to   */
/* screen coordinates.                           */
/*                                               */
642 643
/* Parameters: Pointer to the BBox;              */
/*                                               */
644 645 646
/*             Pointer to WimpRedrawWindowBlock  */
/*             holding details about the window  */
/*             that the BBox retangle lies in.   */
647 648 649 650
/*                                               */
/* Returns:    The contents of the BBox are      */
/*             updated to hold screen            */
/*             coordinates.                      */
651 652 653 654 655 656 657 658 659 660 661 662 663
/*************************************************/

void coords_box_toscreen(BBox * b, WimpRedrawWindowBlock * r)
{
  b->xmax = coords_x_toscreen(b->xmax, r);
  b->xmin = coords_x_toscreen(b->xmin, r);
  b->ymin = coords_y_toscreen(b->ymin, r);
  b->ymax = coords_y_toscreen(b->ymax, r);
}

/*************************************************/
/* coords_x_toworkarea()                         */
/*                                               */
664 665 666 667 668 669
/* Converts a screen X coordinate (0,0 is at the */
/* bottom left of the screen) to a work area     */
/* coordinate (0,0 is at the top left of the     */
/* window).                                      */
/*                                               */
/* Parameters: The screen X coordiante;          */
670 671 672 673 674
/*                                               */
/*             Pointer to WimpRedrawWindowBlock  */
/*             holding details about the window  */
/*             that the coordinate is to be      */
/*             transformed to lie in.            */
675 676 677
/*                                               */
/* Returns:    The given value converted to      */
/*             a work area coordinate.           */
678 679 680 681 682 683 684 685 686 687
/*************************************************/

int coords_x_toworkarea(int x, WimpRedrawWindowBlock * r)
{
  return (x + r->xscroll - r->visible_area.xmin);
}

/*************************************************/
/* coords_y_toworkarea()                         */
/*                                               */
688
/* Converts a screen Y coordinate to a work area */
689 690
/* coordinate.                                   */
/*                                               */
691 692
/* Parameters: The screen Y coordiante;          */
/*                                               */
693 694 695 696
/*             Pointer to WimpRedrawWindowBlock  */
/*             holding details about the window  */
/*             that the coordinate is to be      */
/*             transformed to lie in.            */
697 698 699
/*                                               */
/* Returns:    The given value converted to      */
/*             a work area coordinate.           */
700 701 702 703 704 705 706 707 708 709 710 711 712 713
/*************************************************/

int coords_y_toworkarea(int y, WimpRedrawWindowBlock * r)
{
  return (y + r->yscroll - r->visible_area.ymax);
}

/*************************************************/
/* coords_box_toworkarea()                       */
/*                                               */
/* Converts the contents of a BBox representing  */
/* a rectangle in screen coords to hold work     */
/* area coordinates.                             */
/*                                               */
714 715
/* Parameters: Pointer to the BBox;              */
/*                                               */
716 717 718 719
/*             Pointer to WimpRedrawWindowBlock  */
/*             holding details about the window  */
/*             that the BBox coordinates are to  */
/*             be transformed to lie in.         */
720 721 722 723
/*                                               */
/* Returns:    The contents of the BBox are      */
/*             updated to hold work area         */
/*             coordinates.                      */
724 725 726 727 728 729 730 731 732
/*************************************************/

void coords_box_toworkarea(BBox * b, WimpRedrawWindowBlock * r)
{
  b->xmax = coords_x_toworkarea(b->xmax, r);
  b->xmin = coords_x_toworkarea(b->xmin, r);
  b->ymin = coords_y_toworkarea(b->ymin, r);
  b->ymax = coords_y_toworkarea(b->ymax, r);
}