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 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 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 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
|
/*
* This file is part of the XForms library package.
*
* XForms is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1, or
* (at your option) any later version.
*
* XForms is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with XForms. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file xdraw.c
*
* This file is part of the XForms library package.
* Copyright (c) 1996-2002 T.C. Zhao and Mark Overmars
* All rights reserved.
*
* Basic low level drawing routines in Xlib.
*
* BUGS: All form window share a common GC and color map.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "include/forms.h"
#include "flinternal.h"
static int fli_mono_dither( unsigned long );
static void fli_set_current_gc( GC );
static GC dithered_gc;
/*******************************************************************
* Rectangle routines
****************************************************************{**/
/***************************************
* Function for drawing a (possibly filled) rectangle
***************************************/
void
fl_rectangle( int fill,
FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h,
FL_COLOR col )
{
int bw = fli_dithered( fl_vmode ) && fli_mono_dither( col );
GC gc = flx->gc;
int ( * draw_as )( Display *,
Drawable,
GC,
int,
int,
unsigned int,
unsigned int );
if ( flx->win == None || w <= 0 || h <= 0 )
return;
fli_canonicalize_rect( &x, &y, &w, &h );
draw_as = fill ? XFillRectangle : XDrawRectangle;
if ( bw && fill )
{
fli_set_current_gc( fli_whitegc );
draw_as( flx->display, flx->win, flx->gc, x, y, w, h );
fli_set_current_gc( dithered_gc );
}
fl_color( bw ? FL_BLACK : col );
draw_as( flx->display, flx->win, flx->gc, x, y, w, h );
if ( bw )
fli_set_current_gc( gc );
}
/****** End of rectangle routines ***********************}***/
/****************************************************************
* Polygon and polylines
***********************************************************{****/
/***************************************
* Function for drawing a closed (possibly filled) polygon.
* The 'xp' argument must point to an array with n + 1 elements!
***************************************/
void
fl_polygon( int fill,
FL_POINT * xp,
int n,
FL_COLOR col )
{
int bw = fli_dithered( fl_vmode ) && fli_mono_dither( col );
GC gc = flx->gc;
if ( flx->win == None || n <= 0 )
return;
if ( bw )
{
flx->gc = dithered_gc;
fl_color( FL_WHITE );
if ( fill )
XFillPolygon( flx->display, flx->win, flx->gc, xp, n,
Nonconvex, CoordModeOrigin );
else
{
xp[ n ].x = xp[ 0 ].x;
xp[ n ].y = xp[ 0 ].y;
XDrawLines( flx->display, flx->win, flx->gc, xp, n + 1,
CoordModeOrigin );
}
}
fl_color( bw ? FL_BLACK : col );
if ( fill )
XFillPolygon( flx->display, flx->win, flx->gc, xp, n,
Nonconvex, CoordModeOrigin );
else
{
xp[ n ].x = xp[ 0 ].x;
xp[ n ].y = xp[ 0 ].y;
XDrawLines( flx->display, flx->win, flx->gc, xp, n + 1,
CoordModeOrigin );
}
if ( bw )
flx->gc = gc;
}
/****************************************************************
* Draws a circle at (x, y) woth radius r and col as to color
* of the outline
**********************************************************{******/
void
fl_circ( FL_COORD x,
FL_COORD y,
FL_COORD r,
FL_COLOR col )
{
fl_oval( 0, x - r, y - r, 2 * r, 2 * r, col );
}
/****************************************************************
* Draws a filled circle at (x, y) woth radius r in color col
**********************************************************{******/
void
fl_circf( FL_COORD x,
FL_COORD y,
FL_COORD r,
FL_COLOR col )
{
fl_oval( 1, x - r, y - r, 2 * r, 2 * r, col );
}
/****************************************************************
* Draws a filled circle at (x, y) woth radius r in color col and
* the circumfence in black.
**********************************************************{******/
void
fl_circbound( FL_COORD x,
FL_COORD y,
FL_COORD r,
FL_COLOR col )
{
fl_ovalbound( x - r, y - r, 2 * r, 2 * r, col );
}
/****************************************************************
* Function for drawing a (possibly filled) ellipse.
**********************************************************{******/
void
fl_oval( int fill,
FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h,
FL_COLOR col )
{
int bw = fli_dithered( fl_vmode ) && fli_mono_dither( col );
GC gc = flx->gc;
int ( * draw_as )( Display *,
Drawable,
GC,
int,
int,
unsigned int,
unsigned int,
int,
int );
if ( flx->win == None || w <= 0 || h <= 0 )
return;
draw_as = fill ? XFillArc : XDrawArc;
if ( bw )
{
fli_set_current_gc( fli_whitegc );
draw_as( flx->display, flx->win, flx->gc, x, y, w, h, 0, 360 * 64 );
fli_set_current_gc( dithered_gc );
}
fl_color( bw ? FL_BLACK : col );
if ( w >= 0 && h >= 0 )
draw_as( flx->display, flx->win, flx->gc, x, y, w, h, 0, 360 * 64 );
if ( bw )
fli_set_current_gc( gc );
}
/***************************************
* Draws a filled ellipse with a black border
***************************************/
void
fl_ovalbound( FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h,
FL_COLOR col )
{
if ( flx->win == None || w <= 0 || h <= 0 )
return;
fl_color( col );
XFillArc( flx->display, flx->win, flx->gc, x, y, w, h, 0, 360 * 64 );
fl_color( FL_BLACK );
XDrawArc( flx->display, flx->win, flx->gc, x, y, w - 1, h - 1, 0,
360 * 64 );
}
/******* End of ellipse routines ****************}***********/
/****************************************************************
*
* Arcs
****************************************************************/
/***************************************
***************************************/
void
fl_ovalarc( int fill,
FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h,
int t0,
int dt,
FL_COLOR col )
{
int mono = fli_dithered( fl_vmode ) && fli_mono_dither( col );
int ( * draw_as )( Display *,
Drawable,
GC,
int,
int,
unsigned int,
unsigned int,
int,
int );
if ( flx->win == None || w <= 0 || h <= 0 )
return;
draw_as = fill ? XFillArc : XDrawArc;
if ( mono )
{
fli_set_current_gc( fli_whitegc );
draw_as( flx->display, flx->win, flx->gc, x, y, w, h,
t0 * 6.4, dt * 6.4 );
fli_set_current_gc( dithered_gc );
}
fl_color( mono ? FL_BLACK : col );
if ( w >= 0 && h >= 0 )
draw_as( flx->display, flx->win, flx->gc, x, y, w, h,
t0 * 6.4, dt * 6.4 );
if ( mono )
fli_set_current_gc( fl_state[ fl_vmode ].gc[ 0 ] );
}
/***************************************
***************************************/
void
fl_arcf( FL_COORD x,
FL_Coord y,
FL_COORD r,
int a1,
int a2,
FL_COLOR col )
{
fl_pieslice( 1, x - r, y - r, 2 * r, 2 * r, a1, a2, col );
}
/***************************************
***************************************/
void
fl_arc( FL_COORD x,
FL_Coord y,
FL_COORD r,
int a1,
int a2,
FL_COLOR col )
{
fl_pieslice( 0, x - r, y - r, 2 * r, 2 * r, a1, a2, col );
}
/***************************************
***************************************/
void
fl_pieslice( int fill,
FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h,
int a1,
int a2,
FL_COLOR col )
{
int delta = a2 - a1,
bw = fli_dithered( fl_vmode ) && fli_mono_dither( col );
GC gc = flx->gc;
int ( * draw_as )( Display *,
Drawable,
GC,
int,
int,
unsigned int,
unsigned int,
int,
int );
if ( flx->win == None || w <= 0 || h <= 0)
return;
draw_as = fill ? XFillArc : XDrawArc;
if ( bw )
{
fli_set_current_gc( fli_whitegc );
draw_as( flx->display, flx->win, flx->gc, x, y, w, h,
a1 * 6.4, delta * 6.4 );
fli_set_current_gc( dithered_gc );
}
fl_color( bw ? FL_BLACK : col );
if ( w >= 0 && h >= 0 )
draw_as( flx->display, flx->win, flx->gc, x, y, w, h,
a1 * 6.4, delta * 6.4 );
if ( bw )
fli_set_current_gc( gc );
}
/*********************************************************************
* Line segments
*****************************************************************{***/
/***************************************
***************************************/
void
fl_lines( FL_POINT * xp,
int n,
FL_COLOR col )
{
if ( flx->win == None || n <= 0 )
return;
fl_color( col );
/* We may need to break up the request into smaller pieces */
if ( fli_context->ext_request_size >= n )
XDrawLines( flx->display, flx->win, flx->gc, xp, n, CoordModeOrigin );
else
{
int req = fli_context->ext_request_size;
int i,
nchunks = ( n + ( n / req ) ) / req,
left;
FL_POINT *p = xp;
for ( i = 0; i < nchunks; i++, p += req - 1 )
XDrawLines( flx->display, flx->win, flx->gc, p, req,
CoordModeOrigin );
left = xp + n - p;
if ( left )
{
if ( left == 1 )
{
p--;
left++;
}
XDrawLines( flx->display, flx->win, flx->gc, p, left,
CoordModeOrigin );
}
}
}
/***************************************
* Drwas a simple line from (x1,y1) to (x2,y2)
***************************************/
void
fl_line( FL_Coord xi,
FL_Coord yi,
FL_Coord xf,
FL_Coord yf,
FL_COLOR c )
{
if ( flx->win == None )
return;
fl_color( c );
XDrawLine( flx->display, flx->win, flx->gc, xi, yi, xf, yf );
}
/**************** End of line segments *******************}*********/
/* points */
/***************************************
* Draws a simple point at the given position
***************************************/
void
fl_point( FL_Coord x,
FL_Coord y,
FL_COLOR c )
{
if ( flx->win == None )
return;
fl_color( c );
XDrawPoint( flx->display, flx->win, flx->gc, x, y );
}
/***************************************
* Draws a set of simple point at the given positions
***************************************/
void
fl_points( FL_POINT * p,
int np,
FL_COLOR c )
{
if ( flx->win == None || np <= 0 )
return;
fl_color( c );
XDrawPoints( flx->display, flx->win, flx->gc, p, np, CoordModeOrigin );
}
/********************************************************************
* Basic drawing attributes
****************************************************************{*/
static int lw = 0,
ls = LineSolid,
drmode = GXcopy;
/***************************************
***************************************/
void
fl_linewidth( int n )
{
XGCValues gcvalue;
unsigned long gcmask;
if ( lw == n )
return;
gcmask = GCLineWidth;
gcvalue.line_width = lw = n;
XChangeGC( flx->display, flx->gc, gcmask, &gcvalue );
}
/***************************************
***************************************/
int
fl_get_linewidth( void )
{
return lw;
}
static void fli_xdashedlinestyle( Display *,
GC,
const char *,
int );
/***************************************
***************************************/
void
fli_xlinestyle( Display * d,
GC gc,
int n )
{
static char dots[ ] = { 2, 4 };
static char dotdash[ ] = { 7, 3, 2, 3 };
static char ldash[ ] = { 10, 4 };
XGCValues gcvalue;
unsigned long gcmask;
if ( ls == n )
return;
ls = n;
gcmask = GCLineStyle;
if ( n == FL_DOT )
fli_xdashedlinestyle( d, gc, dots, 2 );
else if ( n == FL_DOTDASH )
fli_xdashedlinestyle( d, gc, dotdash, 4 );
else if ( n == FL_LONGDASH )
fli_xdashedlinestyle( d, gc, ldash, 2 );
if ( n > LineDoubleDash )
n = LineOnOffDash;
gcvalue.line_style = n;
XChangeGC( d, gc, gcmask, &gcvalue );
}
/***************************************
***************************************/
void
fl_linestyle( int n )
{
fli_xlinestyle( flx->display, flx->gc, n );
}
/***************************************
***************************************/
int
fl_get_linestyle( void )
{
return ls;
}
/***************************************
***************************************/
int
fl_get_drawmode( void )
{
return drmode;
}
/***************************************
***************************************/
void
fl_drawmode( int request )
{
if ( drmode != request )
XSetFunction( flx->display, flx->gc, drmode = request );
}
/***************************************
***************************************/
static void
fli_xdashedlinestyle( Display * d,
GC gc,
const char * dash,
int ndash )
{
static char default_dash[ ] = { 4, 4 };
if ( dash == NULL )
{
dash = default_dash;
ndash = 2;
}
XSetDashes( d, gc, 0, ( char * ) dash, ndash );
}
/***************************************
***************************************/
void
fl_dashedlinestyle( const char * dash,
int ndash )
{
static char default_dash[ ] = { 4, 4 };
/* Check that the input is reasonable - XSetDashes() requires that
there's at least one element in the 'dash' array and that none
of its elements are 0. If one of these conditions isn't satis-
fied (or 'dash' itself is NULL) set the defaut dash pattern. */
if ( dash )
{
int i;
for ( i = 0; i < ndash; i++ )
if ( dash[ i ] == '\0' )
{
M_warn( "fl_dashedlinestyle", "Invalid '\0' in dash pattern "
"array, using default pattern" );
ndash = 0;
break;
}
}
if ( ! dash || ! ndash )
{
dash = default_dash;
ndash = 2;
}
XSetDashes( flx->display, flx->gc, 0, ( char * ) dash, ndash );
}
/************************************************************************
* Clipping stuff
***********************************************************************/
/*
* Remember global clipping so unset_clipping will restore it. Most
* useful as part of event dispatching
*/
enum {
FLI_GLOBAL_CLIP = 0,
FLI_NORMAL_CLIP = 1,
FLI_TEXT_CLIP = 2,
FLI_GC_CLIP = 3
};
static int fli_is_clipped[ ] = { 0, 0, 0, 0 };
static FL_RECT fli_clip_rect[ ] = { { 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 } };
#define SET_RECT( t, a, b, c, d ) \
do { \
( t ).x = a; \
( t ).y = b; \
( t ).width = c; \
( t ).height = d; \
} while ( 0 )
#define GET_RECT( t, a, b, c, d ) \
do { \
*a = ( t ).x; \
*b = ( t ).y; \
*c = ( t ).width; \
*d = ( t ).height; \
} while ( 0 )
/***************************************
* Returns if global clipping is switched on - in which case
* the region for global clipping can be obtained via a call
* of fli_get_global_clipping( ).
***************************************/
int
fl_is_global_clipped( void )
{
return fli_is_clipped[ FLI_GLOBAL_CLIP ];
}
/***************************************
* Helper function for determining if normal or text clipping is set
* (also reports if global clipping is set when 'include_global' is
* set).
***************************************/
static int
is_clipped( int type,
int include_global )
{
return fli_is_clipped[ type ]
|| ( include_global && fli_is_clipped[ FLI_GLOBAL_CLIP ] );
}
/***************************************
* Sets global clipping to the specified rectangle. If normal clipping
* is already on the rectange use is the one resulting from intersecting
* the requested rectangle with the one for normal clipping. Text is
* clipped in the same way. If called with a negative width or height
* global clipping is switched off.
***************************************/
void
fli_set_global_clipping( FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h )
{
/* Calling the function with a rectangle with a negative width or height
results in switching off of global clipping */
if ( w < 0 || h < 0 )
{
fli_unset_global_clipping( );
return;
}
SET_RECT( fli_clip_rect[ FLI_GLOBAL_CLIP ], x, y, w, h );
/* If normal clipping is already on intersect the new global and the
normal clip area and set clipping to the result. If normal clipping
is off just use the rectangle specified by the arguments. */
if ( fli_is_clipped[ FLI_NORMAL_CLIP ] )
{
FL_RECT * r = fli_intersect_rects( fli_clip_rect + FLI_GLOBAL_CLIP,
fli_clip_rect + FLI_NORMAL_CLIP );
if ( r )
{
XSetClipRectangles( flx->display, flx->gc, 0, 0, r, 1, Unsorted );
fli_safe_free( r );
}
else
{
FL_RECT n = { 0, 0, 0, 0 };
XSetClipRectangles( flx->display, flx->gc, 0, 0, &n, 1, Unsorted );
}
}
else
XSetClipRectangles( flx->display, flx->gc, 0, 0,
&fli_clip_rect[ FLI_GLOBAL_CLIP ], 1, Unsorted );
/* The same again for text clipping */
if ( fli_is_clipped[ FLI_TEXT_CLIP ] )
{
FL_RECT * r = fli_intersect_rects( fli_clip_rect + FLI_GLOBAL_CLIP,
fli_clip_rect + FLI_TEXT_CLIP );
if ( r )
{
XSetClipRectangles( flx->display, flx->textgc, 0, 0, r, 1,
Unsorted );
fli_safe_free( r );
}
else
{
FL_RECT n = { 0, 0, 0, 0 };
XSetClipRectangles( flx->display, flx->textgc, 0, 0, &n, 1,
Unsorted );
}
}
else
XSetClipRectangles( flx->display, flx->textgc, 0, 0,
fli_clip_rect + FLI_GLOBAL_CLIP, 1, Unsorted );
fli_is_clipped[ FLI_GLOBAL_CLIP ] = 1;
}
/***************************************
* Unsets global clipping - "normal" and text clipping, if set, are retained
***************************************/
void
fli_unset_global_clipping( void )
{
if ( ! fli_is_clipped[ FLI_GLOBAL_CLIP ] )
return;
SET_RECT( fli_clip_rect[ FLI_GLOBAL_CLIP ], 0, 0, 0, 0 );
/* If normal clipping is also on set the clipping rectangle to that set
for normal clipping, otherwise switch clipping off completely. */
if ( fli_is_clipped[ FLI_NORMAL_CLIP ] )
XSetClipRectangles( flx->display, flx->gc, 0, 0,
fli_clip_rect + FLI_NORMAL_CLIP, 1, Unsorted );
else
XSetClipMask( flx->display, flx->gc, None );
/* Same for text clipping */
if ( fli_is_clipped[ FLI_TEXT_CLIP ] )
XSetClipRectangles( flx->display, flx->textgc, 0, 0,
fli_clip_rect + FLI_TEXT_CLIP, 1, Unsorted );
else
XSetClipMask( flx->display, flx->textgc, None );
fli_is_clipped[ FLI_GLOBAL_CLIP ] = 0;
}
/***************************************
* Returns a pointer to the rectangle used for global clipping (only
* to be used when global clipping is on!)
***************************************/
FL_RECT *
fli_get_global_clip_rect( void )
{
return fli_clip_rect + FLI_GLOBAL_CLIP;
}
/***************************************
* Function returns as its return value if global clipping is on or off
* and, via the pointer arguments, the clipping rectangle.
***************************************/
int
fl_get_global_clipping( FL_Coord * x,
FL_Coord * y,
FL_Coord * w,
FL_Coord * h )
{
GET_RECT( fli_clip_rect[ FLI_GLOBAL_CLIP ], x, y, w, h );
return fli_is_clipped[ FLI_GLOBAL_CLIP ];
}
/***************************************
* Helper function to switch off normal, text or GC clipping - if global
* clipping is on it will be retained.
***************************************/
static void
unset_clipping( int type,
GC gc )
{
if ( ! fli_is_clipped[ type ] )
return;
SET_RECT( fli_clip_rect[ type ], 0, 0, 0, 0 );
if ( fli_is_clipped[ FLI_GLOBAL_CLIP ] )
XSetClipRectangles( flx->display, gc, 0, 0,
fli_clip_rect + FLI_GLOBAL_CLIP, 1, Unsorted );
else
XSetClipMask( flx->display, gc, None );
fli_is_clipped[ type ] = 0;
}
/***************************************
* Helper function to switch normal, text or GC clipping on for a certain
* a certain region. 'type' is the type of clipping and 'gc' the GC for
* which the clipping is to be set. If global clipping is already on the
* clipping region is the intersection of the requested clipping region
* with the clipping region for global clipping.
***************************************/
static void
set_clipping( int type,
GC gc,
FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h )
{
if ( w < 0 || h < 0 )
{
unset_clipping( type, gc );
return;
}
SET_RECT( fli_clip_rect[ type ], x, y, w, h );
if ( fli_is_clipped[ FLI_GLOBAL_CLIP ] )
{
FL_RECT * r = fli_intersect_rects( fli_clip_rect + FLI_GLOBAL_CLIP,
fli_clip_rect + type );
if ( r )
{
XSetClipRectangles( flx->display, gc, 0, 0, r, 1, Unsorted );
fli_safe_free( r );
}
else
{
FL_RECT n = { 0, 0, 0, 0 };
XSetClipRectangles( flx->display, gc, 0, 0, &n, 1, Unsorted );
}
}
else
XSetClipRectangles( flx->display, gc, 0, 0, &fli_clip_rect[ type ],
1, Unsorted );
fli_is_clipped[ type ] = 1;
}
/***************************************
* Helper function for determining if normal or text clipping is on and the
* region clipped to. 'type' is the type of clipping. If 'include_global' is
* set also clipping due to global clipping is taken into account (and the
* reported clipping region is the one resulting from intersection of the
* clipping region for the requested type of clipping and the one for global
* clipping). The function returns as its return value if there's clipping
* going on (which may, when 'include_global', also be due to global clipping).
***************************************/
static int
get_clipping( int type,
int include_global,
FL_Coord * x,
FL_Coord * y,
FL_Coord * w,
FL_Coord * h )
{
if ( ! ( include_global && fli_is_clipped[ FLI_GLOBAL_CLIP ] )
&& fli_is_clipped[ type ] )
GET_RECT( fli_clip_rect[ type ], x, y, w, h );
else if ( include_global && fli_is_clipped[ FLI_GLOBAL_CLIP ] )
{
if ( fli_is_clipped[ type ] )
{
FL_RECT * r =
fli_intersect_rects( fli_clip_rect + FLI_GLOBAL_CLIP,
fli_clip_rect + type );
if ( r )
{
GET_RECT( *r, x, y, w, h );
fl_free( r );
}
}
else
GET_RECT( fli_clip_rect[ FLI_GLOBAL_CLIP ], x, y, w, h );
}
return is_clipped( type, include_global );
}
/***************************************
* Returns if "normal" (i.e. non-text) clipping is switched on.
* If 'include_global' is set also also global clipping (used
* e.g. when redrawing on an expose event) is on, otherwise only
* clipping set via a call of fl_set_clipping() is reported.
***************************************/
int
fl_is_clipped( int include_global )
{
return is_clipped( FLI_NORMAL_CLIP, include_global );
}
/***************************************
* Function for setting normal clipping. If global clipping is on the
* rectangle set for clipping is the intersection of the rectangle specified
* by the arguments and the one for global clipping. Specifying a negative
* clipping width or height results in clipping becoming switched off.
***************************************/
void
fl_set_clipping( FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h )
{
set_clipping( FLI_NORMAL_CLIP, flx->gc, x, y, w, h );
}
/****************************************
* Function for switching of normal clipping. Note that global clipping
* will be retained.
***************************************/
void
fl_unset_clipping( )
{
unset_clipping( FLI_NORMAL_CLIP, flx->gc );
}
/***************************************
* Function for determining if normal clipping is on and the region clipped
* to. If 'include_global' is set also clipping due to global clipping is
* taken into account (and the reported clipping region is the one resulting
* from intersection of the normal clipping region and the one for global
* clipping). The function returns as its return value if there's clipping
* going on (which may, when 'include_global', also be due to global clipping).
***************************************/
int
fl_get_clipping( int include_global,
FL_Coord * x,
FL_Coord * y,
FL_Coord * w,
FL_Coord * h )
{
return get_clipping( FLI_NORMAL_CLIP, include_global, x, y, w, h );
}
/***************************************
* Returns if "text" clipping is switched on. If 'include_global'
* is set also also global clipping (used e.g. when redrawing on
* an expose event) is on, otherwise only clipping set via a call
* of fl_set_text_clipping() is reported.
***************************************/
int
fl_is_text_clipped( int include_global )
{
return is_clipped( FLI_TEXT_CLIP, include_global );
}
/***************************************
* Function for setting text clipping. If global clipping is on the rectangle
* set for clipping is the intersection of the rectangle specified by the
* arguments and the one for global clipping. Specifying a negative clipping
* width or height results in clipping becoming switched off.
***************************************/
void
fl_set_text_clipping( FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h )
{
set_clipping( FLI_TEXT_CLIP, flx->textgc, x, y, w, h );
}
/***************************************
* Function for switching of text clipping. Note that global clipping
* will be retained.
***************************************/
void
fl_unset_text_clipping( void )
{
unset_clipping( FLI_TEXT_CLIP, flx->textgc );
}
/***************************************
* Function for determining if text clipping is on and the region clipped
* to. If 'include_global' is set also clipping due to global clipping is
* taken into account (and the reported clipping region is the one resulting
* from intersection of the text clipping region and the one for global
* clipping). The function returns as its return value if there's clipping
* going on (which may, when 'include_global', also be due to global clipping).
***************************************/
int
fl_get_text_clipping( int include_global,
FL_Coord * x,
FL_Coord * y,
FL_Coord * w,
FL_Coord * h )
{
return get_clipping( FLI_TEXT_CLIP, include_global, x, y, w, h );
}
/***************************************
* Function for setting clipping for the specified GC. If global clipping is
* on the rectangle set for clipping is the intersection of the rectangle
* specified by the arguments and the one for global clipping. Specifying a
* negative clipping width or height results in clipping becoming switched off.
***************************************/
void
fl_set_gc_clipping( GC gc,
FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h )
{
fli_is_clipped[ FLI_GC_CLIP ] = 1;
set_clipping( FLI_GC_CLIP, gc, x, y, w, h );
}
/***************************************
* Function for switching of clipping for the given gc. Note that global
* clipping will be retained.
***************************************/
void
fl_unset_gc_clipping( GC gc )
{
fli_is_clipped[ FLI_GC_CLIP ] = 1;
unset_clipping( FLI_GC_CLIP, gc );
}
/***************************************
* Function that allows to set additional (always reducing the clipping
* rectangle further) to already set clipping - the intersection of the
* region and the already set clipping region is calculated and clipping
* then set to the resulting rectangle.
***************************************/
void
fli_set_additional_clipping( FL_Coord x,
FL_Coord y,
FL_Coord w,
FL_Coord h )
{
FL_RECT rect;
SET_RECT( rect, x, y, w, h );
if ( fli_is_clipped[ FLI_NORMAL_CLIP ] )
{
FL_RECT * r = fli_intersect_rects( fli_clip_rect + FLI_NORMAL_CLIP,
&rect );
if ( r )
{
rect = *r;
fli_safe_free( r );
}
else
SET_RECT( rect, 0, 0, 0, 0 );
}
fl_set_clipping( rect.x, rect.y, rect.width, rect.height );
}
/***************************************
***************************************/
static void
fli_set_current_gc( GC gc )
{
if ( flx->gc == gc )
return;
flx->gc = gc;
flx->color = FL_NoColor;
if ( fli_is_clipped[ FLI_GLOBAL_CLIP ]
&& fli_is_clipped[ FLI_NORMAL_CLIP ] )
{
FL_RECT * r = fli_intersect_rects( fli_clip_rect + FLI_GLOBAL_CLIP,
fli_clip_rect + FLI_NORMAL_CLIP );
if ( r )
{
XSetClipRectangles( flx->display, gc, 0, 0, r, 1, Unsorted );
fli_safe_free( r );
}
else
{
FL_RECT n = { 0, 0, 0, 0 };
XSetClipRectangles( flx->display, gc, 0, 0, &n, 1, Unsorted );
}
}
else if ( fli_is_clipped[ FLI_GLOBAL_CLIP ] )
XSetClipRectangles( flx->display, gc, 0, 0,
fli_clip_rect + FLI_GLOBAL_CLIP, 1, Unsorted );
else if ( fli_is_clipped[ FLI_NORMAL_CLIP ] )
XSetClipRectangles( flx->display, gc, 0, 0,
fli_clip_rect + FLI_NORMAL_CLIP, 1, Unsorted );
else
XSetClipMask( flx->display, gc, None );
}
/***************************************
* Manually dither non-gray scale colors by changing default GC. Grayscales
* are typically used in buttons, boxes etc, better not to dither them
***************************************/
static int
fli_mono_dither( unsigned long col )
{
int bwtrick = 0;
switch ( col )
{
case FL_RED:
case FL_MAGENTA:
case FL_SLATEBLUE:
case FL_PALEGREEN:
case FL_DARKGOLD:
case FL_INACTIVE_COL:
dithered_gc = fli_bwgc[ 1 ];
bwtrick = 1;
break;
case FL_YELLOW:
case FL_CYAN:
case FL_INDIANRED:
case FL_GREEN:
dithered_gc = fli_bwgc[ 2 ];
bwtrick = 1;
break;
case FL_BLUE:
dithered_gc = fli_bwgc[ 0 ];
bwtrick = 1;
break;
default:
if ( col >= FL_FREE_COL1 )
{
int r,
g,
b;
fl_get_icm_color( col, &r, &g, &b );
if ( ( bwtrick = ( r > 70 && r <= 210 ) ) )
dithered_gc = fli_bwgc[ r / 70 - 1 ];
}
break;
}
return bwtrick;
}
/*
* Local variables:
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
|