DragBox 8.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
/* 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   : DragBox.c                              */
/*                                                 */
/* Purpose: Plot user drag boxes for such things   */
/*          as non-solid frame resizes (where the  */
/*          'box' shape could be very irregular).  */
/*                                                 */
/* Author : A.D.Hodgkinson                         */
/*                                                 */
/* History: 26-Aug-97: Created, based on the ResEd */
/*                     'Common.c.wimp' code.       */
/***************************************************/

#include <stdlib.h>
#include <stdio.h>

#include "swis.h"

#include "wimp.h"
#include "wimplib.h"
#include "event.h"

#include "svcprint.h"
#include "Global.h"
#include "FromROSLib.h"
#include "Utils.h"

#include "DragBox.h"

/* Local statics */

/* These are the possible patterns used to plot the drag boxes.      */
/* The first patterns are used when plotting and erasing a drag box. */
/* The second patterns are used when rotating a stationary drag box. */

static char patterns1[] = { 0xfc, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3f, 0x7e };
static char patterns2[] = { 0x82, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x41 };

/* Contain the current patterns */

static int  patternid   = 7; /* Chooses the pattern */
static char pattern1[]  = { 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e };
static char pattern2[]  = { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 };

/* This points to the pattern used by dragbox_plot_eor_box; it addresses */
/* pattern1 whilst removing an existing drag box, or plotting a new one, */
/* and addresses pattern2 when rotating a stationary drag box.           */

static char * pattern = pattern1;

/*************************************************/
/* dragbox_set_dotdash()                         */
/*                                               */
/* Sets the dot-dash pattern according to the    */
/* given eight bytes, or a default one.          */
/*                                               */
/* Parameters: Pointer to an 8 char long array   */
/*             chars, or NULL for a default      */
/*             pattern.                          */
/*************************************************/

_kernel_oserror * dragbox_set_dotdash(char * eight)
{
  if (!eight) eight = "\360\360\360\360\360\360\360\360";

  /* Output char 23, then 6 (misc VDU; set dot-dash) */

  RetError(_swix(OS_WriteI + 23, 0));
  RetError(_swix(OS_WriteI + 6,  0));

  /* Now output the 8 bytes describing the pattern */

  return _swix(OS_WriteN,
               _INR(0,1),

               eight,
               8);
}

/*************************************************/
/* dragbox_cycle_pattern()                       */
/*                                               */
/* Cycle the dot-dash pattern for a 'rotating'   */
/* drag box.                                     */
/*************************************************/

void dragbox_cycle_pattern(void)
{
  int i;

  patternid --;

  if (patternid < 0) patternid = 7;

  /* Cycle the pattern */

  for (i = 0; i < 8; i++)
  {
    pattern1[i] = patterns1[patternid];
    pattern2[i] = patterns2[patternid];
  }

  return;
}

/*************************************************/
/* dragbox_plot_eor_box()                        */
/*                                               */
/* Plot a dotted rubber box using EOR. Should    */
/* only be used during a redraw loop.            */
/*                                               */
/* Parameters: A WimpRedrawWindowBlock pointer   */
/*             relevant to the redraw session;   */
/*                                               */
/*             Pointer to a BBox holding the     */
/*             min and max coords of the BBox    */
/*             (window work area coords, min     */
/*             values inclusive, max values      */
/*             exclusive).                       */
/*************************************************/

void dragbox_plot_eor_box(WimpRedrawWindowBlock * r, BBox * rect)
{
  BBox box = *rect;

  /* Convert the given rectangle work-area coords to screen coords */

  coords_box_toscreen(&box, r);

  /* Make xmax and ymax inclusive coords */

  box.xmax -= wimpt_dx();
  box.ymax -= wimpt_dy();

  /* Set the dash pattern */

  #ifdef TRACE
    if (tl & (1u<<27)) Printf("Set dotdash\n");
  #endif

  dragbox_set_dotdash(pattern);

  /* Set the colour and plot the box */

  #ifdef TRACE
    if (tl & (1u<<27)) Printf("Set colour\n");
  #endif

  _swix(Wimp_SetColour, _IN(0), 0x3f);

  #ifdef TRACE
    if (tl & (1u<<27)) Printf("Draw over %d, %d, %d, %d\n",box.xmin,box.ymin,box.xmax,box.ymax);
  #endif

  _swix(OS_Plot, _INR(0,2), 4,      box.xmin, box.ymin);
  _swix(OS_Plot, _INR(0,2), 5 | 24, box.xmax, box.ymin);
  _swix(OS_Plot, _INR(0,2), 5 | 48, box.xmax, box.ymax);
  _swix(OS_Plot, _INR(0,2), 5 | 48, box.xmin, box.ymax);
  _swix(OS_Plot, _INR(0,2), 5 | 48, box.xmin, box.ymin);

  return;
}

/*************************************************/
/* dragbox_update_eor_box()                      */
/*                                               */
/* Plot a dotted rubber box using EOR. Does its  */
/* own update redraw loop for the plot.          */
/*                                               */
/* Parameters: Window handle that the box is to  */
/*             lie within;                       */
/*                                               */
/*             Pointer to a BBox holding the     */
/*             min and max coords of the BBox    */
/*             (window work area coords, min     */
/*             values inclusive, max values      */
/*             exclusive).                       */
/*************************************************/

void dragbox_update_eor_box(int handle, BBox * rect)
{
  WimpGetWindowStateBlock s;
  WimpRedrawWindowBlock   r;
  int                     more = 0;

  s.window_handle = handle;
  if (wimp_get_window_state(&s)) return;

  /* Convert the given work area rectangle to screen coords */
  /* for redrawing                                          */

  r.window_handle = s.window_handle;
  r.visible_area  = *rect;
  r.xscroll       = s.xscroll;
  r.yscroll       = s.yscroll;

//  coords_box_toworkarea(&r.visible_area, (WimpRedrawWindowBlock *) &s);

  /* Start the update */

  wimp_update_window(&r, &more);

  /* Do the redraw */

  while (more)
  {
    #ifdef TRACE
      if (tl & (1u<<27)) Printf("Plot EOR\n");
    #endif

    dragbox_plot_eor_box(&r, rect);

    wimp_get_rectangle(&r, &more);
  }

  return;
}

/*************************************************/
/* dragbox_start_rotate_box()                    */
/*                                               */
/* Call before starting a 'rotate' drag box      */
/* plot.                                         */
/*************************************************/

void dragbox_start_rotate_box(void)
{
  pattern = pattern2;

  return;
}

/*************************************************/
/* dragbox_end_rotate_box()                      */
/*                                               */
/* Call after completing a 'rotate' drag box     */
/* plot.                                         */
/*************************************************/

void dragbox_end_rotate_box(void)
{
  pattern = pattern1;

  dragbox_cycle_pattern();

  return;
}



void dragbox_draw_box(void)
{
  #ifdef TRACE
    if (tl & (1u<<27)) Printf("Draw\n");
  #endif
}

void dragbox_remove_box(void)
{
  #ifdef TRACE
    if (tl & (1u<<27)) Printf("Remove\n");
  #endif
}

void dragbox_move_box(void)
{
  #ifdef TRACE
    if (tl & (1u<<27)) Printf("Move\n");
  #endif
}