Module: SugarCube::CoreGraphics
- Defined in:
- lib/sugarcube/core_graphics.rb
Defined Under Namespace
Classes: EdgeInsets, Offset, Point, Rect, Size
Constant Summary collapse
- PI =
3.141592654
- PHI =
1.618033989
- E =
2.718281828
Class Method Summary collapse
-
.EdgeInsets(top_or_inset, left = nil, bottom = nil, right = nil) ⇒ Object
Accepts 1 or 4 arguments.
-
.Offset(horizontal_or_offset, vertical = nil) ⇒ Object
Accepts 1 or 2 arguments.
- .Point(x_or_origin, y = nil) ⇒ Object
-
.Rect(x_or_origin, y_or_size = nil, w = nil, h = nil) ⇒ Object
Accepts 1, 2 or 4 arguments.
- .Size(w_or_size, h = nil) ⇒ Object
Class Method Details
.EdgeInsets(top_or_inset, left = nil, bottom = nil, right = nil) ⇒ Object
Accepts 1 or 4 arguments. 1 argument should be an Array or UIEdgeInset, 4 should be top, left, bottom, right
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/sugarcube/core_graphics.rb', line 493 def EdgeInsets(top_or_inset, left=nil, bottom=nil, right=nil) unless left or bottom or right case top_or_inset when UIEdgeInsets top = top.top left = top.left bottom = top.bottom right = top.right when Array top = top_or_inset[0] left = top_or_inset[1] bottom = top_or_inset[2] right = top_or_inset[3] when Numeric top = left = bottom = right = top_or_inset else raise RuntimeError.new("Invalid argument sent to EdgeInsets(#{top_or_inset.inspect})") end else top = top_or_inset end return EdgeInsets.new([top, left, bottom, right]) end |
.Offset(horizontal_or_offset, vertical = nil) ⇒ Object
Accepts 1 or 2 arguments. 1 argument should be an Array or UIOffset, 2 should be horizontal, vertical
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/sugarcube/core_graphics.rb', line 520 def Offset(horizontal_or_offset, vertical=nil) if not vertical case horizontal_or_offset when UIOffset horizontal = horizontal_or_offset.horizontal vertical = horizontal_or_offset.vertical when Array horizontal = horizontal_or_offset[0] vertical = horizontal_or_offset[1] when Fixnum horizontal_or_offset = vertical = horizontal_or_offset[0] else raise RuntimeError.new("Invalid argument sent to Offset(#{horizontal_or_offset.inspect})") end else horizontal = horizontal_or_offset end return Offset.new([horizontal, vertical]) end |
.Point(x_or_origin, y = nil) ⇒ Object
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/sugarcube/core_graphics.rb', line 419 def Point(x_or_origin, y=nil) if not y case x_or_origin when CGPoint x = x_or_origin.x y = x_or_origin.y when Array x = x_or_origin[0] y = x_or_origin[1] else raise RuntimeError.new("Invalid argument sent to Point(#{x_or_origin.inspect})") end else x = x_or_origin end return Point.new([x, y]) end |
.Rect(x_or_origin, y_or_size = nil, w = nil, h = nil) ⇒ Object
Accepts 1, 2 or 4 arguments. 1 argument should be an Array, Rect, or CGRect 2 arguments should be a Point/CGPoint and a Size/CGSize, 4 should be x, y, w, h
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 |
# File 'lib/sugarcube/core_graphics.rb', line 441 def Rect(x_or_origin, y_or_size=nil, w=nil, h=nil) if not y_or_size case x_or_origin when CGRect x = x_or_origin.origin.x y = x_or_origin.origin.y w = x_or_origin.size.width h = x_or_origin.size.height when UIView, CALayer x = x_or_origin.frame.origin.x y = x_or_origin.frame.origin.y w = x_or_origin.frame.size.width h = x_or_origin.frame.size.height when Rect x = x_or_origin[0][0] y = x_or_origin[0][1] w = x_or_origin[1][0] h = x_or_origin[1][1] when Array if x_or_origin.length == 2 x = x_or_origin[0][0] y = x_or_origin[0][1] w = x_or_origin[1][0] h = x_or_origin[1][1] elsif x = x_or_origin[0] y = x_or_origin[1] w = x_or_origin[2] h = x_or_origin[3] else raise RuntimeError.new("Invalid argument sent to Rect(#{x_or_origin.inspect})") end else raise RuntimeError.new("Invalid argument sent to Rect(#{x_or_origin.inspect})") end elsif not w and not h x_or_origin = Point(x_or_origin) unless x_or_origin.is_a? Point x = x_or_origin.x y = x_or_origin.y y_or_size = Size(y_or_size) unless y_or_size.is_a? Size w = y_or_size.width h = y_or_size.height else x = x_or_origin y = y_or_size end return Rect.new([[x, y], [w, h]]) end |
.Size(w_or_size, h = nil) ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/sugarcube/core_graphics.rb', line 401 def Size(w_or_size, h=nil) if not h case w_or_size when CGSize w = w_or_size.width h = w_or_size.height when Array w = w_or_size[0] h = w_or_size[1] else raise RuntimeError.new("Invalid argument sent to Size(#{w_or_size.inspect})") end else w = w_or_size end return Size.new([w, h]) end |