1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module graphene.Rect; 26 27 private import glib.MemorySlice; 28 private import gobject.ObjectG; 29 private import graphene.Point; 30 private import graphene.Vec2; 31 private import graphene.c.functions; 32 public import graphene.c.types; 33 private import gtkd.Loader; 34 35 36 /** 37 * The location and size of a rectangle region. 38 * 39 * The width and height of a #graphene_rect_t can be negative; for instance, 40 * a #graphene_rect_t with an origin of [ 0, 0 ] and a size of [ 10, 10 ] is 41 * equivalent to a #graphene_rect_t with an origin of [ 10, 10 ] and a size 42 * of [ -10, -10 ]. 43 * 44 * Application code can normalize rectangles using graphene_rect_normalize(); 45 * this function will ensure that the width and height of a rectangle are 46 * positive values. All functions taking a #graphene_rect_t as an argument 47 * will internally operate on a normalized copy; all functions returning a 48 * #graphene_rect_t will always return a normalized rectangle. 49 * 50 * Since: 1.0 51 */ 52 public class Rect 53 { 54 /** the main Gtk struct */ 55 protected graphene_rect_t* graphene_rect; 56 protected bool ownedRef; 57 58 /** Get the main Gtk struct */ 59 public graphene_rect_t* getRectStruct(bool transferOwnership = false) 60 { 61 if (transferOwnership) 62 ownedRef = false; 63 return graphene_rect; 64 } 65 66 /** the main Gtk struct as a void* */ 67 protected void* getStruct() 68 { 69 return cast(void*)graphene_rect; 70 } 71 72 /** 73 * Sets our main struct and passes it to the parent class. 74 */ 75 public this (graphene_rect_t* graphene_rect, bool ownedRef = false) 76 { 77 this.graphene_rect = graphene_rect; 78 this.ownedRef = ownedRef; 79 } 80 81 ~this () 82 { 83 if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef ) 84 graphene_rect_free(graphene_rect); 85 } 86 87 88 /** */ 89 public static GType getType() 90 { 91 return graphene_rect_get_type(); 92 } 93 94 /** 95 * Checks whether a #graphene_rect_t contains the given coordinates. 96 * 97 * Params: 98 * p = a #graphene_point_t 99 * 100 * Returns: `true` if the rectangle contains the point 101 * 102 * Since: 1.0 103 */ 104 public bool containsPoint(Point p) 105 { 106 return graphene_rect_contains_point(graphene_rect, (p is null) ? null : p.getPointStruct()) != 0; 107 } 108 109 /** 110 * Checks whether a #graphene_rect_t fully contains the given 111 * rectangle. 112 * 113 * Params: 114 * b = a #graphene_rect_t 115 * 116 * Returns: `true` if the rectangle @a fully contains @b 117 * 118 * Since: 1.0 119 */ 120 public bool containsRect(Rect b) 121 { 122 return graphene_rect_contains_rect(graphene_rect, (b is null) ? null : b.getRectStruct()) != 0; 123 } 124 125 /** 126 * Checks whether the two given rectangle are equal. 127 * 128 * Params: 129 * b = a #graphene_rect_t 130 * 131 * Returns: `true` if the rectangles are equal 132 * 133 * Since: 1.0 134 */ 135 public bool equal(Rect b) 136 { 137 return graphene_rect_equal(graphene_rect, (b is null) ? null : b.getRectStruct()) != 0; 138 } 139 140 /** 141 * Expands a #graphene_rect_t to contain the given #graphene_point_t. 142 * 143 * Params: 144 * p = a #graphene_point_t 145 * res = return location for the expanded rectangle 146 * 147 * Since: 1.4 148 */ 149 public void expand(Point p, out Rect res) 150 { 151 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 152 153 graphene_rect_expand(graphene_rect, (p is null) ? null : p.getPointStruct(), outres); 154 155 res = ObjectG.getDObject!(Rect)(outres, true); 156 } 157 158 /** 159 * Frees the resources allocated by graphene_rect_alloc(). 160 * 161 * Since: 1.0 162 */ 163 public void free() 164 { 165 graphene_rect_free(graphene_rect); 166 ownedRef = false; 167 } 168 169 /** 170 * Compute the area of given normalized rectangle. 171 * 172 * Returns: the area of the normalized rectangle 173 * 174 * Since: 1.10 175 */ 176 public float getArea() 177 { 178 return graphene_rect_get_area(graphene_rect); 179 } 180 181 /** 182 * Retrieves the coordinates of the bottom-left corner of the given rectangle. 183 * 184 * Params: 185 * p = return location for a #graphene_point_t 186 * 187 * Since: 1.0 188 */ 189 public void getBottomLeft(out Point p) 190 { 191 graphene_point_t* outp = sliceNew!graphene_point_t(); 192 193 graphene_rect_get_bottom_left(graphene_rect, outp); 194 195 p = ObjectG.getDObject!(Point)(outp, true); 196 } 197 198 /** 199 * Retrieves the coordinates of the bottom-right corner of the given rectangle. 200 * 201 * Params: 202 * p = return location for a #graphene_point_t 203 * 204 * Since: 1.0 205 */ 206 public void getBottomRight(out Point p) 207 { 208 graphene_point_t* outp = sliceNew!graphene_point_t(); 209 210 graphene_rect_get_bottom_right(graphene_rect, outp); 211 212 p = ObjectG.getDObject!(Point)(outp, true); 213 } 214 215 /** 216 * Retrieves the coordinates of the center of the given rectangle. 217 * 218 * Params: 219 * p = return location for a #graphene_point_t 220 * 221 * Since: 1.0 222 */ 223 public void getCenter(out Point p) 224 { 225 graphene_point_t* outp = sliceNew!graphene_point_t(); 226 227 graphene_rect_get_center(graphene_rect, outp); 228 229 p = ObjectG.getDObject!(Point)(outp, true); 230 } 231 232 /** 233 * Retrieves the normalized height of the given rectangle. 234 * 235 * Returns: the normalized height of the rectangle 236 * 237 * Since: 1.0 238 */ 239 public float getHeight() 240 { 241 return graphene_rect_get_height(graphene_rect); 242 } 243 244 /** 245 * Retrieves the coordinates of the top-left corner of the given rectangle. 246 * 247 * Params: 248 * p = return location for a #graphene_point_t 249 * 250 * Since: 1.0 251 */ 252 public void getTopLeft(out Point p) 253 { 254 graphene_point_t* outp = sliceNew!graphene_point_t(); 255 256 graphene_rect_get_top_left(graphene_rect, outp); 257 258 p = ObjectG.getDObject!(Point)(outp, true); 259 } 260 261 /** 262 * Retrieves the coordinates of the top-right corner of the given rectangle. 263 * 264 * Params: 265 * p = return location for a #graphene_point_t 266 * 267 * Since: 1.0 268 */ 269 public void getTopRight(out Point p) 270 { 271 graphene_point_t* outp = sliceNew!graphene_point_t(); 272 273 graphene_rect_get_top_right(graphene_rect, outp); 274 275 p = ObjectG.getDObject!(Point)(outp, true); 276 } 277 278 /** 279 * Computes the four vertices of a #graphene_rect_t. 280 * 281 * Params: 282 * vertices = return location for an array 283 * of 4 #graphene_vec2_t 284 * 285 * Since: 1.4 286 */ 287 public void getVertices(out Vec2[4] vertices) 288 { 289 graphene_vec2_t* outvertices = cast(graphene_vec2_t*)sliceAlloc0(graphene_vec2_t.sizeof * 4); 290 291 graphene_rect_get_vertices(graphene_rect, outvertices); 292 293 for(size_t i = 0; i < 4; i++) 294 { 295 vertices[i] = ObjectG.getDObject!(Vec2)(cast(graphene_vec2_t*) &outvertices[i]); 296 } 297 } 298 299 /** 300 * Retrieves the normalized width of the given rectangle. 301 * 302 * Returns: the normalized width of the rectangle 303 * 304 * Since: 1.0 305 */ 306 public float getWidth() 307 { 308 return graphene_rect_get_width(graphene_rect); 309 } 310 311 /** 312 * Retrieves the normalized X coordinate of the origin of the given 313 * rectangle. 314 * 315 * Returns: the normalized X coordinate of the rectangle 316 * 317 * Since: 1.0 318 */ 319 public float getX() 320 { 321 return graphene_rect_get_x(graphene_rect); 322 } 323 324 /** 325 * Retrieves the normalized Y coordinate of the origin of the given 326 * rectangle. 327 * 328 * Returns: the normalized Y coordinate of the rectangle 329 * 330 * Since: 1.0 331 */ 332 public float getY() 333 { 334 return graphene_rect_get_y(graphene_rect); 335 } 336 337 /** 338 * Initializes the given #graphene_rect_t with the given values. 339 * 340 * This function will implicitly normalize the #graphene_rect_t 341 * before returning. 342 * 343 * Params: 344 * x = the X coordinate of the @graphene_rect_t.origin 345 * y = the Y coordinate of the @graphene_rect_t.origin 346 * width = the width of the @graphene_rect_t.size 347 * height = the height of the @graphene_rect_t.size 348 * 349 * Returns: the initialized rectangle 350 * 351 * Since: 1.0 352 */ 353 public Rect init(float x, float y, float width, float height) 354 { 355 auto __p = graphene_rect_init(graphene_rect, x, y, width, height); 356 357 if(__p is null) 358 { 359 return null; 360 } 361 362 return ObjectG.getDObject!(Rect)(cast(graphene_rect_t*) __p); 363 } 364 365 /** 366 * Initializes @r using the given @src rectangle. 367 * 368 * This function will implicitly normalize the #graphene_rect_t 369 * before returning. 370 * 371 * Params: 372 * src = a #graphene_rect_t 373 * 374 * Returns: the initialized rectangle 375 * 376 * Since: 1.0 377 */ 378 public Rect initFromRect(Rect src) 379 { 380 auto __p = graphene_rect_init_from_rect(graphene_rect, (src is null) ? null : src.getRectStruct()); 381 382 if(__p is null) 383 { 384 return null; 385 } 386 387 return ObjectG.getDObject!(Rect)(cast(graphene_rect_t*) __p); 388 } 389 390 /** 391 * Changes the given rectangle to be smaller, or larger depending on the 392 * given inset parameters. 393 * 394 * To create an inset rectangle, use positive @d_x or @d_y values; to 395 * create a larger, encompassing rectangle, use negative @d_x or @d_y 396 * values. 397 * 398 * The origin of the rectangle is offset by @d_x and @d_y, while the size 399 * is adjusted by `(2 * @d_x, 2 * @d_y)`. If @d_x and @d_y are positive 400 * values, the size of the rectangle is decreased; if @d_x and @d_y are 401 * negative values, the size of the rectangle is increased. 402 * 403 * If the size of the resulting inset rectangle has a negative width or 404 * height then the size will be set to zero. 405 * 406 * Params: 407 * dX = the horizontal inset 408 * dY = the vertical inset 409 * 410 * Returns: the inset rectangle 411 * 412 * Since: 1.0 413 */ 414 public Rect inset(float dX, float dY) 415 { 416 auto __p = graphene_rect_inset(graphene_rect, dX, dY); 417 418 if(__p is null) 419 { 420 return null; 421 } 422 423 return ObjectG.getDObject!(Rect)(cast(graphene_rect_t*) __p); 424 } 425 426 /** 427 * Changes the given rectangle to be smaller, or larger depending on the 428 * given inset parameters. 429 * 430 * To create an inset rectangle, use positive @d_x or @d_y values; to 431 * create a larger, encompassing rectangle, use negative @d_x or @d_y 432 * values. 433 * 434 * The origin of the rectangle is offset by @d_x and @d_y, while the size 435 * is adjusted by `(2 * @d_x, 2 * @d_y)`. If @d_x and @d_y are positive 436 * values, the size of the rectangle is decreased; if @d_x and @d_y are 437 * negative values, the size of the rectangle is increased. 438 * 439 * If the size of the resulting inset rectangle has a negative width or 440 * height then the size will be set to zero. 441 * 442 * Params: 443 * dX = the horizontal inset 444 * dY = the vertical inset 445 * res = return location for the inset rectangle 446 * 447 * Since: 1.4 448 */ 449 public void insetR(float dX, float dY, out Rect res) 450 { 451 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 452 453 graphene_rect_inset_r(graphene_rect, dX, dY, outres); 454 455 res = ObjectG.getDObject!(Rect)(outres, true); 456 } 457 458 /** 459 * Linearly interpolates the origin and size of the two given 460 * rectangles. 461 * 462 * Params: 463 * b = a #graphene_rect_t 464 * factor = the linear interpolation factor 465 * res = return location for the 466 * interpolated rectangle 467 * 468 * Since: 1.0 469 */ 470 public void interpolate(Rect b, double factor, out Rect res) 471 { 472 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 473 474 graphene_rect_interpolate(graphene_rect, (b is null) ? null : b.getRectStruct(), factor, outres); 475 476 res = ObjectG.getDObject!(Rect)(outres, true); 477 } 478 479 /** 480 * Computes the intersection of the two given rectangles. 481 * 482 * ![](rectangle-intersection.png) 483 * 484 * The intersection in the image above is the blue outline. 485 * 486 * If the two rectangles do not intersect, @res will contain 487 * a degenerate rectangle with origin in (0, 0) and a size of 0. 488 * 489 * Params: 490 * b = a #graphene_rect_t 491 * res = return location for 492 * a #graphene_rect_t 493 * 494 * Returns: `true` if the two rectangles intersect 495 * 496 * Since: 1.0 497 */ 498 public bool intersection(Rect b, out Rect res) 499 { 500 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 501 502 auto __p = graphene_rect_intersection(graphene_rect, (b is null) ? null : b.getRectStruct(), outres) != 0; 503 504 res = ObjectG.getDObject!(Rect)(outres, true); 505 506 return __p; 507 } 508 509 /** 510 * Normalizes the passed rectangle. 511 * 512 * This function ensures that the size of the rectangle is made of 513 * positive values, and that the origin is the top-left corner of 514 * the rectangle. 515 * 516 * Returns: the normalized rectangle 517 * 518 * Since: 1.0 519 */ 520 public Rect normalize() 521 { 522 auto __p = graphene_rect_normalize(graphene_rect); 523 524 if(__p is null) 525 { 526 return null; 527 } 528 529 return ObjectG.getDObject!(Rect)(cast(graphene_rect_t*) __p); 530 } 531 532 /** 533 * Normalizes the passed rectangle. 534 * 535 * This function ensures that the size of the rectangle is made of 536 * positive values, and that the origin is in the top-left corner 537 * of the rectangle. 538 * 539 * Params: 540 * res = the return location for the 541 * normalized rectangle 542 * 543 * Since: 1.4 544 */ 545 public void normalizeR(out Rect res) 546 { 547 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 548 549 graphene_rect_normalize_r(graphene_rect, outres); 550 551 res = ObjectG.getDObject!(Rect)(outres, true); 552 } 553 554 /** 555 * Offsets the origin by @d_x and @d_y. 556 * 557 * The size of the rectangle is unchanged. 558 * 559 * Params: 560 * dX = the horizontal offset 561 * dY = the vertical offset 562 * 563 * Returns: the offset rectangle 564 * 565 * Since: 1.0 566 */ 567 public Rect offset(float dX, float dY) 568 { 569 auto __p = graphene_rect_offset(graphene_rect, dX, dY); 570 571 if(__p is null) 572 { 573 return null; 574 } 575 576 return ObjectG.getDObject!(Rect)(cast(graphene_rect_t*) __p); 577 } 578 579 /** 580 * Offsets the origin of the given rectangle by @d_x and @d_y. 581 * 582 * The size of the rectangle is left unchanged. 583 * 584 * Params: 585 * dX = the horizontal offset 586 * dY = the vertical offset 587 * res = return location for the offset 588 * rectangle 589 * 590 * Since: 1.4 591 */ 592 public void offsetR(float dX, float dY, out Rect res) 593 { 594 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 595 596 graphene_rect_offset_r(graphene_rect, dX, dY, outres); 597 598 res = ObjectG.getDObject!(Rect)(outres, true); 599 } 600 601 /** 602 * Rounds the origin and size of the given rectangle to 603 * their nearest integer values; the rounding is guaranteed 604 * to be large enough to have an area bigger or equal to the 605 * original rectangle, but might not fully contain its extents. 606 * Use graphene_rect_round_extents() in case you need to round 607 * to a rectangle that covers fully the original one. 608 * 609 * This function is the equivalent of calling `floor` on 610 * the coordinates of the origin, and `ceil` on the size. 611 * 612 * Deprecated: Use graphene_rect_round_extents() instead 613 * 614 * Params: 615 * res = return location for the 616 * rounded rectangle 617 * 618 * Since: 1.4 619 */ 620 public void round(out Rect res) 621 { 622 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 623 624 graphene_rect_round(graphene_rect, outres); 625 626 res = ObjectG.getDObject!(Rect)(outres, true); 627 } 628 629 /** 630 * Rounds the origin of the given rectangle to its nearest 631 * integer value and and recompute the size so that the 632 * rectangle is large enough to contain all the conrners 633 * of the original rectangle. 634 * 635 * This function is the equivalent of calling `floor` on 636 * the coordinates of the origin, and recomputing the size 637 * calling `ceil` on the bottom-right coordinates. 638 * 639 * If you want to be sure that the rounded rectangle 640 * completely covers the area that was covered by the 641 * original rectangle — i.e. you want to cover the area 642 * including all its corners — this function will make sure 643 * that the size is recomputed taking into account the ceiling 644 * of the coordinates of the bottom-right corner. 645 * If the difference between the original coordinates and the 646 * coordinates of the rounded rectangle is greater than the 647 * difference between the original size and and the rounded 648 * size, then the move of the origin would not be compensated 649 * by a move in the anti-origin, leaving the corners of the 650 * original rectangle outside the rounded one. 651 * 652 * Params: 653 * res = return location for the 654 * rectangle with rounded extents 655 * 656 * Since: 1.10 657 */ 658 public void roundExtents(out Rect res) 659 { 660 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 661 662 graphene_rect_round_extents(graphene_rect, outres); 663 664 res = ObjectG.getDObject!(Rect)(outres, true); 665 } 666 667 /** 668 * Rounds the origin and the size of the given rectangle to 669 * their nearest integer values; the rounding is guaranteed 670 * to be large enough to contain the original rectangle. 671 * 672 * Deprecated: Use graphene_rect_round() instead 673 * 674 * Returns: the pixel-aligned rectangle. 675 * 676 * Since: 1.0 677 */ 678 public Rect roundToPixel() 679 { 680 auto __p = graphene_rect_round_to_pixel(graphene_rect); 681 682 if(__p is null) 683 { 684 return null; 685 } 686 687 return ObjectG.getDObject!(Rect)(cast(graphene_rect_t*) __p); 688 } 689 690 /** 691 * Scales the size and origin of a rectangle horizontaly by @s_h, 692 * and vertically by @s_v. The result @res is normalized. 693 * 694 * Params: 695 * sH = horizontal scale factor 696 * sV = vertical scale factor 697 * res = return location for the 698 * scaled rectangle 699 * 700 * Since: 1.10 701 */ 702 public void scale(float sH, float sV, out Rect res) 703 { 704 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 705 706 graphene_rect_scale(graphene_rect, sH, sV, outres); 707 708 res = ObjectG.getDObject!(Rect)(outres, true); 709 } 710 711 alias unio = union_; 712 /** 713 * Computes the union of the two given rectangles. 714 * 715 * ![](rectangle-union.png) 716 * 717 * The union in the image above is the blue outline. 718 * 719 * Params: 720 * b = a #graphene_rect_t 721 * res = return location for a #graphene_rect_t 722 * 723 * Since: 1.0 724 */ 725 public void union_(Rect b, out Rect res) 726 { 727 graphene_rect_t* outres = sliceNew!graphene_rect_t(); 728 729 graphene_rect_union(graphene_rect, (b is null) ? null : b.getRectStruct(), outres); 730 731 res = ObjectG.getDObject!(Rect)(outres, true); 732 } 733 734 /** 735 * Allocates a new #graphene_rect_t. 736 * 737 * The contents of the returned rectangle are undefined. 738 * 739 * Returns: the newly allocated rectangle 740 * 741 * Since: 1.0 742 */ 743 public static Rect alloc() 744 { 745 auto __p = graphene_rect_alloc(); 746 747 if(__p is null) 748 { 749 return null; 750 } 751 752 return ObjectG.getDObject!(Rect)(cast(graphene_rect_t*) __p, true); 753 } 754 755 /** 756 * Returns a degenerate rectangle with origin fixed at (0, 0) and 757 * a size of 0, 0. 758 * 759 * Returns: a fixed rectangle 760 * 761 * Since: 1.4 762 */ 763 public static Rect zero() 764 { 765 auto __p = graphene_rect_zero(); 766 767 if(__p is null) 768 { 769 return null; 770 } 771 772 return ObjectG.getDObject!(Rect)(cast(graphene_rect_t*) __p); 773 } 774 }