| 1 |
// See the included license.txt for copyright and license details. |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
/// |
|---|
| 5 |
module dfl.drawing; |
|---|
| 6 |
|
|---|
| 7 |
import dfl.internal.dlib, dfl.internal.gtk; |
|---|
| 8 |
import dfl.base; |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
/// X and Y coordinate. |
|---|
| 12 |
struct Point // docmain |
|---|
| 13 |
{ |
|---|
| 14 |
union |
|---|
| 15 |
{ |
|---|
| 16 |
struct |
|---|
| 17 |
{ |
|---|
| 18 |
gint x; |
|---|
| 19 |
gint y; |
|---|
| 20 |
} |
|---|
| 21 |
GdkPoint point; // package |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
/// Construct a new Point. |
|---|
| 26 |
static Point opCall(int x, int y) |
|---|
| 27 |
{ |
|---|
| 28 |
Point pt; |
|---|
| 29 |
pt.x = x; |
|---|
| 30 |
pt.y = y; |
|---|
| 31 |
return pt; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
/// ditto |
|---|
| 35 |
static Point opCall() |
|---|
| 36 |
{ |
|---|
| 37 |
Point pt; |
|---|
| 38 |
return pt; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
/// |
|---|
| 43 |
int opEquals(Point pt) |
|---|
| 44 |
{ |
|---|
| 45 |
return x == pt.x && y == pt.y; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
/// |
|---|
| 50 |
Point opAdd(Size sz) |
|---|
| 51 |
{ |
|---|
| 52 |
Point result; |
|---|
| 53 |
result.x = x + sz.width; |
|---|
| 54 |
result.y = y + sz.height; |
|---|
| 55 |
return result; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
/// |
|---|
| 60 |
Point opSub(Size sz) |
|---|
| 61 |
{ |
|---|
| 62 |
Point result; |
|---|
| 63 |
result.x = x - sz.width; |
|---|
| 64 |
result.y = y - sz.height; |
|---|
| 65 |
return result; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
/// |
|---|
| 70 |
void opAddAssign(Size sz) |
|---|
| 71 |
{ |
|---|
| 72 |
x += sz.width; |
|---|
| 73 |
y += sz.height; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
/// |
|---|
| 78 |
void opSubAssign(Size sz) |
|---|
| 79 |
{ |
|---|
| 80 |
x -= sz.width; |
|---|
| 81 |
y -= sz.height; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
/// |
|---|
| 86 |
Point opNeg() |
|---|
| 87 |
{ |
|---|
| 88 |
return Point(-x, -y); |
|---|
| 89 |
} |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
/// Width and height. |
|---|
| 94 |
struct Size // docmain |
|---|
| 95 |
{ |
|---|
| 96 |
union |
|---|
| 97 |
{ |
|---|
| 98 |
struct |
|---|
| 99 |
{ |
|---|
| 100 |
gint width; |
|---|
| 101 |
gint height; |
|---|
| 102 |
} |
|---|
| 103 |
//GdkSize size; // package |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
/// Construct a new Size. |
|---|
| 108 |
static Size opCall(int width, int height) |
|---|
| 109 |
{ |
|---|
| 110 |
Size sz; |
|---|
| 111 |
sz.width = width; |
|---|
| 112 |
sz.height = height; |
|---|
| 113 |
return sz; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
/// ditto |
|---|
| 117 |
static Size opCall() |
|---|
| 118 |
{ |
|---|
| 119 |
Size sz; |
|---|
| 120 |
return sz; |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
/// |
|---|
| 125 |
int opEquals(Size sz) |
|---|
| 126 |
{ |
|---|
| 127 |
return width == sz.width && height == sz.height; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
/// |
|---|
| 132 |
Size opAdd(Size sz) |
|---|
| 133 |
{ |
|---|
| 134 |
Size result; |
|---|
| 135 |
result.width = width + sz.width; |
|---|
| 136 |
result.height = height + sz.height; |
|---|
| 137 |
return result; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
/// |
|---|
| 142 |
Size opSub(Size sz) |
|---|
| 143 |
{ |
|---|
| 144 |
Size result; |
|---|
| 145 |
result.width = width - sz.width; |
|---|
| 146 |
result.height = height - sz.height; |
|---|
| 147 |
return result; |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
/// |
|---|
| 152 |
void opAddAssign(Size sz) |
|---|
| 153 |
{ |
|---|
| 154 |
width += sz.width; |
|---|
| 155 |
height += sz.height; |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
/// |
|---|
| 160 |
void opSubAssign(Size sz) |
|---|
| 161 |
{ |
|---|
| 162 |
width -= sz.width; |
|---|
| 163 |
height -= sz.height; |
|---|
| 164 |
} |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
/// X, Y, width and height rectangle dimensions. |
|---|
| 169 |
struct Rect // docmain |
|---|
| 170 |
{ |
|---|
| 171 |
union |
|---|
| 172 |
{ |
|---|
| 173 |
struct |
|---|
| 174 |
{ |
|---|
| 175 |
gint x, y, width, height; |
|---|
| 176 |
} |
|---|
| 177 |
GdkRectangle rect; // package |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
// Used internally. |
|---|
| 181 |
void getRect(GdkRectangle* r) // package |
|---|
| 182 |
{ |
|---|
| 183 |
*r = rect; |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
/// |
|---|
| 188 |
Point location() // getter |
|---|
| 189 |
{ |
|---|
| 190 |
return Point(x, y); |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
/// ditto |
|---|
| 194 |
void location(Point pt) // setter |
|---|
| 195 |
{ |
|---|
| 196 |
x = pt.x; |
|---|
| 197 |
y = pt.y; |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
/// |
|---|
| 202 |
Size size() //getter |
|---|
| 203 |
{ |
|---|
| 204 |
return Size(width, height); |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
/// ditto |
|---|
| 208 |
void size(Size sz) // setter |
|---|
| 209 |
{ |
|---|
| 210 |
width = sz.width; |
|---|
| 211 |
height = sz.height; |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
/// |
|---|
| 216 |
int right() // getter |
|---|
| 217 |
{ |
|---|
| 218 |
return x + width; |
|---|
| 219 |
} |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
/// |
|---|
| 223 |
int bottom() // getter |
|---|
| 224 |
{ |
|---|
| 225 |
return y + height; |
|---|
| 226 |
} |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
/// Construct a new Rect. |
|---|
| 230 |
static Rect opCall(int x, int y, int width, int height) |
|---|
| 231 |
{ |
|---|
| 232 |
Rect r; |
|---|
| 233 |
r.x = x; |
|---|
| 234 |
r.y = y; |
|---|
| 235 |
r.width = width; |
|---|
| 236 |
r.height = height; |
|---|
| 237 |
return r; |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
/// ditto |
|---|
| 241 |
static Rect opCall(Point location, Size size) |
|---|
| 242 |
{ |
|---|
| 243 |
Rect r; |
|---|
| 244 |
r.x = location.x; |
|---|
| 245 |
r.y = location.y; |
|---|
| 246 |
r.width = size.width; |
|---|
| 247 |
r.height = size.height; |
|---|
| 248 |
return r; |
|---|
| 249 |
} |
|---|
| 250 |
|
|---|
| 251 |
/// ditto |
|---|
| 252 |
static Rect opCall() |
|---|
| 253 |
{ |
|---|
| 254 |
Rect r; |
|---|
| 255 |
return r; |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
// Used internally. |
|---|
| 260 |
static Rect opCall(GdkRectangle* rect) // package |
|---|
| 261 |
{ |
|---|
| 262 |
Rect r; |
|---|
| 263 |
r.rect = *rect; |
|---|
| 264 |
return r; |
|---|
| 265 |
} |
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
/// Construct a new Rect from left, top, right and bottom values. |
|---|
| 269 |
static Rect fromLTRB(int left, int top, int right, int bottom) |
|---|
| 270 |
{ |
|---|
| 271 |
Rect r; |
|---|
| 272 |
r.x = left; |
|---|
| 273 |
r.y = top; |
|---|
| 274 |
r.width = right - left; |
|---|
| 275 |
r.height = bottom - top; |
|---|
| 276 |
return r; |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
/// |
|---|
| 281 |
int opEquals(Rect r) |
|---|
| 282 |
{ |
|---|
| 283 |
return x == r.x && y == r.y && |
|---|
| 284 |
width == r.width && height == r.height; |
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
/// |
|---|
| 289 |
bool contains(int c_x, int c_y) |
|---|
| 290 |
{ |
|---|
| 291 |
if(c_x >= x && c_y >= y) |
|---|
| 292 |
{ |
|---|
| 293 |
if(c_x <= right && c_y <= bottom) |
|---|
| 294 |
return true; |
|---|
| 295 |
} |
|---|
| 296 |
return false; |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
/// ditto |
|---|
| 300 |
bool contains(Point pos) |
|---|
| 301 |
{ |
|---|
| 302 |
return contains(pos.x, pos.y); |
|---|
| 303 |
} |
|---|
| 304 |
|
|---|
| 305 |
/// ditto |
|---|
| 306 |
// Contained entirely within -this-. |
|---|
| 307 |
bool contains(Rect r) |
|---|
| 308 |
{ |
|---|
| 309 |
if(r.x >= x && r.y >= y) |
|---|
| 310 |
{ |
|---|
| 311 |
if(r.right <= right && r.bottom <= bottom) |
|---|
| 312 |
return true; |
|---|
| 313 |
} |
|---|
| 314 |
return false; |
|---|
| 315 |
} |
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
/// |
|---|
| 319 |
void inflate(int i_width, int i_height) |
|---|
| 320 |
{ |
|---|
| 321 |
x -= i_width; |
|---|
| 322 |
width += i_width * 2; |
|---|
| 323 |
y -= i_height; |
|---|
| 324 |
height += i_height * 2; |
|---|
| 325 |
} |
|---|
| 326 |
|
|---|
| 327 |
/// ditto |
|---|
| 328 |
void inflate(Size insz) |
|---|
| 329 |
{ |
|---|
| 330 |
inflate(insz.width, insz.height); |
|---|
| 331 |
} |
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
/// |
|---|
| 335 |
// Just tests if there's an intersection. |
|---|
| 336 |
bool intersectsWith(Rect r) |
|---|
| 337 |
{ |
|---|
| 338 |
if(r.right >= x && r.bottom >= y) |
|---|
| 339 |
{ |
|---|
| 340 |
if(r.y <= bottom && r.x <= right) |
|---|
| 341 |
return true; |
|---|
| 342 |
} |
|---|
| 343 |
return false; |
|---|
| 344 |
} |
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
/// |
|---|
| 348 |
void offset(int x, int y) |
|---|
| 349 |
{ |
|---|
| 350 |
this.x += x; |
|---|
| 351 |
this.y += y; |
|---|
| 352 |
} |
|---|
| 353 |
|
|---|
| 354 |
/// ditto |
|---|
| 355 |
void offset(Point pt) |
|---|
| 356 |
{ |
|---|
| 357 |
//return offset(pt.x, pt.y); |
|---|
| 358 |
this.x += pt.x; |
|---|
| 359 |
this.y += pt.y; |
|---|
| 360 |
} |
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
/+ |
|---|
| 364 |
// Modify -this- to include only the intersection |
|---|
| 365 |
// of -this- and -r-. |
|---|
| 366 |
void intersect(Rect r) |
|---|
| 367 |
{ |
|---|
| 368 |
} |
|---|
| 369 |
+/ |
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
// void offset(Point), void offset(int, int) |
|---|
| 373 |
// static Rect union(Rect, Rect) |
|---|
| 374 |
} |
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
unittest |
|---|
| 378 |
{ |
|---|
| 379 |
Rect r = Rect(3, 3, 3, 3); |
|---|
| 380 |
|
|---|
| 381 |
assert(r.contains(3, 3)); |
|---|
| 382 |
assert(!r.contains(3, 2)); |
|---|
| 383 |
assert(r.contains(6, 6)); |
|---|
| 384 |
assert(!r.contains(6, 7)); |
|---|
| 385 |
assert(r.contains(r)); |
|---|
| 386 |
assert(r.contains(Rect(4, 4, 2, 2))); |
|---|
| 387 |
assert(!r.contains(Rect(2, 4, 4, 2))); |
|---|
| 388 |
assert(!r.contains(Rect(4, 3, 2, 4))); |
|---|
| 389 |
|
|---|
| 390 |
r.inflate(2, 1); |
|---|
| 391 |
assert(r.x == 1); |
|---|
| 392 |
assert(r.right == 8); |
|---|
| 393 |
assert(r.y == 2); |
|---|
| 394 |
assert(r.bottom == 7); |
|---|
| 395 |
r.inflate(-2, -1); |
|---|
| 396 |
assert(r == Rect(3, 3, 3, 3)); |
|---|
| 397 |
|
|---|
| 398 |
assert(r.intersectsWith(Rect(4, 4, 2, 9))); |
|---|
| 399 |
assert(r.intersectsWith(Rect(3, 3, 1, 1))); |
|---|
| 400 |
assert(r.intersectsWith(Rect(0, 3, 3, 0))); |
|---|
| 401 |
assert(r.intersectsWith(Rect(3, 2, 0, 1))); |
|---|
| 402 |
assert(!r.intersectsWith(Rect(3, 1, 0, 1))); |
|---|
| 403 |
assert(r.intersectsWith(Rect(5, 6, 1, 1))); |
|---|
| 404 |
assert(!r.intersectsWith(Rect(7, 6, 1, 1))); |
|---|
| 405 |
assert(!r.intersectsWith(Rect(6, 7, 1, 1))); |
|---|
| 406 |
} |
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
/// Color value representation |
|---|
| 410 |
struct Color // docmain |
|---|
| 411 |
{ |
|---|
| 412 |
/// Red, green, blue and alpha channel color values. |
|---|
| 413 |
ubyte r() // getter |
|---|
| 414 |
{ validateColor(); return color.red; } |
|---|
| 415 |
|
|---|
| 416 |
/// ditto |
|---|
| 417 |
ubyte g() // getter |
|---|
| 418 |
{ validateColor(); return color.green; } |
|---|
| 419 |
|
|---|
| 420 |
/// ditto |
|---|
| 421 |
ubyte b() // getter |
|---|
| 422 |
{ validateColor(); return color.blue; } |
|---|
| 423 |
|
|---|
| 424 |
/// ditto |
|---|
| 425 |
ubyte a() // getter |
|---|
| 426 |
{ /+ validateColor(); +/ return color.alpha; } |
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
/// Return the numeric color value. |
|---|
| 430 |
guint32 toArgb() |
|---|
| 431 |
{ |
|---|
| 432 |
validateColor(); |
|---|
| 433 |
return color.cref; |
|---|
| 434 |
} |
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
/// Return the numeric red, green and blue color value. |
|---|
| 438 |
guint32 toRgb() |
|---|
| 439 |
{ |
|---|
| 440 |
validateColor(); |
|---|
| 441 |
return color.cref & 0x00FFFFFF; |
|---|
| 442 |
} |
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
/// Construct a new color. |
|---|
| 446 |
static Color opCall(ubyte alpha, Color c) |
|---|
| 447 |
{ |
|---|
| 448 |
Color nc; |
|---|
| 449 |
nc.color.blue = c.color.blue; |
|---|
| 450 |
nc.color.green = c.color.green; |
|---|
| 451 |
nc.color.red = c.color.red; |
|---|
| 452 |
nc.color.alpha = alpha; |
|---|
| 453 |
return nc; |
|---|
| 454 |
} |
|---|
| 455 |
|
|---|
| 456 |
/// ditto |
|---|
| 457 |
static Color opCall(ubyte red, ubyte green, ubyte blue) |
|---|
| 458 |
{ |
|---|
| 459 |
Color nc; |
|---|
| 460 |
nc.color.blue = blue; |
|---|
| 461 |
nc.color.green = green; |
|---|
| 462 |
nc.color.red = red; |
|---|
| 463 |
nc.color.alpha = 0xFF; |
|---|
| 464 |
return nc; |
|---|
| 465 |
} |
|---|
| 466 |
|
|---|
| 467 |
/// ditto |
|---|
| 468 |
static Color opCall(ubyte alpha, ubyte red, ubyte green, ubyte blue) |
|---|
| 469 |
{ |
|---|
| 470 |
return fromArgb(alpha, red, green, blue); |
|---|
| 471 |
} |
|---|
| 472 |
|
|---|
| 473 |
/// ditto |
|---|
| 474 |
//alias opCall fromArgb; |
|---|
| 475 |
static Color fromArgb(ubyte alpha, ubyte red, ubyte green, ubyte blue) |
|---|
| 476 |
{ |
|---|
| 477 |
Color nc; |
|---|
| 478 |
nc.color.blue = blue; |
|---|
| 479 |
nc.color.green = green; |
|---|
| 480 |
nc.color.red = red; |
|---|
| 481 |
nc.color.alpha = alpha; |
|---|
| 482 |
return nc; |
|---|
| 483 |
} |
|---|
| 484 |
|
|---|
| 485 |
/// ditto |
|---|
| 486 |
static Color fromRgb(guint32 rgb) |
|---|
| 487 |
{ |
|---|
| 488 |
if(0xFFFFFFFF == rgb) |
|---|
| 489 |
return empty; |
|---|
| 490 |
Color nc; |
|---|
| 491 |
nc.color.cref = rgb; |
|---|
| 492 |
nc.color.alpha = 0xFF; |
|---|
| 493 |
return nc; |
|---|
| 494 |
} |
|---|
| 495 |
|
|---|
| 496 |
/// ditto |
|---|
| 497 |
static Color fromRgb(ubyte alpha, guint32 rgb) |
|---|
| 498 |
{ |
|---|
| 499 |
Color nc; |
|---|
| 500 |
nc.color.cref = rgb | ((cast(guint32)alpha) << 24); |
|---|
| 501 |
return nc; |
|---|
| 502 |
} |
|---|
| 503 |
|
|---|
| 504 |
/// ditto |
|---|
| 505 |
static Color empty() // getter |
|---|
| 506 |
{ |
|---|
| 507 |
return Color(0, 0, 0, 0); |
|---|
| 508 |
} |
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
/// Return a completely transparent color value. |
|---|
| 512 |
static Color transparent() // getter |
|---|
| 513 |
{ |
|---|
| 514 |
return Color.fromArgb(0, 0xFF, 0xFF, 0xFF); |
|---|
| 515 |
} |
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
deprecated alias blendColor blend; |
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
/// Blend colors; alpha channels are ignored. |
|---|
| 522 |
// Blends the color channels half way. |
|---|
| 523 |
// Does not consider alpha channels and discards them. |
|---|
| 524 |
// The new blended color is returned; -this- Color is not modified. |
|---|
| 525 |
Color blendColor(Color wc) |
|---|
| 526 |
{ |
|---|
| 527 |
if(*this == Color.empty) |
|---|
| 528 |
return wc; |
|---|
| 529 |
if(wc == Color.empty) |
|---|
| 530 |
return *this; |
|---|
| 531 |
|
|---|
| 532 |
validateColor(); |
|---|
| 533 |
wc.validateColor(); |
|---|
| 534 |
|
|---|
| 535 |
return Color((cast(uint)color.red + cast(uint)wc.color.red) >> 1, |
|---|
| 536 |
(cast(uint)color.green + cast(uint)wc.color.green) >> 1, |
|---|
| 537 |
(cast(uint)color.blue + cast(uint)wc.color.blue) >> 1); |
|---|
| 538 |
} |
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
/// Alpha blend this color with a background color to return a solid color (100% opaque). |
|---|
| 542 |
// Blends with backColor if this color has opacity to produce a solid color. |
|---|
| 543 |
// Returns the new solid color, or the original color if no opacity. |
|---|
| 544 |
// If backColor has opacity, it is ignored. |
|---|
| 545 |
// The new blended color is returned; -this- Color is not modified. |
|---|
| 546 |
Color solidColor(Color backColor) |
|---|
| 547 |
{ |
|---|
| 548 |
//if(0x7F == this.color.alpha) |
|---|
| 549 |
// return blendColor(backColor); |
|---|
| 550 |
//if(*this == Color.empty) // Checked if(0 == this.color.alpha) |
|---|
| 551 |
// return backColor; |
|---|
| 552 |
if(0 == this.color.alpha) |
|---|
| 553 |
return backColor; |
|---|
| 554 |
if(backColor == Color.empty) |
|---|
| 555 |
return *this; |
|---|
| 556 |
if(0xFF == this.color.alpha) |
|---|
| 557 |
return *this; |
|---|
| 558 |
|
|---|
| 559 |
validateColor(); |
|---|
| 560 |
backColor.validateColor(); |
|---|
| 561 |
|
|---|
| 562 |
float fa, ba; |
|---|
| 563 |
fa = cast(float)color.alpha / 255.0; |
|---|
| 564 |
ba = 1.0 - fa; |
|---|
| 565 |
|
|---|
| 566 |
Color result; |
|---|
| 567 |
result.color.alpha = 0xFF; |
|---|
| 568 |
result.color.red = cast(ubyte)(this.color.red * fa + backColor.color.red * ba); |
|---|
| 569 |
result.color.green = cast(ubyte)(this.color.green * fa + backColor.color.green * ba); |
|---|
| 570 |
result.color.blue = cast(ubyte)(this.color.blue * fa + backColor.color.blue * ba); |
|---|
| 571 |
return result; |
|---|
| 572 |
} |
|---|
| 573 |
|
|---|
| 574 |
|
|---|
| 575 |
/+ |
|---|
| 576 |
package static Color systemColor(int colorIndex) |
|---|
| 577 |
{ |
|---|
| 578 |
Color c; |
|---|
| 579 |
c.sysIndex = colorIndex; |
|---|
| 580 |
c.color.alpha = 0xFF; |
|---|
| 581 |
return c; |
|---|
| 582 |
} |
|---|
| 583 |
|
|---|
| 584 |
|
|---|
| 585 |
// Gets color index or INVAILD_SYSTEM_COLOR_INDEX. |
|---|
| 586 |
package int _systemColorIndex() // getter |
|---|
| 587 |
{ |
|---|
| 588 |
return sysIndex; |
|---|
| 589 |
} |
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
package const ubyte INVAILD_SYSTEM_COLOR_INDEX = ubyte.max; |
|---|
| 593 |
+/ |
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
private: |
|---|
| 597 |
union _color |
|---|
| 598 |
{ |
|---|
| 599 |
struct |
|---|
| 600 |
{ |
|---|
| 601 |
align(1): |
|---|
| 602 |
ubyte red; |
|---|
| 603 |
ubyte green; |
|---|
| 604 |
ubyte blue; |
|---|
| 605 |
ubyte alpha; |
|---|
| 606 |
} |
|---|
| 607 |
guint32 cref; |
|---|
| 608 |
} |
|---|
| 609 |
static assert(_color.sizeof == guint32.sizeof); |
|---|
| 610 |
_color color; |
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
void validateColor() |
|---|
| 614 |
{ |
|---|
| 615 |
/+ |
|---|
| 616 |
if(sysIndex != INVAILD_SYSTEM_COLOR_INDEX) |
|---|
| 617 |
{ |
|---|
| 618 |
color.cref = GetSysColor(sysIndex); |
|---|
| 619 |
//color.alpha = 0xFF; // Should already be set. |
|---|
| 620 |
} |
|---|
| 621 |
+/ |
|---|
| 622 |
} |
|---|
| 623 |
} |
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
/+ // To-do: ... |
|---|
| 627 |
/// |
|---|
| 628 |
class SystemColors // docmain |
|---|
| 629 |
{ |
|---|
| 630 |
private this() |
|---|
| 631 |
{ |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
static: |
|---|
| 636 |
|
|---|
| 637 |
/// |
|---|
| 638 |
Color activeBorder() // getter |
|---|
| 639 |
{ |
|---|
| 640 |
return Color.systemColor(COLOR_ACTIVEBORDER); |
|---|
| 641 |
} |
|---|
| 642 |
|
|---|
| 643 |
/// ditto |
|---|
| 644 |
Color activeCaption() // getter |
|---|
| 645 |
{ |
|---|
| 646 |
return Color.systemColor(COLOR_ACTIVECAPTION); |
|---|
| 647 |
} |
|---|
| 648 |
|
|---|
| 649 |
/// ditto |
|---|
| 650 |
Color activeCaptionText() // getter |
|---|
| 651 |
{ |
|---|
| 652 |
return Color.systemColor(COLOR_CAPTIONTEXT); |
|---|
| 653 |
} |
|---|
| 654 |
|
|---|
| 655 |
/// ditto |
|---|
| 656 |
Color appWorkspace() // getter |
|---|
| 657 |
{ |
|---|
| 658 |
return Color.systemColor(COLOR_APPWORKSPACE); |
|---|
| 659 |
} |
|---|
| 660 |
|
|---|
| 661 |
/// ditto |
|---|
| 662 |
Color control() // getter |
|---|
| 663 |
{ |
|---|
| 664 |
return Color.systemColor(COLOR_BTNFACE); |
|---|
| 665 |
} |
|---|
| 666 |
|
|---|
| 667 |
/// ditto |
|---|
| 668 |
Color controlDark() // getter |
|---|
| 669 |
{ |
|---|
| 670 |
return Color.systemColor(COLOR_BTNSHADOW); |
|---|
| 671 |
} |
|---|
| 672 |
|
|---|
| 673 |
/// ditto |
|---|
| 674 |
Color controlDarkDark() // getter |
|---|
| 675 |
{ |
|---|
| 676 |
return Color.systemColor(COLOR_3DDKSHADOW); // ? |
|---|
| 677 |
} |
|---|
| 678 |
|
|---|
| 679 |
/// ditto |
|---|
| 680 |
Color controlLight() // getter |
|---|
| 681 |
{ |
|---|
| 682 |
return Color.systemColor(COLOR_3DLIGHT); |
|---|
| 683 |
} |
|---|
| 684 |
|
|---|
| 685 |
/// ditto |
|---|
| 686 |
Color controlLightLight() // getter |
|---|
| 687 |
{ |
|---|
| 688 |
return Color.systemColor(COLOR_BTNHIGHLIGHT); // ? |
|---|
| 689 |
} |
|---|
| 690 |
|
|---|
| 691 |
/// ditto |
|---|
| 692 |
Color controlText() // getter |
|---|
| 693 |
{ |
|---|
| 694 |
return Color.systemColor(COLOR_BTNTEXT); |
|---|
| 695 |
} |
|---|
| 696 |
|
|---|
| 697 |
/// ditto |
|---|
| 698 |
Color desktop() // getter |
|---|
| 699 |
{ |
|---|
| 700 |
return Color.systemColor(COLOR_DESKTOP); |
|---|
| 701 |
} |
|---|
| 702 |
|
|---|
| 703 |
/// ditto |
|---|
| 704 |
Color grayText() // getter |
|---|
| 705 |
{ |
|---|
| 706 |
return Color.systemColor(COLOR_GRAYTEXT); |
|---|
| 707 |
} |
|---|
| 708 |
|
|---|
| 709 |
/// ditto |
|---|
| 710 |
Color highlight() // getter |
|---|
| 711 |
{ |
|---|
| 712 |
return Color.systemColor(COLOR_HIGHLIGHT); |
|---|
| 713 |
} |
|---|
| 714 |
|
|---|
| 715 |
/// ditto |
|---|
| 716 |
Color highlightText() // getter |
|---|
| 717 |
{ |
|---|
| 718 |
return Color.systemColor(COLOR_HIGHLIGHTTEXT); |
|---|
| 719 |
} |
|---|
| 720 |
|
|---|
| 721 |
/// ditto |
|---|
| 722 |
Color hotTrack() // getter |
|---|
| 723 |
{ |
|---|
| 724 |
return Color(0, 0, 0xFF); // ? |
|---|
| 725 |
} |
|---|
| 726 |
|
|---|
| 727 |
/// ditto |
|---|
| 728 |
Color inactiveBorder() // getter |
|---|
| 729 |
{ |
|---|
| 730 |
return Color.systemColor(COLOR_INACTIVEBORDER); |
|---|
| 731 |
} |
|---|
| 732 |
|
|---|
| 733 |
/// ditto |
|---|
| 734 |
Color inactiveCaption() // getter |
|---|
| 735 |
{ |
|---|
| 736 |
return Color.systemColor(COLOR_INACTIVECAPTION); |
|---|
| 737 |
} |
|---|
| 738 |
|
|---|
| 739 |
/// ditto |
|---|
| 740 |
Color inactiveCaptionText() // getter |
|---|
| 741 |
{ |
|---|
| 742 |
return Color.systemColor(COLOR_INACTIVECAPTIONTEXT); |
|---|
| 743 |
} |
|---|
| 744 |
|
|---|
| 745 |
/// ditto |
|---|
| 746 |
Color info() // getter |
|---|
| 747 |
{ |
|---|
| 748 |
return Color.systemColor(COLOR_INFOBK); |
|---|
| 749 |
} |
|---|
| 750 |
|
|---|
| 751 |
/// ditto |
|---|
| 752 |
Color infoText() // getter |
|---|
| 753 |
{ |
|---|
| 754 |
return Color.systemColor(COLOR_INFOTEXT); |
|---|
| 755 |
} |
|---|
| 756 |
|
|---|
| 757 |
/// ditto |
|---|
| 758 |
Color menu() // getter |
|---|
| 759 |
{ |
|---|
| 760 |
return Color.systemColor(COLOR_MENU); |
|---|
| 761 |
} |
|---|
| 762 |
|
|---|
| 763 |
/// ditto |
|---|
| 764 |
Color menuText() // getter |
|---|
| 765 |
{ |
|---|
| 766 |
return Color.systemColor(COLOR_MENUTEXT); |
|---|
| 767 |
} |
|---|
| 768 |
|
|---|
| 769 |
/// ditto |
|---|
| 770 |
Color scrollBar() // getter |
|---|
| 771 |
{ |
|---|
| 772 |
return Color.systemColor(CTLCOLOR_SCROLLBAR); |
|---|
| 773 |
} |
|---|
| 774 |
|
|---|
| 775 |
/// ditto |
|---|
| 776 |
Color window() // getter |
|---|
| 777 |
{ |
|---|
| 778 |
return Color.systemColor(COLOR_WINDOW); |
|---|
| 779 |
} |
|---|
| 780 |
|
|---|
| 781 |
/// ditto |
|---|
| 782 |
Color windowFrame() // getter |
|---|
| 783 |
{ |
|---|
| 784 |
return Color.systemColor(COLOR_WINDOWFRAME); |
|---|
| 785 |
} |
|---|
| 786 |
|
|---|
| 787 |
/// ditto |
|---|
| 788 |
Color windowText() // getter |
|---|
| 789 |
{ |
|---|
| 790 |
return Color.systemColor(COLOR_WINDOWTEXT); |
|---|
| 791 |
} |
|---|
| 792 |
} |
|---|
| 793 |
+/ |
|---|
| 794 |
|
|---|
| 795 |
|
|---|
| 796 |
/+ // To-do: ... |
|---|
| 797 |
/// |
|---|
| 798 |
class SystemIcons // docmain |
|---|
| 799 |
{ |
|---|
| 800 |
private this() |
|---|
| 801 |
{ |
|---|
| 802 |
} |
|---|
| 803 |
|
|---|
| 804 |
|
|---|
| 805 |
static: |
|---|
| 806 |
|
|---|
| 807 |
/// |
|---|
| 808 |
Icon application() // getter |
|---|
| 809 |
{ |
|---|
| 810 |
return new Icon(LoadImageA(null, IDI_APPLICATION, |
|---|
| 811 |
IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED), false); |
|---|
| 812 |
} |
|---|
| 813 |
|
|---|
| 814 |
/// ditto |
|---|
| 815 |
Icon error() // getter |
|---|
| 816 |
{ |
|---|
| 817 |
return new Icon(LoadImageA(null, IDI_HAND, |
|---|
| 818 |
IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED), false); |
|---|
| 819 |
} |
|---|
| 820 |
|
|---|
| 821 |
/// ditto |
|---|
| 822 |
Icon question() // getter |
|---|
| 823 |
{ |
|---|
| 824 |
return new Icon(LoadImageA(null, IDI_QUESTION, |
|---|
| 825 |
IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED), false); |
|---|
| 826 |
} |
|---|
| 827 |
|
|---|
| 828 |
/// ditto |
|---|
| 829 |
Icon warning() // getter |
|---|
| 830 |
{ |
|---|
| 831 |
return new Icon(LoadImageA(null, IDI_EXCLAMATION, |
|---|
| 832 |
IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED), false); |
|---|
| 833 |
} |
|---|
| 834 |
} |
|---|
| 835 |
+/ |
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
/// |
|---|
| 839 |
abstract class Image // docmain |
|---|
| 840 |
{ |
|---|
| 841 |
//flags(); // getter ??? |
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 |
/+ |
|---|
| 845 |
final ImageFormat rawFormat(); // getter |
|---|
| 846 |
+/ |
|---|
| 847 |
|
|---|
| 848 |
|
|---|
| 849 |
static Bitmap fromHBitmap(GdkBitmap* hbm) // package |
|---|
| 850 |
{ |
|---|
| 851 |
return new Bitmap(hbm, false); // Not owned. Up to caller to manage or call dispose(). |
|---|
| 852 |
} |
|---|
| 853 |
|
|---|
| 854 |
|
|---|
| 855 |
/+ |
|---|
| 856 |
static Image fromFile(char[] file) |
|---|
| 857 |
{ |
|---|
| 858 |
return new Image(LoadImageA()); |
|---|
| 859 |
} |
|---|
| 860 |
+/ |
|---|
| 861 |
|
|---|
| 862 |
|
|---|
| 863 |
/// |
|---|
| 864 |
void draw(Graphics g, Point pt); |
|---|
| 865 |
/// ditto |
|---|
| 866 |
void drawStretched(Graphics g, Rect r); |
|---|
| 867 |
|
|---|
| 868 |
|
|---|
| 869 |
/// |
|---|
| 870 |
Size size(); // getter |
|---|
| 871 |
|
|---|
| 872 |
|
|---|
| 873 |
/// |
|---|
| 874 |
int width() // getter |
|---|
| 875 |
{ |
|---|
| 876 |
return size.width; |
|---|
| 877 |
} |
|---|
| 878 |
|
|---|
| 879 |
|
|---|
| 880 |
/// |
|---|
| 881 |
int height() // getter |
|---|
| 882 |
{ |
|---|
| 883 |
return size.height; |
|---|
| 884 |
} |
|---|
| 885 |
} |
|---|
| 886 |
|
|---|
| 887 |
|
|---|
| 888 |
// To-do: derive from Image when supported! |
|---|
| 889 |
/// |
|---|
| 890 |
class Bitmap//: Image // docmain |
|---|
| 891 |
{ |
|---|
| 892 |
/// |
|---|
| 893 |
// Load from a bmp file. |
|---|
| 894 |
this(char[] fileName) |
|---|
| 895 |
{ |
|---|
| 896 |
//this.hbm = |
|---|
| 897 |
// To-do: ... |
|---|
| 898 |
if(!this.hbm) |
|---|
| 899 |
throw new DflException("Unable to load bitmap from file '" ~ fileName ~ "'"); |
|---|
| 900 |
} |
|---|
| 901 |
|
|---|
| 902 |
// Used internally. |
|---|
| 903 |
this(GdkBitmap* hbm, bool owned = true) |
|---|
| 904 |
{ |
|---|
| 905 |
this.hbm = hbm; |
|---|
| 906 |
this.owned = owned; |
|---|
| 907 |
} |
|---|
| 908 |
|
|---|
| 909 |
|
|---|
| 910 |
/// |
|---|
| 911 |
final GdkBitmap* handle() // getter |
|---|
| 912 |
{ |
|---|
| 913 |
return hbm; |
|---|
| 914 |
} |
|---|
| 915 |
|
|---|
| 916 |
|
|---|
| 917 |
/+ |
|---|
| 918 |
private void _getInfo(BITMAP* bm) |
|---|
| 919 |
{ |
|---|
| 920 |
if(GetObjectA(hbm, BITMAP.sizeof, bm) != BITMAP.sizeof) |
|---|
| 921 |
throw new DflException("Unable to get image information"); |
|---|
| 922 |
} |
|---|
| 923 |
+/ |
|---|
| 924 |
|
|---|
| 925 |
|
|---|
| 926 |
/+ |
|---|
| 927 |
/// |
|---|
| 928 |
final override Size size() // getter |
|---|
| 929 |
{ |
|---|
| 930 |
/+ |
|---|
| 931 |
BITMAP bm; |
|---|
| 932 |
_getInfo(&bm); |
|---|
| 933 |
return Size(bm.bmWidth, bm.bmHeight); |
|---|
| 934 |
+/ |
|---|
| 935 |
// To-do: ... |
|---|
| 936 |
} |
|---|
| 937 |
+/ |
|---|
| 938 |
|
|---|
| 939 |
|
|---|
| 940 |
/+ |
|---|
| 941 |
/// |
|---|
| 942 |
final override int width() // getter |
|---|
| 943 |
{ |
|---|
| 944 |
return size.width; |
|---|
| 945 |
} |
|---|
| 946 |
|
|---|
| 947 |
|
|---|
| 948 |
/// |
|---|
| 949 |
final override int height() // getter |
|---|
| 950 |
{ |
|---|
| 951 |
return size.height; |
|---|
| 952 |
} |
|---|
| 953 |
+/ |
|---|
| 954 |
|
|---|
| 955 |
|
|---|
| 956 |
/+ // To-do: ... ... |
|---|
| 957 |
private void _draw(Graphics g, Point pt, HDC memdc) |
|---|
| 958 |
{ |
|---|
| 959 |
HGDIOBJ hgo; |
|---|
| 960 |
Size sz; |
|---|
| 961 |
|
|---|
| 962 |
sz = size; |
|---|
| 963 |
hgo = SelectObject(memdc, hbm); |
|---|
| 964 |
BitBlt(g.handle, pt.x, pt.y, sz.width, sz.height, memdc, 0, 0, SRCCOPY); |
|---|
| 965 |
SelectObject(memdc, hgo); // Old bitmap. |
|---|
| 966 |
} |
|---|
| 967 |
|
|---|
| 968 |
|
|---|
| 969 |
/// |
|---|
| 970 |
final override void draw(Graphics g, Point pt) |
|---|
| 971 |
{ |
|---|
| 972 |
HDC memdc; |
|---|
| 973 |
memdc = CreateCompatibleDC(g.handle); |
|---|
| 974 |
try |
|---|
| 975 |
{ |
|---|
| 976 |
_draw(g, pt, memdc); |
|---|
| 977 |
} |
|---|
| 978 |
finally |
|---|
| 979 |
{ |
|---|
| 980 |
DeleteDC(memdc); |
|---|
| 981 |
} |
|---|
| 982 |
} |
|---|
| 983 |
|
|---|
| 984 |
/// ditto |
|---|
| 985 |
// -tempMemGraphics- is used as a temporary Graphics instead of |
|---|
| 986 |
// creating and destroying a temporary one for each call. |
|---|
| 987 |
final void draw(Graphics g, Point pt, Graphics tempMemGraphics) |
|---|
| 988 |
{ |
|---|
| 989 |
_draw(g, pt, tempMemGraphics.handle); |
|---|
| 990 |
} |
|---|
| 991 |
|
|---|
| 992 |
|
|---|
| 993 |
private void _drawStretched(Graphics g, Rect r, HDC memdc) |
|---|
| 994 |
{ |
|---|
| 995 |
HGDIOBJ hgo; |
|---|
| 996 |
Size sz; |
|---|
| 997 |
int lstretch; |
|---|
| 998 |
|
|---|
| 999 |
sz = size; |
|---|
| 1000 |
hgo = SelectObject(memdc, hbm); |
|---|
| 1001 |
lstretch = SetStretchBltMode(g.handle, COLORONCOLOR); |
|---|
| 1002 |
StretchBlt(g.handle, r.x, r.y, r.width, r.height, memdc, 0, 0, sz.width, sz.height, SRCCOPY); |
|---|
| 1003 |
SetStretchBltMode(g.handle, lstretch); |
|---|
| 1004 |
SelectObject(memdc, hgo); // Old bitmap. |
|---|
| 1005 |
} |
|---|
| 1006 |
|
|---|
| 1007 |
|
|---|
| 1008 |
/// |
|---|
| 1009 |
final override void drawStretched(Graphics g, Rect r) |
|---|
| 1010 |
{ |
|---|
| 1011 |
HDC memdc; |
|---|
| 1012 |
memdc = CreateCompatibleDC(g.handle); |
|---|
| 1013 |
try |
|---|
| 1014 |
{ |
|---|
| 1015 |
_drawStretched(g, r, memdc); |
|---|
| 1016 |
} |
|---|
| 1017 |
finally |
|---|
| 1018 |
{ |
|---|
| 1019 |
DeleteDC(memdc); |
|---|
| 1020 |
} |
|---|
| 1021 |
} |
|---|
| 1022 |
|
|---|
| 1023 |
/// ditto |
|---|
| 1024 |
// -tempMemGraphics- is used as a temporary Graphics instead of |
|---|
| 1025 |
// creating and destroying a temporary one for each call. |
|---|
| 1026 |
final void drawStretched(Graphics g, Rect r, Graphics tempMemGraphics) |
|---|
| 1027 |
{ |
|---|
| 1028 |
_drawStretched(g, r, tempMemGraphics.handle); |
|---|
| 1029 |
} |
|---|
| 1030 |
+/ |
|---|
| 1031 |
|
|---|
| 1032 |
|
|---|
| 1033 |
/// |
|---|
| 1034 |
void dispose() |
|---|
| 1035 |
{ |
|---|
| 1036 |
if(hbm) |
|---|
| 1037 |
{ |
|---|
| 1038 |
g_object_unref(hbm); |
|---|
| 1039 |
hbm = null; |
|---|
| 1040 |
} |
|---|
| 1041 |
} |
|---|
| 1042 |
|
|---|
| 1043 |
|
|---|
| 1044 |
~this() |
|---|
| 1045 |
{ |
|---|
| 1046 |
if(owned) |
|---|
| 1047 |
dispose(); |
|---|
| 1048 |
} |
|---|
| 1049 |
|
|---|
| 1050 |
|
|---|
| 1051 |
private: |
|---|
| 1052 |
GdkBitmap* hbm; |
|---|
| 1053 |
bool owned = true; |
|---|
| 1054 |
} |
|---|
| 1055 |
|
|---|
| 1056 |
|
|---|
| 1057 |
// To-do: ... |
|---|
| 1058 |
|
|---|
| 1059 |
/// |
|---|
| 1060 |
enum TextTrimming: uint |
|---|
| 1061 |
{ |
|---|
| 1062 |
_none, |
|---|
| 1063 |
} |
|---|
| 1064 |
|
|---|
| 1065 |
|
|---|
| 1066 |
/// |
|---|
| 1067 |
enum TextFormatFlags: uint |
|---|
| 1068 |
{ |
|---|
| 1069 |
_none, |
|---|
| 1070 |
} |
|---|
| 1071 |
|
|---|
| 1072 |
|
|---|
| 1073 |
/// |
|---|
| 1074 |
enum TextAlignment: uint |
|---|
| 1075 |
{ |
|---|
| 1076 |
_none, |
|---|
| 1077 |
} |
|---|
| 1078 |
|
|---|
| 1079 |
|
|---|
| 1080 |
/+ // To-do: ... |
|---|
| 1081 |
/// |
|---|
| 1082 |
class TextFormat |
|---|
| 1083 |
{ |
|---|
| 1084 |
/// |
|---|
| 1085 |
this() |
|---|
| 1086 |
{ |
|---|
| 1087 |
} |
|---|
| 1088 |
|
|---|
| 1089 |
/// ditto |
|---|
| 1090 |
this(TextFormat tf) |
|---|
| 1091 |
{ |
|---|
| 1092 |
_trim = tf._trim; |
|---|
| 1093 |
_flags = tf._flags; |
|---|
| 1094 |
_align = tf._align; |
|---|
| 1095 |
_params = tf._params; |
|---|
| 1096 |
} |
|---|
| 1097 |
|
|---|
| 1098 |
/// ditto |
|---|
| 1099 |
this(TextFormatFlags flags) |
|---|
| 1100 |
{ |
|---|
| 1101 |
_flags = flags; |
|---|
| 1102 |
} |
|---|
| 1103 |
|
|---|
| 1104 |
|
|---|
| 1105 |
/// |
|---|
| 1106 |
static TextFormat genericDefault() // getter |
|---|
| 1107 |
{ |
|---|
| 1108 |
TextFormat result; |
|---|
| 1109 |
result = new TextFormat; |
|---|
| 1110 |
result._trim = TextTrimming.NONE; |
|---|
| 1111 |
result._flags = TextFormatFlags.NO_PREFIX | TextFormatFlags.WORD_BREAK | |
|---|
| 1112 |
TextFormatFlags.NO_CLIP | TextFormatFlags.LINE_LIMIT; |
|---|
| 1113 |
return result; |
|---|
| 1114 |
} |
|---|
| 1115 |
|
|---|
| 1116 |
/// ditto |
|---|
| 1117 |
static TextFormat genericTypographic() // getter |
|---|
| 1118 |
{ |
|---|
| 1119 |
return new TextFormat; |
|---|
| 1120 |
} |
|---|
| 1121 |
|
|---|
| 1122 |
|
|---|
| 1123 |
/// |
|---|
| 1124 |
final void alignment(TextAlignment ta) // setter |
|---|
| 1125 |
{ |
|---|
| 1126 |
_align = ta; |
|---|
| 1127 |
} |
|---|
| 1128 |
|
|---|
| 1129 |
/// ditto |
|---|
| 1130 |
final TextAlignment alignment() // getter |
|---|
| 1131 |
{ |
|---|
| 1132 |
return _align; |
|---|
| 1133 |
} |
|---|
| 1134 |
|
|---|
| 1135 |
|
|---|
| 1136 |
/// |
|---|
| 1137 |
final void formatFlags(TextFormatFlags tff) // setter |
|---|
| 1138 |
{ |
|---|
| 1139 |
_flags = tff; |
|---|
| 1140 |
} |
|---|
| 1141 |
|
|---|
| 1142 |
/// ditto |
|---|
| 1143 |
final TextFormatFlags formatFlags() // getter |
|---|
| 1144 |
{ |
|---|
| 1145 |
return _flags; |
|---|
| 1146 |
} |
|---|
| 1147 |
|
|---|
| 1148 |
|
|---|
| 1149 |
/// |
|---|
| 1150 |
final void trimming(TextTrimming tt) // getter |
|---|
| 1151 |
{ |
|---|
| 1152 |
_trim = tt; |
|---|
| 1153 |
} |
|---|
| 1154 |
|
|---|
| 1155 |
/// ditto |
|---|
| 1156 |
final TextTrimming trimming() // getter |
|---|
| 1157 |
{ |
|---|
| 1158 |
return _trim; |
|---|
| 1159 |
} |
|---|
| 1160 |
|
|---|
| 1161 |
|
|---|
| 1162 |
// Units of the average character width. |
|---|
| 1163 |
|
|---|
| 1164 |
/// |
|---|
| 1165 |
final void tabLength(int tablen) // setter |
|---|
| 1166 |
{ |
|---|
| 1167 |
_params.iTabLength = tablen; |
|---|
| 1168 |
} |
|---|
| 1169 |
|
|---|
| 1170 |
/// ditto |
|---|
| 1171 |
final int tabLength() // getter |
|---|
| 1172 |
{ |
|---|
| 1173 |
return _params.iTabLength; |
|---|
| 1174 |
} |
|---|
| 1175 |
|
|---|
| 1176 |
|
|---|
| 1177 |
// Units of the average character width. |
|---|
| 1178 |
|
|---|
| 1179 |
/// |
|---|
| 1180 |
final void leftMargin(int sz) // setter |
|---|
| 1181 |
{ |
|---|
| 1182 |
_params.iLeftMargin = sz; |
|---|
| 1183 |
} |
|---|
| 1184 |
|
|---|
| 1185 |
/// ditto |
|---|
| 1186 |
final int leftMargin() // getter |
|---|
| 1187 |
{ |
|---|
| 1188 |
return _params.iLeftMargin; |
|---|
| 1189 |
} |
|---|
| 1190 |
|
|---|
| 1191 |
|
|---|
| 1192 |
// Units of the average character width. |
|---|
| 1193 |
|
|---|
| 1194 |
/// |
|---|
| 1195 |
final void rightMargin(int sz) // setter |
|---|
| 1196 |
{ |
|---|
| 1197 |
_params.iRightMargin = sz; |
|---|
| 1198 |
} |
|---|
| 1199 |
|
|---|
| 1200 |
/// ditto |
|---|
| 1201 |
final int rightMargin() // getter |
|---|
| 1202 |
{ |
|---|
| 1203 |
return _params.iRightMargin; |
|---|
| 1204 |
} |
|---|
| 1205 |
|
|---|
| 1206 |
|
|---|
| 1207 |
private: |
|---|
| 1208 |
TextTrimming _trim = TextTrimming.NONE; // TextTrimming.CHARACTER. |
|---|
| 1209 |
TextFormatFlags _flags = TextFormatFlags.NO_PREFIX | TextFormatFlags.WORD_BREAK; |
|---|
| 1210 |
TextAlignment _align = TextAlignment.LEFT; |
|---|
| 1211 |
package DRAWTEXTPARAMS _params = { DRAWTEXTPARAMS.sizeof, 8, 0, 0 }; |
|---|
| 1212 |
} |
|---|
| 1213 |
+/ |
|---|
| 1214 |
|
|---|
| 1215 |
|
|---|
| 1216 |
// To-do: ... |
|---|
| 1217 |
|
|---|
| 1218 |
/// |
|---|
| 1219 |
class Graphics // docmain |
|---|
| 1220 |
{ |
|---|
| 1221 |
// Used internally. |
|---|
| 1222 |
this(GdkGC* hdc, bool owned = true) |
|---|
| 1223 |
{ |
|---|
| 1224 |
this.hdc = hdc; |
|---|
| 1225 |
this.owned = owned; |
|---|
| 1226 |
} |
|---|
| 1227 |
|
|---|
| 1228 |
|
|---|
| 1229 |
~this() |
|---|
| 1230 |
{ |
|---|
| 1231 |
if(owned) |
|---|
| 1232 |
dispose(); |
|---|
| 1233 |
} |
|---|
| 1234 |
|
|---|
| 1235 |
|
|---|
| 1236 |
void fillRectangle(Color c, Rect r) |
|---|
| 1237 |
{ |
|---|
| 1238 |
// STUB |
|---|
| 1239 |
} |
|---|
| 1240 |
|
|---|
| 1241 |
|
|---|
| 1242 |
/// |
|---|
| 1243 |
final GdkGC* handle() // getter |
|---|
| 1244 |
{ |
|---|
| 1245 |
return hdc; |
|---|
| 1246 |
} |
|---|
| 1247 |
|
|---|
| 1248 |
|
|---|
| 1249 |
/// |
|---|
| 1250 |
void dispose() |
|---|
| 1251 |
{ |
|---|
| 1252 |
if(hdc) |
|---|
| 1253 |
{ |
|---|
| 1254 |
gdk_gc_unref(hdc); |
|---|
| 1255 |
hdc = null; |
|---|
| 1256 |
} |
|---|
| 1257 |
} |
|---|
| 1258 |
|
|---|
| 1259 |
|
|---|
| 1260 |
private: |
|---|
| 1261 |
GdkGC* hdc; |
|---|
| 1262 |
bool owned = true; |
|---|
| 1263 |
} |
|---|
| 1264 |
|
|---|
| 1265 |
|
|---|
| 1266 |
// To-do: ... |
|---|
| 1267 |
|
|---|
| 1268 |
|
|---|
| 1269 |
/// |
|---|
| 1270 |
class Font // docmain |
|---|
| 1271 |
{ |
|---|
| 1272 |
} |
|---|
| 1273 |
|
|---|
| 1274 |
|
|---|
| 1275 |
// To-do: ... |
|---|