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 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 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
|
#include "cdk.h"
/*
* $Author: glovem $
* $Date: 1997/04/25 12:50:55 $
* $Revision: 1.34 $
*/
/*
* This creates a marquee widget.
*/
CDKMARQUEE *newCDKMarquee (CDKSCREEN *cdkscreen, int xplace, int yplace, int width, boolean box, boolean shadow)
{
CDKMARQUEE *marquee = (CDKMARQUEE *)malloc (sizeof (CDKMARQUEE));
int parentWidth = WIN_WIDTH (cdkscreen->window);
int xpos = xplace;
int ypos = yplace;
int boxHeight = 3;
int boxWidth = width;
/*
* If the width is a negative value, the width will
* be COLS-width, otherwise, the width will be the
* given width.
*/
boxWidth = setWidgetDimension (parentWidth, width, 0);
/* Rejustify the x and y positions if we need to. */
alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);
/* Create the marquee pointer. */
marquee->parent = cdkscreen->window;
marquee->win = newwin (boxHeight, boxWidth, ypos, xpos);
marquee->boxHeight = boxHeight;
marquee->boxWidth = boxWidth;
marquee->shadowWin = (WINDOW *)NULL;
marquee->active = TRUE;
marquee->width = width;
marquee->box = box;
marquee->shadow = shadow;
marquee->ULChar = ACS_ULCORNER;
marquee->URChar = ACS_URCORNER;
marquee->LLChar = ACS_LLCORNER;
marquee->LRChar = ACS_LRCORNER;
marquee->HChar = ACS_HLINE;
marquee->VChar = ACS_VLINE;
marquee->BoxAttrib = A_NORMAL;
/* Is the window NULL??? */
if (marquee->win == (WINDOW *)NULL)
{
/* Clean up any memory. */
free (marquee);
/* Return a NULL pointer. */
return ( (CDKMARQUEE *)NULL );
}
keypad (marquee->win, TRUE);
/* Register this baby. */
registerCDKObject (cdkscreen, vMARQUEE, marquee);
/* Return the marquee pointer. */
return(marquee);
}
/*
* This activates the marquee.
*/
int activateCDKMarquee (CDKMARQUEE *marquee, char *mesg, int delay, int repeat, boolean box)
{
/* Declear local variables. */
chtype *message;
int mesgLength = 0;
int startPos = 0;
int firstChar = 0;
int lastChar = 1;
int repeatCount = 0;
int viewSize = 0;
int x, y, junk;
/* Keep the box info. */
marquee->box = box;
/* Make sure the message has some content. */
if (mesg == (char *)NULL)
{
return (-1);
}
/* Translate the char * to a chtype * */
message = char2Chtype (mesg, &mesgLength, &junk);
/* Draw in the marquee. */
drawCDKMarquee (marquee, marquee->box);
/* Set up the variables. */
viewSize = lastChar - firstChar;
startPos = marquee->width - viewSize;
if (marquee->box == TRUE)
{
startPos--;
}
/* Start doing the marquee thing... */
for (;;)
{
if (marquee->active)
{
/* Draw in the characters. */
y = firstChar;
for (x=startPos ; x < (startPos+viewSize) ; x++)
{
mvwaddch (marquee->win, 1, x, message[y]);
y++;
}
wrefresh (marquee->win);
/* Set my variables. */
if (mesgLength < (marquee->width-2))
{
if (lastChar < mesgLength)
{
lastChar ++;
viewSize ++;
startPos = marquee->width - viewSize + 1;
}
else if (lastChar == mesgLength)
{
if (startPos > 1)
{
/* This means the whole string is visible. */
startPos --;
viewSize = mesgLength - 1;
}
else
{
/* We have to start chopping the viewSize */
startPos = 1;
firstChar++;
viewSize--;
}
}
}
else
{
if (startPos > 1)
{
lastChar ++;
viewSize ++;
startPos --;
}
else
{
if (lastChar < mesgLength)
{
firstChar ++;
lastChar ++;
startPos = 1;
viewSize = marquee->width - 2;
}
else
{
firstChar ++;
viewSize --;
startPos = 1;
}
}
}
/* OK, lets check if we have to start over. */
if ( viewSize == 0 && firstChar == mesgLength)
{
/* Check if we need to repeat or not. */
repeatCount ++;
if (repeat > 0 && repeatCount == repeat)
{
freeChtype (message);
return (0);
}
/* Time to start over. */
mvwaddch (marquee->win, 1, 1, ' '|A_NORMAL);
wrefresh (marquee->win);
firstChar = 0;
lastChar = 1;
viewSize = lastChar - firstChar;
startPos = marquee->width - viewSize;
if (marquee->box)
{
startPos--;
}
}
/* Now sleep */
usleep ((delay * 10000));
}
}
}
/*
* This de-activates a marquee widget.
*/
void deactivateCDKMarquee (CDKMARQUEE *marquee)
{
marquee->active = FALSE;
}
/*
* This moves the marquee field to the given location.
*/
void moveCDKMarquee (CDKMARQUEE *marquee, int xplace, int yplace, boolean relative, boolean refresh)
{
/* Declare local variables. */
int currentX = marquee->win->_begx;
int currentY = marquee->win->_begy;
int xpos = xplace;
int ypos = yplace;
int xdiff = 0;
int ydiff = 0;
/*
* If this is a relative move, then we will adjust where we want
* to move to.
*/
if (relative)
{
xpos = marquee->win->_begx + xplace;
ypos = marquee->win->_begy + yplace;
}
/* Adjust the window if we need to. */
alignxy (marquee->screen->window, &xpos, &ypos, marquee->boxWidth, marquee->boxHeight);
/* Get the difference. */
xdiff = currentX - xpos;
ydiff = currentY - ypos;
/* Move the window to the new location. */
marquee->win->_begx = xpos;
marquee->win->_begy = ypos;
/* If there is a shadow box we have to move it too. */
if (marquee->shadowWin != (WINDOW *)NULL)
{
marquee->shadowWin->_begx -= xdiff;
marquee->shadowWin->_begy -= ydiff;
}
/* Touch the windows so they 'move'. */
touchwin (marquee->screen->window);
wrefresh (marquee->screen->window);
/* Redraw the window, if they asked for it. */
if (refresh)
{
drawCDKMarquee (marquee, marquee->box);
}
}
/*
* This allows the user to use the cursor keys to adjust the
* position of the widget.
*/
void positionCDKMarquee (CDKMARQUEE *marquee)
{
/* Declare some variables. */
int origX = marquee->win->_begx;
int origY = marquee->win->_begy;
chtype key = (chtype)NULL;
/* Let them move the widget around until they hit return. */
while ((key != KEY_RETURN) && (key != KEY_ENTER))
{
key = wgetch (marquee->win);
if (key == KEY_UP || key == '8')
{
if (marquee->win->_begy > 0)
{
moveCDKMarquee (marquee, 0, -1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == KEY_DOWN || key == '2')
{
if (marquee->win->_begy+marquee->win->_maxy < marquee->screen->window->_maxy-1)
{
moveCDKMarquee (marquee, 0, 1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == KEY_LEFT || key == '4')
{
if (marquee->win->_begx > 0)
{
moveCDKMarquee (marquee, -1, 0, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == KEY_RIGHT || key == '6')
{
if (marquee->win->_begx+marquee->win->_maxx < marquee->screen->window->_maxx-1)
{
moveCDKMarquee (marquee, 1, 0, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '7')
{
if (marquee->win->_begy > 0 && marquee->win->_begx > 0)
{
moveCDKMarquee (marquee, -1, -1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '9')
{
if (marquee->win->_begx+marquee->win->_maxx < marquee->screen->window->_maxx-1 &&
marquee->win->_begy > 0)
{
moveCDKMarquee (marquee, 1, -1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '1')
{
if (marquee->win->_begx > 0 && marquee->win->_begx+marquee->win->_maxx < marquee->screen->window->_maxx-1)
{
moveCDKMarquee (marquee, -1, 1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '3')
{
if (marquee->win->_begx+marquee->win->_maxx < marquee->screen->window->_maxx-1 &&
marquee->win->_begy+marquee->win->_maxy < marquee->screen->window->_maxy-1)
{
moveCDKMarquee (marquee, 1, 1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '5')
{
moveCDKMarquee (marquee, CENTER, CENTER, FALSE, TRUE);
}
else if (key == 't')
{
moveCDKMarquee (marquee, marquee->win->_begx, TOP, FALSE, TRUE);
}
else if (key == 'b')
{
moveCDKMarquee (marquee, marquee->win->_begx, BOTTOM, FALSE, TRUE);
}
else if (key == 'l')
{
moveCDKMarquee (marquee, LEFT, marquee->win->_begy, FALSE, TRUE);
}
else if (key == 'r')
{
moveCDKMarquee (marquee, RIGHT, marquee->win->_begy, FALSE, TRUE);
}
else if (key == 'c')
{
moveCDKMarquee (marquee, CENTER, marquee->win->_begy, FALSE, TRUE);
}
else if (key == 'C')
{
moveCDKMarquee (marquee, marquee->win->_begx, CENTER, FALSE, TRUE);
}
else if (key == CDK_REFRESH)
{
eraseCDKScreen (marquee->screen);
refreshCDKScreen (marquee->screen);
}
else if (key == KEY_ESC)
{
moveCDKMarquee (marquee, origX, origY, FALSE, TRUE);
}
else if ((key != KEY_RETURN) && (key != KEY_ENTER))
{
Beep();
}
}
}
/*
* This draws the marquee widget on the screen.
*/
void drawCDKMarquee (CDKMARQUEE *marquee, boolean Box)
{
/* Keep the box information. */
marquee->box = Box;
/* Do we need to draw a shadow??? */
if (marquee->shadowWin != (WINDOW *)NULL)
{
drawShadow (marquee->shadowWin);
}
/* Box it if needed. */
if (Box)
{
attrbox (marquee->win,
marquee->ULChar, marquee->URChar,
marquee->LLChar, marquee->LRChar,
marquee->HChar, marquee->VChar,
marquee->BoxAttrib);
}
/* Refresh the window. */
touchwin (marquee->win);
wrefresh (marquee->win);
}
/*
* This destroys the marquee.
*/
void destroyCDKMarquee (CDKMARQUEE *marquee)
{
/* Erase the object. */
eraseCDKMarquee (marquee);
/* Clean up the windows. */
deleteCursesWindow (marquee->shadowWin);
deleteCursesWindow (marquee->win);
/* Unregister this object. */
unregisterCDKObject (vMARQUEE, marquee);
/* Finish cleaning up. */
free (marquee);
}
/*
* This erases the marquee.
*/
void eraseCDKMarquee (CDKMARQUEE *marquee)
{
eraseCursesWindow (marquee->win);
eraseCursesWindow (marquee->shadowWin);
}
/*
* These functions set the drawing characters of the widget.
*/
void setCDKMarqueeULChar (CDKMARQUEE *marquee, chtype character)
{
marquee->ULChar = character;
}
void setCDKMarqueeURChar (CDKMARQUEE *marquee, chtype character)
{
marquee->URChar = character;
}
void setCDKMarqueeLLChar (CDKMARQUEE *marquee, chtype character)
{
marquee->LLChar = character;
}
void setCDKMarqueeLRChar (CDKMARQUEE *marquee, chtype character)
{
marquee->LRChar = character;
}
void setCDKMarqueeVerticalChar (CDKMARQUEE *marquee, chtype character)
{
marquee->VChar = character;
}
void setCDKMarqueeHorizontalChar (CDKMARQUEE *marquee, chtype character)
{
marquee->HChar = character;
}
void setCDKMarqueeBoxAttribute (CDKMARQUEE *marquee, chtype character)
{
marquee->BoxAttrib = character;
}
/*
* This sets the background color of the widget.
*/
void setCDKMarqueeBackgroundColor (CDKMARQUEE *marquee, char *color)
{
chtype *holder = (chtype *)NULL;
int junk1, junk2;
/* Make sure the color isn't NULL. */
if (color == (char *)NULL)
{
return;
}
/* Convert the value of the environment variable to a chtype. */
holder = char2Chtype (color, &junk1, &junk2);
/* Set the widgets background color. */
wbkgd (marquee->win, holder[0]);
/* Clean up. */
freeChtype (holder);
}
|