| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "tk3d.h" |
| 16 |
|
| 17 |
|
| 18 |
#if !(defined(__WIN32__) || defined(MAC_TCL) || defined(MAC_OSX_TK)) |
| 19 |
#include "tkUnixInt.h" |
| 20 |
#endif |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
typedef struct { |
| 28 |
TkBorder info; |
| 29 |
GC solidGC; |
| 30 |
} UnixBorder; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
TkBorder * |
| 49 |
TkpGetBorder() |
| 50 |
{ |
| 51 |
UnixBorder *borderPtr = (UnixBorder *) ckalloc(sizeof(UnixBorder)); |
| 52 |
borderPtr->solidGC = None; |
| 53 |
return (TkBorder *) borderPtr; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
void |
| 75 |
TkpFreeBorder(borderPtr) |
| 76 |
TkBorder *borderPtr; |
| 77 |
{ |
| 78 |
UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr; |
| 79 |
Display *display = DisplayOfScreen(borderPtr->screen); |
| 80 |
|
| 81 |
if (unixBorderPtr->solidGC != None) { |
| 82 |
Tk_FreeGC(display, unixBorderPtr->solidGC); |
| 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 |
void |
| 113 |
Tk_3DVerticalBevel(tkwin, drawable, border, x, y, width, height, |
| 114 |
leftBevel, relief) |
| 115 |
Tk_Window tkwin; |
| 116 |
Drawable drawable; |
| 117 |
Tk_3DBorder border; |
| 118 |
int x, y, width, height; |
| 119 |
int leftBevel; |
| 120 |
|
| 121 |
|
| 122 |
int relief; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
{ |
| 127 |
TkBorder *borderPtr = (TkBorder *) border; |
| 128 |
GC left, right; |
| 129 |
Display *display = Tk_Display(tkwin); |
| 130 |
|
| 131 |
if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT)) { |
| 132 |
TkpGetShadows(borderPtr, tkwin); |
| 133 |
} |
| 134 |
|
| 135 |
if (relief == TK_RELIEF_RAISED) { |
| 136 |
XFillRectangle(display, drawable, |
| 137 |
(leftBevel) ? borderPtr->lightGC : borderPtr->darkGC, |
| 138 |
x, y, (unsigned) width, (unsigned) height); |
| 139 |
} else if (relief == TK_RELIEF_SUNKEN) { |
| 140 |
XFillRectangle(display, drawable, |
| 141 |
(leftBevel) ? borderPtr->darkGC : borderPtr->lightGC, |
| 142 |
x, y, (unsigned) width, (unsigned) height); |
| 143 |
} else if (relief == TK_RELIEF_RIDGE) { |
| 144 |
int half; |
| 145 |
|
| 146 |
left = borderPtr->lightGC; |
| 147 |
right = borderPtr->darkGC; |
| 148 |
ridgeGroove: |
| 149 |
half = width/2; |
| 150 |
if (!leftBevel && (width & 1)) { |
| 151 |
half++; |
| 152 |
} |
| 153 |
XFillRectangle(display, drawable, left, x, y, (unsigned) half, |
| 154 |
(unsigned) height); |
| 155 |
XFillRectangle(display, drawable, right, x+half, y, |
| 156 |
(unsigned) (width-half), (unsigned) height); |
| 157 |
} else if (relief == TK_RELIEF_GROOVE) { |
| 158 |
left = borderPtr->darkGC; |
| 159 |
right = borderPtr->lightGC; |
| 160 |
goto ridgeGroove; |
| 161 |
} else if (relief == TK_RELIEF_FLAT) { |
| 162 |
XFillRectangle(display, drawable, borderPtr->bgGC, x, y, |
| 163 |
(unsigned) width, (unsigned) height); |
| 164 |
} else if (relief == TK_RELIEF_SOLID) { |
| 165 |
UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr; |
| 166 |
if (unixBorderPtr->solidGC == None) { |
| 167 |
XGCValues gcValues; |
| 168 |
|
| 169 |
gcValues.foreground = BlackPixelOfScreen(borderPtr->screen); |
| 170 |
unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground, &gcValues); |
| 171 |
} |
| 172 |
XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y, |
| 173 |
(unsigned) width, (unsigned) height); |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
void |
| 196 |
Tk_3DHorizontalBevel(tkwin, drawable, border, x, y, width, height, |
| 197 |
leftIn, rightIn, topBevel, relief) |
| 198 |
Tk_Window tkwin; |
| 199 |
Drawable drawable; |
| 200 |
Tk_3DBorder border; |
| 201 |
int x, y, width, height; |
| 202 |
|
| 203 |
int leftIn, rightIn; |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
int topBevel; |
| 214 |
|
| 215 |
|
| 216 |
int relief; |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
{ |
| 221 |
TkBorder *borderPtr = (TkBorder *) border; |
| 222 |
Display *display = Tk_Display(tkwin); |
| 223 |
int bottom, halfway, x1, x2, x1Delta, x2Delta; |
| 224 |
UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr; |
| 225 |
GC topGC = None, bottomGC = None; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT) && |
| 230 |
(relief != TK_RELIEF_SOLID)) { |
| 231 |
TkpGetShadows(borderPtr, tkwin); |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
switch (relief) { |
| 240 |
case TK_RELIEF_FLAT: |
| 241 |
topGC = bottomGC = borderPtr->bgGC; |
| 242 |
break; |
| 243 |
case TK_RELIEF_GROOVE: |
| 244 |
topGC = borderPtr->darkGC; |
| 245 |
bottomGC = borderPtr->lightGC; |
| 246 |
break; |
| 247 |
case TK_RELIEF_RAISED: |
| 248 |
topGC = bottomGC = |
| 249 |
(topBevel) ? borderPtr->lightGC : borderPtr->darkGC; |
| 250 |
break; |
| 251 |
case TK_RELIEF_RIDGE: |
| 252 |
topGC = borderPtr->lightGC; |
| 253 |
bottomGC = borderPtr->darkGC; |
| 254 |
break; |
| 255 |
case TK_RELIEF_SOLID: |
| 256 |
if (unixBorderPtr->solidGC == None) { |
| 257 |
XGCValues gcValues; |
| 258 |
|
| 259 |
gcValues.foreground = BlackPixelOfScreen(borderPtr->screen); |
| 260 |
unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground, |
| 261 |
&gcValues); |
| 262 |
} |
| 263 |
XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y, |
| 264 |
(unsigned) width, (unsigned) height); |
| 265 |
return; |
| 266 |
case TK_RELIEF_SUNKEN: |
| 267 |
topGC = bottomGC = |
| 268 |
(topBevel) ? borderPtr->darkGC : borderPtr->lightGC; |
| 269 |
break; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
x1 = x; |
| 277 |
if (!leftIn) { |
| 278 |
x1 += height; |
| 279 |
} |
| 280 |
x2 = x+width; |
| 281 |
if (!rightIn) { |
| 282 |
x2 -= height; |
| 283 |
} |
| 284 |
x1Delta = (leftIn) ? 1 : -1; |
| 285 |
x2Delta = (rightIn) ? -1 : 1; |
| 286 |
halfway = y + height/2; |
| 287 |
if (!topBevel && (height & 1)) { |
| 288 |
halfway++; |
| 289 |
} |
| 290 |
bottom = y + height; |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
for ( ; y < bottom; y++) { |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
if (x1 < -32767) |
| 302 |
x1 = -32767; |
| 303 |
if (x2 > 32767) |
| 304 |
x2 = 32767; |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
if (x1 < x2) { |
| 313 |
XFillRectangle(display, drawable, |
| 314 |
(y < halfway) ? topGC : bottomGC, x1, y, |
| 315 |
(unsigned) (x2-x1), (unsigned) 1); |
| 316 |
} |
| 317 |
x1 += x1Delta; |
| 318 |
x2 += x2Delta; |
| 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 |
void |
| 345 |
TkpGetShadows(borderPtr, tkwin) |
| 346 |
TkBorder *borderPtr; |
| 347 |
Tk_Window tkwin; |
| 348 |
|
| 349 |
{ |
| 350 |
XColor lightColor, darkColor; |
| 351 |
int stressed, tmp1, tmp2; |
| 352 |
int r, g, b; |
| 353 |
XGCValues gcValues; |
| 354 |
|
| 355 |
if (borderPtr->lightGC != None) { |
| 356 |
return; |
| 357 |
} |
| 358 |
stressed = TkpCmapStressed(tkwin, borderPtr->colormap); |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
if (!stressed && (Tk_Depth(tkwin) >= 6)) { |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
r = (int) borderPtr->bgColorPtr->red; |
| 395 |
g = (int) borderPtr->bgColorPtr->green; |
| 396 |
b = (int) borderPtr->bgColorPtr->blue; |
| 397 |
|
| 398 |
if (r*0.5*r + g*1.0*g + b*0.28*b < MAX_INTENSITY*0.05*MAX_INTENSITY) { |
| 399 |
darkColor.red = (MAX_INTENSITY + 3*r)/4; |
| 400 |
darkColor.green = (MAX_INTENSITY + 3*g)/4; |
| 401 |
darkColor.blue = (MAX_INTENSITY + 3*b)/4; |
| 402 |
} else { |
| 403 |
darkColor.red = (60 * r)/100; |
| 404 |
darkColor.green = (60 * g)/100; |
| 405 |
darkColor.blue = (60 * b)/100; |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
borderPtr->darkColorPtr = Tk_GetColorByValue(tkwin, &darkColor); |
| 413 |
gcValues.foreground = borderPtr->darkColorPtr->pixel; |
| 414 |
borderPtr->darkGC = Tk_GetGC(tkwin, GCForeground, &gcValues); |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
if (g > MAX_INTENSITY*0.95) { |
| 421 |
lightColor.red = (90 * r)/100; |
| 422 |
lightColor.green = (90 * g)/100; |
| 423 |
lightColor.blue = (90 * b)/100; |
| 424 |
} else { |
| 425 |
tmp1 = (14 * r)/10; |
| 426 |
if (tmp1 > MAX_INTENSITY) { |
| 427 |
tmp1 = MAX_INTENSITY; |
| 428 |
} |
| 429 |
tmp2 = (MAX_INTENSITY + r)/2; |
| 430 |
lightColor.red = (tmp1 > tmp2) ? tmp1 : tmp2; |
| 431 |
tmp1 = (14 * g)/10; |
| 432 |
if (tmp1 > MAX_INTENSITY) { |
| 433 |
tmp1 = MAX_INTENSITY; |
| 434 |
} |
| 435 |
tmp2 = (MAX_INTENSITY + g)/2; |
| 436 |
lightColor.green = (tmp1 > tmp2) ? tmp1 : tmp2; |
| 437 |
tmp1 = (14 * b)/10; |
| 438 |
if (tmp1 > MAX_INTENSITY) { |
| 439 |
tmp1 = MAX_INTENSITY; |
| 440 |
} |
| 441 |
tmp2 = (MAX_INTENSITY + b)/2; |
| 442 |
lightColor.blue = (tmp1 > tmp2) ? tmp1 : tmp2; |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
borderPtr->lightColorPtr = Tk_GetColorByValue(tkwin, &lightColor); |
| 450 |
gcValues.foreground = borderPtr->lightColorPtr->pixel; |
| 451 |
borderPtr->lightGC = Tk_GetGC(tkwin, GCForeground, &gcValues); |
| 452 |
return; |
| 453 |
} |
| 454 |
|
| 455 |
if (borderPtr->shadow == None) { |
| 456 |
borderPtr->shadow = Tk_GetBitmap((Tcl_Interp *) NULL, tkwin, |
| 457 |
Tk_GetUid("gray50")); |
| 458 |
if (borderPtr->shadow == None) { |
| 459 |
panic("TkpGetShadows couldn't allocate bitmap for border"); |
| 460 |
} |
| 461 |
} |
| 462 |
if (borderPtr->visual->map_entries > 2) { |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
gcValues.foreground = borderPtr->bgColorPtr->pixel; |
| 471 |
gcValues.background = BlackPixelOfScreen(borderPtr->screen); |
| 472 |
gcValues.stipple = borderPtr->shadow; |
| 473 |
gcValues.fill_style = FillOpaqueStippled; |
| 474 |
borderPtr->darkGC = Tk_GetGC(tkwin, |
| 475 |
GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues); |
| 476 |
gcValues.background = WhitePixelOfScreen(borderPtr->screen); |
| 477 |
borderPtr->lightGC = Tk_GetGC(tkwin, |
| 478 |
GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues); |
| 479 |
return; |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
gcValues.foreground = WhitePixelOfScreen(borderPtr->screen); |
| 489 |
gcValues.background = BlackPixelOfScreen(borderPtr->screen); |
| 490 |
gcValues.stipple = borderPtr->shadow; |
| 491 |
gcValues.fill_style = FillOpaqueStippled; |
| 492 |
borderPtr->lightGC = Tk_GetGC(tkwin, |
| 493 |
GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues); |
| 494 |
if (borderPtr->bgColorPtr->pixel |
| 495 |
== WhitePixelOfScreen(borderPtr->screen)) { |
| 496 |
gcValues.foreground = BlackPixelOfScreen(borderPtr->screen); |
| 497 |
borderPtr->darkGC = Tk_GetGC(tkwin, GCForeground, &gcValues); |
| 498 |
} else { |
| 499 |
borderPtr->darkGC = borderPtr->lightGC; |
| 500 |
borderPtr->lightGC = Tk_GetGC(tkwin, GCForeground, &gcValues); |
| 501 |
} |
| 502 |
} |