Class: Fzeet::Windows::RECT

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/fzeet/windows/core/Rect.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](*args) ⇒ Object Also known as: from



12
13
14
15
16
17
18
19
20
# File 'lib/fzeet/windows/core/Rect.rb', line 12

def self.[](*args)
	case args.length
	when 2 # location, size
		new.set(args[0][:x], args[0][:y], args[0][:x] + args[1][:cx], args[0][:y] + args[1][:cy])
	when 4 # left, top, right, bottom
		new.set(*args)
	else raise ArgumentError
	end
end

Instance Method Details

#&(other) ⇒ Object



94
# File 'lib/fzeet/windows/core/Rect.rb', line 94

def &(other) self.class.new.tap { |r| Windows.IntersectRect(r, self, other) } end

#-(other) ⇒ Object



95
# File 'lib/fzeet/windows/core/Rect.rb', line 95

def -(other) self.class.new.tap { |r| Windows.SubtractRect(r, self, other) } end

#==(other) ⇒ Object



61
# File 'lib/fzeet/windows/core/Rect.rb', line 61

def ==(other) Windows.EqualRect(self, other) != 0 end

#clearObject



34
# File 'lib/fzeet/windows/core/Rect.rb', line 34

def clear; set(0, 0, 0, 0) end

#dupObject



27
# File 'lib/fzeet/windows/core/Rect.rb', line 27

def dup; self.class[self[:left], self[:top], self[:right], self[:bottom]] end

#empty?Boolean

Returns:

  • (Boolean)


62
# File 'lib/fzeet/windows/core/Rect.rb', line 62

def empty?; Windows.IsRectEmpty(self) != 0 end

#exclude?(arg) ⇒ Boolean

Returns:

  • (Boolean)


74
# File 'lib/fzeet/windows/core/Rect.rb', line 74

def exclude?(arg) !include?(arg) end

#getObject Also known as: to_a



29
# File 'lib/fzeet/windows/core/Rect.rb', line 29

def get; [self[:left], self[:top], self[:right], self[:bottom]] end

#heightObject



53
# File 'lib/fzeet/windows/core/Rect.rb', line 53

def height; self[:bottom] - self[:top] end

#height=(height) ⇒ Object



54
# File 'lib/fzeet/windows/core/Rect.rb', line 54

def height=(height) self[:bottom] = self[:top] + height end

#include?(*args) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
# File 'lib/fzeet/windows/core/Rect.rb', line 64

def include?(*args)
	return args.all? { |arg| include?(arg) } if args.length > 1

	case args[0]
	when POINT; Windows.PtInRect(self, args[0]) != 0
	when RECT; [args[0].lt, args[0].lb, args[0].rt, args[0].rb].all? { |pt| include?(pt) }
	else raise ArgumentError
	end
end

#inflate(dx, dy) ⇒ Object



90
# File 'lib/fzeet/windows/core/Rect.rb', line 90

def inflate(dx, dy) dup.inflate!(dx, dy) end

#inflate!(dx, dy) ⇒ Object



91
# File 'lib/fzeet/windows/core/Rect.rb', line 91

def inflate!(dx, dy) tap { |r| Windows.Detonate(0, :InflateRect, r, dx, dy) } end

#lbObject



41
# File 'lib/fzeet/windows/core/Rect.rb', line 41

def lb; POINT[self[:left], self[:bottom]] end

#lb=(pt) ⇒ Object



42
# File 'lib/fzeet/windows/core/Rect.rb', line 42

def lb=(pt) self[:left], self[:bottom] = pt[:x], pt[:y] end

#ltObject Also known as: location



36
# File 'lib/fzeet/windows/core/Rect.rb', line 36

def lt; POINT[self[:left], self[:top]] end

#lt=(pt) ⇒ Object Also known as: location=



37
# File 'lib/fzeet/windows/core/Rect.rb', line 37

def lt=(pt) self[:left], self[:top] = pt[:x], pt[:y] end

#normalizeObject



78
# File 'lib/fzeet/windows/core/Rect.rb', line 78

def normalize; dup.normalize! end

#normalize!Object



80
81
82
83
84
85
# File 'lib/fzeet/windows/core/Rect.rb', line 80

def normalize!
	self[:left], self[:right] = self[:right], self[:left] if self[:left] > self[:right]
	self[:top], self[:bottom] = self[:bottom], self[:top] if self[:top] > self[:bottom]

	self
end

#normalized?Boolean

Returns:

  • (Boolean)


76
# File 'lib/fzeet/windows/core/Rect.rb', line 76

def normalized?; self[:left] <= self[:right] && self[:top] <= self[:bottom] end

#offset(dx, dy) ⇒ Object



87
# File 'lib/fzeet/windows/core/Rect.rb', line 87

def offset(dx, dy) dup.offset!(dx, dy) end

#offset!(dx, dy) ⇒ Object



88
# File 'lib/fzeet/windows/core/Rect.rb', line 88

def offset!(dx, dy) tap { |r| Windows.Detonate(0, :OffsetRect, r, dx, dy) } end

#rbObject



47
# File 'lib/fzeet/windows/core/Rect.rb', line 47

def rb; POINT[self[:right], self[:bottom]] end

#rb=(pt) ⇒ Object



48
# File 'lib/fzeet/windows/core/Rect.rb', line 48

def rb=(pt) self[:right], self[:bottom] = pt[:x], pt[:y] end

#rtObject



44
# File 'lib/fzeet/windows/core/Rect.rb', line 44

def rt; POINT[self[:right], self[:top]] end

#rt=(pt) ⇒ Object



45
# File 'lib/fzeet/windows/core/Rect.rb', line 45

def rt=(pt) self[:right], self[:top] = pt[:x], pt[:y] end

#set(l, t, r, b) ⇒ Object



32
# File 'lib/fzeet/windows/core/Rect.rb', line 32

def set(l, t, r, b) tap { |rect| rect[:left], rect[:top], rect[:right], rect[:bottom] = l, t, r, b } end

#sizeObject



58
# File 'lib/fzeet/windows/core/Rect.rb', line 58

def size; SIZE[width, height] end

#size=(s) ⇒ Object



59
# File 'lib/fzeet/windows/core/Rect.rb', line 59

def size=(s) self.width, self.height = s[:cx], s[:cy] end

#structSizeObject



56
# File 'lib/fzeet/windows/core/Rect.rb', line 56

alias structSize size

#widthObject



50
# File 'lib/fzeet/windows/core/Rect.rb', line 50

def width; self[:right] - self[:left] end

#width=(width) ⇒ Object



51
# File 'lib/fzeet/windows/core/Rect.rb', line 51

def width=(width) self[:right] = self[:left] + width end

#|(other) ⇒ Object



93
# File 'lib/fzeet/windows/core/Rect.rb', line 93

def |(other) self.class.new.tap { |r| Windows.UnionRect(r, self, other) } end