Class: Hokusai::Util::Selection

Inherits:
Object
  • Object
show all
Defined in:
ui/src/hokusai/util/selection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSelection

Returns a new instance of Selection.



6
7
8
9
10
11
12
# File 'ui/src/hokusai/util/selection.rb', line 6

def initialize
  ptr = FFI::MemoryPointer.new :pointer
  LibHokusai.hoku_selection_init(ptr)
  @raw = LibHokusai::HokuSelection.new(ptr.get_pointer(0))
  ptr.free
  @started = false
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



3
4
5
# File 'ui/src/hokusai/util/selection.rb', line 3

def raw
  @raw
end

#startedObject

Returns the value of attribute started.



4
5
6
# File 'ui/src/hokusai/util/selection.rb', line 4

def started
  @started
end

Instance Method Details

#activate!Object



44
45
46
# File 'ui/src/hokusai/util/selection.rb', line 44

def activate!
  raw[:type] = :active
end

#active?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'ui/src/hokusai/util/selection.rb', line 36

def active?
  type == :active
end

#clearObject



26
27
28
29
30
31
32
33
34
# File 'ui/src/hokusai/util/selection.rb', line 26

def clear
  raw[:start_x] = 0.0
  raw[:stop_x] = 0.0
  raw[:start_y] = 0.0
  raw[:stop_y] = 0.0
  raw[:cursor] = nil

  activate!
end

#coordsObject



52
53
54
# File 'ui/src/hokusai/util/selection.rb', line 52

def coords
  [start_x, stop_x, start_y, stop_y]
end

#cursorObject



125
126
127
128
129
130
131
132
133
# File 'ui/src/hokusai/util/selection.rb', line 125

def cursor
  return nil if raw[:cursor].null?

  if frozen?
    return [raw[:cursor][:x], raw[:cursor][:y] - offset_y, raw[:cursor][:w], raw[:cursor][:h]]
  end

  [raw[:cursor][:x], raw[:cursor][:y], raw[:cursor][:w], raw[:cursor][:h]]
end

#cursor=(position) ⇒ Object

Raises:



112
113
114
115
116
117
118
119
120
121
122
123
# File 'ui/src/hokusai/util/selection.rb', line 112

def cursor=(position)
  if position.nil?
    LibHokusai.hoku_selection_cursor_free(raw)
    return
  end

  pos = LibHokusai::HokuCursorPosition.create(position)

  ret = LibHokusai.hoku_selection_cursor_set(raw, pos)

  raise Hokusai::Error.new("Could not set cursor") if !ret.zero?
end

#down?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'ui/src/hokusai/util/selection.rb', line 100

def down?
  start_y <= stop_y
end

#freeze!Object



48
49
50
# File 'ui/src/hokusai/util/selection.rb', line 48

def freeze!
  raw[:type] = :frozen
end

#frozen?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'ui/src/hokusai/util/selection.rb', line 40

def frozen?
  type == :frozen
end

#left?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'ui/src/hokusai/util/selection.rb', line 104

def left?
  stop_x < start_x
end

#none?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'ui/src/hokusai/util/selection.rb', line 18

def none?
  type == :none
end

#offset_yObject



60
61
62
# File 'ui/src/hokusai/util/selection.rb', line 60

def offset_y
  raw[:offset_y]
end

#offset_y=(val) ⇒ Object



56
57
58
# File 'ui/src/hokusai/util/selection.rb', line 56

def offset_y=(val)
  raw[:offset_y] = val
end

#ready?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'ui/src/hokusai/util/selection.rb', line 22

def ready?
  type == :none || type == :frozen
end

#rect_selected(rect) ⇒ Object



135
136
137
# File 'ui/src/hokusai/util/selection.rb', line 135

def rect_selected(rect)
  selected(rect[0], rect[1], rect[2], rect[3])
end

#right?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'ui/src/hokusai/util/selection.rb', line 108

def right?
  start_x <= stop_x
end

#selected(x, y, width, height) ⇒ Object



139
140
141
142
143
# File 'ui/src/hokusai/util/selection.rb', line 139

def selected(x, y, width, height)
  return false if none?

  LibHokusai.hoku_selection_selected(raw, x, y, width, height)
end

#start(x, y) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'ui/src/hokusai/util/selection.rb', line 64

def start(x, y)
  raw[:start_x] = x
  raw[:start_y] = y
  raw[:stop_x] = x
  raw[:stop_y] = y

  raw[:cursor] = nil

  activate!
end

#start_xObject



80
81
82
# File 'ui/src/hokusai/util/selection.rb', line 80

def start_x
  raw[:start_x]
end

#start_yObject



92
93
94
# File 'ui/src/hokusai/util/selection.rb', line 92

def start_y
  raw[:start_y]
end

#stop(x, y) ⇒ Object



75
76
77
78
# File 'ui/src/hokusai/util/selection.rb', line 75

def stop(x, y)
  raw[:stop_x] = x
  raw[:stop_y] = y
end

#stop_xObject



84
85
86
# File 'ui/src/hokusai/util/selection.rb', line 84

def stop_x
  raw[:stop_x]
end

#stop_yObject



88
89
90
# File 'ui/src/hokusai/util/selection.rb', line 88

def stop_y
  raw[:stop_y]
end

#typeObject



14
15
16
# File 'ui/src/hokusai/util/selection.rb', line 14

def type
  raw[:type]
end

#up?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'ui/src/hokusai/util/selection.rb', line 96

def up?
  stop_y < start_y
end