autocad 0.4.6 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop/minitest.yml +2 -2
  3. data/.rubocop/strict.yml +4 -4
  4. data/.rubocop.yml +36 -33
  5. data/CHANGELOG.md +5 -5
  6. data/LICENSE.txt +21 -21
  7. data/README.md +134 -39
  8. data/Rakefile +26 -10
  9. data/exe/autocad +3 -3
  10. data/gemfiles/rubocop.gemfile +2 -1
  11. data/lib/autocad/app.rb +127 -28
  12. data/lib/autocad/arc.rb +3 -0
  13. data/lib/autocad/block.rb +11 -6
  14. data/lib/autocad/block_reference.rb +33 -4
  15. data/lib/autocad/bounding_box.rb +202 -0
  16. data/lib/autocad/dim_style.rb +4 -0
  17. data/lib/autocad/drawing.rb +873 -172
  18. data/lib/autocad/element.rb +217 -25
  19. data/lib/autocad/errors.rb +9 -0
  20. data/lib/autocad/filter.rb +502 -168
  21. data/lib/autocad/layer.rb +129 -41
  22. data/lib/autocad/layout.rb +120 -0
  23. data/lib/autocad/line.rb +154 -55
  24. data/lib/autocad/message_box.rb +95 -95
  25. data/lib/autocad/model.rb +217 -89
  26. data/lib/autocad/mtext.rb +189 -110
  27. data/lib/autocad/plot.rb +45 -0
  28. data/lib/autocad/plot_configuration.rb +372 -0
  29. data/lib/autocad/point.rb +7 -0
  30. data/lib/autocad/point3d.rb +18 -11
  31. data/lib/autocad/pviewport.rb +136 -21
  32. data/lib/autocad/selection_filter.rb +358 -180
  33. data/lib/autocad/selection_set.rb +140 -61
  34. data/lib/autocad/selection_set_adapter.rb +187 -8
  35. data/lib/autocad/spline.rb +27 -0
  36. data/lib/autocad/text.rb +66 -11
  37. data/lib/autocad/text_style.rb +4 -0
  38. data/lib/autocad/version.rb +1 -1
  39. data/lib/autocad/viewport.rb +57 -0
  40. data/lib/autocad.rb +126 -30
  41. data/lib/faa/cleanup.rb +137 -0
  42. data/lib/win32ole_helper.rb +52 -0
  43. data/rbs_collection.lock.yaml +38 -18
  44. data/sig/generated/autocad/app.rbs +278 -251
  45. data/sig/generated/autocad/arc.rbs +6 -3
  46. data/sig/generated/autocad/block.rbs +8 -5
  47. data/sig/generated/autocad/block_reference.rbs +99 -59
  48. data/sig/generated/autocad/bounding_box.rbs +78 -0
  49. data/sig/generated/autocad/dim_style.rbs +6 -0
  50. data/sig/generated/autocad/drawing.rbs +597 -158
  51. data/sig/generated/autocad/element.rbs +233 -166
  52. data/sig/generated/autocad/errors.rbs +29 -23
  53. data/sig/generated/autocad/filter.rbs +388 -60
  54. data/sig/generated/autocad/layer.rbs +76 -19
  55. data/sig/generated/autocad/layout.rbs +64 -0
  56. data/sig/generated/autocad/line.rbs +128 -25
  57. data/sig/generated/autocad/message_box.rbs +81 -81
  58. data/sig/generated/autocad/model.rbs +115 -41
  59. data/sig/generated/autocad/mtext.rbs +123 -0
  60. data/sig/generated/autocad/plot.rbs +26 -0
  61. data/sig/generated/autocad/plot_configuration.rbs +176 -0
  62. data/sig/generated/autocad/point.rbs +7 -0
  63. data/sig/generated/autocad/point3d.rbs +70 -66
  64. data/sig/generated/autocad/pviewport.rbs +64 -0
  65. data/sig/generated/autocad/selection_filter.rbs +226 -50
  66. data/sig/generated/autocad/selection_set.rbs +112 -37
  67. data/sig/generated/autocad/selection_set_adapter.rbs +235 -28
  68. data/sig/generated/autocad/spline.rbs +22 -0
  69. data/sig/generated/autocad/text.rbs +66 -7
  70. data/sig/generated/autocad/text_style.rbs +6 -0
  71. data/sig/generated/autocad/viewport.rbs +19 -2
  72. data/sig/generated/autocad.rbs +140 -68
  73. data/sig/generated/faa/cleanup.rbs +53 -0
  74. data/sig/generated/win32ole_helper.rbs +9 -0
  75. data/sig/prototype/lib/autocad/app.rbs +3 -1
  76. data/sig/prototype/lib/autocad/bounding_box.rbs +15 -0
  77. data/sig/prototype/lib/autocad/drawing.rbs +6 -0
  78. data/sig/prototype/lib/autocad/layer.rbs +5 -0
  79. data/sig/prototype/lib/autocad/viewport.rbs +7 -0
  80. data/sig/prototype/lib/autocad.rbs +1 -1
  81. metadata +29 -5
  82. data/event_handler.log +0 -24
  83. data/sig/generated/autocad/text_node.rbs +0 -37
data/lib/autocad/layer.rb CHANGED
@@ -1,41 +1,129 @@
1
- module Autocad
2
- class Layer < Element
3
- def name
4
- ole_obj.name
5
- end
6
-
7
- def description
8
- ole_obj.description
9
- end
10
-
11
- def lock(lk = true)
12
- ole_obj.Lock = lk
13
- rescue
14
- raise Autocad::Error.new("Error locking layer #{name}")
15
- end
16
-
17
- def visible?
18
- ole_obj.Visible
19
- end
20
-
21
- def visible=(vis)
22
- ole_obj.Visible = vis
23
- end
24
-
25
- def delete
26
- ole_obj.Delete
27
- rescue => e
28
- raise Autocad::Error.new("Error deleting layer #{name} #{e}")
29
- end
30
-
31
- def linetype=(ltname)
32
- found_lt = app.current_drawing.linetypes.find { |lt| lt.name == ltname }
33
-
34
- app.current_drawing.ole_obj.Linetypes.Load(ltname, ltname) unless found_lt
35
-
36
- ole_obj.Linetype = ltname
37
- rescue => e
38
- raise Autocad::Error.new("Error setting linetype of layer #{name} : #{e}")
39
- end
40
- end
41
- end
1
+ module Autocad
2
+ class Layer < Element
3
+ # @rbs return String -- the name of the layer
4
+ def name
5
+ ole_obj.name
6
+ end
7
+
8
+ # Get the color of the layer
9
+ # @rbs return Integer -- the color index of the layer
10
+ def color
11
+ ole_obj.Color
12
+ end
13
+
14
+ # Set the color of the layer
15
+ # @rbs color: Integer|Symbol -- the color to set (can be ACAD::COLOR constant, symbol, or integer)
16
+ # @rbs return void
17
+ def color=(color)
18
+ ole_obj.Color = Autocad.color_to_index(color)
19
+ end
20
+
21
+ # Get the symbolic color name if available
22
+ # @rbs return Symbol|Integer -- the symbolic color name or integer if no name exists
23
+ def color_name
24
+ Autocad::Color.from_index(color)
25
+ end
26
+
27
+ # set the name of the layer
28
+ # @rbs name: String
29
+ # @rbs return void
30
+ def name=(name)
31
+ ole_obj.name = name
32
+ end
33
+
34
+ def description
35
+ ole_obj.description
36
+ end
37
+
38
+ # is the layer the active layer
39
+ # @rbs return bool
40
+ def active?
41
+ drawing.active_layer_name == name
42
+ end
43
+
44
+ # Activates the current layer by setting it as the active layer in the drawing.
45
+ # This method assigns the current layer's OLE object to the ActiveLayer property of the drawing's OLE object.
46
+ #
47
+ # @rbs return void
48
+ def activate
49
+ drawing.ole_obj.ActiveLayer = ole_obj
50
+ end
51
+
52
+ # @rbs return bool
53
+ def frozen?
54
+ ole_obj.Freeze
55
+ end
56
+
57
+ # freeze the layer - entities on layer are invisible and wont be
58
+ # regenerated
59
+ def freeze
60
+ ole_obj.Freeze = true
61
+ end
62
+
63
+ # unfreeze the layer
64
+ def unfreeze
65
+ ole_obj.Freeze = false
66
+ end
67
+
68
+ # @rbs return bool
69
+ def thawed?
70
+ !frozen?
71
+ end
72
+
73
+ alias_method :thaw, :unfreeze
74
+
75
+ # lock the layer - entities on layer can't be changed
76
+ def lock
77
+ ole_obj.Lock = true
78
+ end
79
+
80
+ # unlock the layer
81
+ def unlock
82
+ ole_obj.Lock = false
83
+ end
84
+
85
+ # @rbs return bool -- true if layer is locked
86
+ def locked?
87
+ ole_obj.Lock
88
+ end
89
+
90
+ def visible?
91
+ ole_obj.Visible
92
+ end
93
+
94
+ def visible=(vis)
95
+ ole_obj.Visible = vis
96
+ end
97
+
98
+ # turn on the layer.
99
+ #
100
+ def turn_on
101
+ ole_obj.LayerOn = true
102
+ end
103
+
104
+ def turn_off
105
+ ole_obj.LayerOn = false
106
+ end
107
+
108
+ # @rbs return bool
109
+ def on?
110
+ ole_obj.LayerOn
111
+ end
112
+
113
+ def delete
114
+ ole_obj.Delete
115
+ rescue => e
116
+ raise Autocad::Error.new("Error deleting layer #{name} #{e}")
117
+ end
118
+
119
+ def linetype=(ltname)
120
+ found_lt = app.current_drawing.linetypes.find { |lt| lt.name == ltname }
121
+
122
+ app.current_drawing.ole_obj.Linetypes.Load(ltname, ltname) unless found_lt
123
+
124
+ ole_obj.Linetype = ltname
125
+ rescue => e
126
+ raise Autocad::Error.new("Error setting linetype of layer #{name} : #{e}")
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,120 @@
1
+ module Autocad
2
+ class Layout < PlotConfiguration
3
+ # Inserts a block into the layout
4
+ # @rbs block: Block
5
+ # @rbs pt: Point3d?
6
+ # @rbs return void
7
+ def insert_block(block, pt: nil)
8
+ end
9
+
10
+ # Get the layout name
11
+ # @rbs return String
12
+ def name
13
+ @ole_obj.Name
14
+ end
15
+
16
+ # Set the layout name
17
+ # @rbs str: String
18
+ # @rbs return void
19
+ def name=(str)
20
+ @ole_obj.Name = str
21
+ end
22
+
23
+ # Copy plot settings from another configuration
24
+ # @rbs pc: PlotConfiguration
25
+ # @rbs return void
26
+ def copy_plot_configuration(pc)
27
+ ole_obj.CopyFrom(pc.ole_obj)
28
+ end
29
+
30
+ # Insert a block reference into the layout
31
+ # @rbs name: String
32
+ # @rbs pt: Point3d
33
+ # @rbs rotation: Float
34
+ # @rbs scale: Float
35
+ # @rbs return BlockReference?
36
+ # @raise [StandardError] On insertion failure
37
+ def add_block_reference(name, pt:, rotation: 0.0, scale: 1.0)
38
+ name = name.to_s
39
+ name = app.windows_path(name) if File.file?(name)
40
+
41
+ pt3d = Point3d.new(pt)
42
+ ole_reference = ole_obj.Block.InsertBlock(pt3d.to_ole, name.to_s,
43
+ scale.to_f, scale.to_f, scale.to_f, rotation.to_f)
44
+ app.wrap(ole_reference)
45
+ rescue StandardError => e
46
+ app.error_proc.call(e, self)
47
+ nil
48
+ end
49
+
50
+ # Get layout tab order position
51
+ # @rbs return Integer
52
+ def tab_order
53
+ @ole_obj.TabOrder
54
+ end
55
+
56
+ # Set layout tab order position
57
+ # @rbs n: Integer
58
+ # @rbs return void
59
+ def tab_order=(n)
60
+ @ole_obj.TabOrder = n
61
+ end
62
+
63
+ # Get paper dimensions in millimeters
64
+ # @rbs return [Float, Float]
65
+ def paper_size
66
+ width = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_BYREF | WIN32OLE::VARIANT::VT_R8)
67
+ height = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_BYREF | WIN32OLE::VARIANT::VT_R8)
68
+ @ole_obj.GetPaperSize(width, height)
69
+ [width.value, height.value]
70
+ end
71
+
72
+ # Calculate usable area bounds with margins
73
+ # @rbs return BoundingBox
74
+ def bounds
75
+ width, height = paper_size
76
+ lower_left, upper_right = paper_margins
77
+ lower_left_pt = lower_left
78
+ upper_right_pt = Point3d(width, height) - upper_right
79
+ BoundingBox.from_min_max(lower_left_pt, upper_right_pt)
80
+ end
81
+
82
+ # Get paper size in inches
83
+ # @rbs return [Float, Float]
84
+ def paper_size_inches
85
+ width, height = paper_size
86
+ [width / 25.4, height / 25.4]
87
+ end
88
+
89
+ # Add a paper space viewport
90
+ # @rbs scale: Symbol
91
+ # @rbs return PViewport
92
+ def add_pviewport(scale = :scale_to_fit)
93
+ psize_width, psize_h = paper_size
94
+ margins = paper_margins
95
+ width_mm = psize_width - margins[0][0] - margins[1][0]
96
+ height_mm = psize_h - margins[0][1] - margins[1][1]
97
+ width = width_mm / paper_units_scale_factor
98
+ height = height_mm / paper_units_scale_factor
99
+
100
+ center = [width / 2.0, height / 2.0]
101
+ pv = drawing.paper_space.add_pv_viewport(center, width: width, height: height)
102
+ pv.on
103
+ pv.standard_scale = scale
104
+ pv
105
+ end
106
+
107
+ # Get page margins
108
+ # @rbs return [[Float, Float], [Float, Float]]
109
+ def paper_margins
110
+ lower_left = nil
111
+ upper_right = nil
112
+ @ole_obj.GetPaperMargins lower_left, upper_right
113
+ lower_left, upper_right = WIN32OLE::ARGV
114
+ [lower_left, upper_right]
115
+ rescue StandardError => e
116
+ puts "Error getting paper margins: #{e.message}"
117
+ [[0.0, 0.0], [0.0, 0.0]] # Return default values instead of breaking
118
+ end
119
+ end
120
+ end
data/lib/autocad/line.rb CHANGED
@@ -1,55 +1,154 @@
1
- # rbs_inline: enabled
2
-
3
- require_relative 'element'
4
-
5
- module Autocad
6
- class Line < Element
7
- def length
8
- ole_obj.length
9
- end
10
-
11
- def line?
12
- true
13
- end
14
-
15
- def start_point # : Point3d
16
- Point3d(ole_obj.StartPoint)
17
- end
18
-
19
- def end_point # : Point3d
20
- Point3d(ole_obj.EndPoint)
21
- end
22
-
23
- def normal
24
- ole_obj.Normal
25
- end
26
-
27
- def thickness
28
- ole_obj.Thickness
29
- end
30
-
31
- def delta
32
- ole_obj.Delta
33
- end
34
- end
35
-
36
- class Circle < Element
37
- def center
38
- Point3d.new(ole_obj.Center)
39
- end
40
-
41
- def radius
42
- Point3d.new(ole_obj.Radius)
43
- end
44
- end
45
-
46
- class Polyline < Element
47
- def length
48
- @ole_obj.Length
49
- end
50
-
51
- def coordinates
52
- @ole_obj.coordinates
53
- end
54
- end
55
- end
1
+ # rbs_inline: enabled
2
+
3
+ require_relative 'element'
4
+
5
+ module Autocad
6
+ # Represents a line entity in AutoCAD, providing access to geometric properties and spatial relationships.
7
+ #
8
+ # Key Features:
9
+ # - Length calculation
10
+ # - Start/end point coordinates
11
+ # - 3D orientation properties
12
+ # - Thickness control
13
+ # - Geometric vector analysis
14
+ #
15
+ # Geometric Relationships:
16
+ # Normal (Z-axis)
17
+ # ↑
18
+ # │
19
+ # Start ●───┼───● End
20
+ # │
21
+ # └─── Delta Vector
22
+ #
23
+ # @example Create and query a line
24
+ # line = drawing.model.add_line([0,0,0], [5,5,0])
25
+ # puts line.length # => 7.0710678118654755
26
+ # puts line.delta # => (5.0, 5.0, 0.0)
27
+ class Line < Element
28
+ # Calculates the linear length of the line segment.
29
+ #
30
+ # @example
31
+ # line = drawing.model.add_line([0,0,0], [5,5,0])
32
+ # puts line.length # => 7.0710678118654755
33
+ #
34
+ # @return [Float] The length of the line
35
+ # @rbs return float
36
+ def length
37
+ ole_obj.length
38
+ end
39
+
40
+ # Type-check method confirming this is a line entity.
41
+ #
42
+ # @example
43
+ # line.line? # => true
44
+ #
45
+ # @return [Boolean] Always returns true for Line objects
46
+ # @rbs return bool
47
+ def line?
48
+ true
49
+ end
50
+
51
+ # 3D coordinates of the line's starting point in World Coordinate System (WCS).
52
+ #
53
+ # @example
54
+ # start = line.start_point
55
+ # puts start # => (0.0, 0.0, 0.0)
56
+ #
57
+ # @return [Point3d] The start point coordinates
58
+ # @rbs return Point3d
59
+ def start_point
60
+ Point3d.new(ole_obj.StartPoint)
61
+ end
62
+
63
+ # 3D coordinates of the line's endpoint in World Coordinate System (WCS).
64
+ #
65
+ # @example
66
+ # ending = line.end_point
67
+ # puts ending # => (5.0, 5.0, 0.0)
68
+ #
69
+ # @return [Point3d] The end point coordinates
70
+ # @rbs return Point3d
71
+ def end_point
72
+ Point3d.new(ole_obj.EndPoint)
73
+ end
74
+
75
+ # Unit vector perpendicular to the line's plane (Z-axis direction by default).
76
+ #
77
+ # Properties:
78
+ # - Always returns unit vector (magnitude = 1)
79
+ # - Affects shading and 3D operations
80
+ #
81
+ # @example
82
+ # line.normal # => (0.0, 0.0, 1.0)
83
+ #
84
+ # @return [Point3d] The normal vector
85
+ # @rbs return Point3d
86
+ def normal
87
+ Point3d.new ole_obj.Normal
88
+ end
89
+
90
+ # Extrusion thickness along the normal vector (3D effect).
91
+ #
92
+ # Note:
93
+ # - Positive values extrude in normal direction
94
+ # - Negative values extrude opposite direction
95
+ # - 0 = 2D line
96
+ #
97
+ # @example
98
+ # line.thickness = 2.5 # Creates 3D prism
99
+ #
100
+ # @return [Float] The current thickness value
101
+ # @rbs return float
102
+ def thickness
103
+ ole_obj.Thickness
104
+ end
105
+
106
+ # Directional vector from start to end point (equivalent to `end_point - start_point`).
107
+ #
108
+ # Mathematical Properties:
109
+ # - X/Y/Z components = coordinate differences
110
+ # - Magnitude = line length
111
+ #
112
+ # @example
113
+ # line.delta # => (5.0, 5.0, 0.0)
114
+ # line.delta.magnitude == line.length # => true
115
+ #
116
+ # @return [Point3d] The vector from start to end point
117
+ # @rbs return Point3d
118
+ def delta
119
+ Point3d.new ole_obj.Delta
120
+ end
121
+ end
122
+
123
+ class Circle < Element
124
+ # The center point of the circle in World Coordinate System (WCS)
125
+ # @rbs return Point3d
126
+ def center
127
+ Point3d.new(ole_obj.Center)
128
+ end
129
+
130
+ # The radius of the circle
131
+ # @rbs return float
132
+ def radius
133
+ ole_obj.Radius
134
+ end
135
+
136
+ def inspect
137
+ "#<#{self.class} center=#{center} radius=#{radius}>"
138
+ end
139
+ end
140
+
141
+ class Polyline < Element
142
+ # The total length of all polyline segments
143
+ # @rbs return float
144
+ def length
145
+ Point3d.new @ole_obj.Length
146
+ end
147
+
148
+ # Array of all vertex coordinates in the polyline
149
+ # @rbs return Array[Point3d]
150
+ def coordinates
151
+ @ole_obj.coordinates.map { |pt| Point3d.new(pt) }
152
+ end
153
+ end
154
+ end
@@ -1,95 +1,95 @@
1
- require "fiddle/import"
2
- require "fiddle/types"
3
-
4
- module WinAPI
5
- extend Fiddle::Importer
6
- dlload "user32.dll"
7
- include Fiddle::BasicTypes
8
- include Fiddle::Win32Types
9
-
10
- typealias "LPCWSTR", "wchar_t*"
11
-
12
- extern "int MessageBoxA(HWND, LPCSTR, LPCSTR, DWORD)"
13
- extern "int MessageBoxW(HWND, LPCWSTR, LPCWSTR, DWORD)"
14
- # window handling
15
- extern "HWND GetForegroundWindow()"
16
- extern "int GetWindowText(HWND, char*, int)"
17
- extern "int GetWindowTextLength(HWND)"
18
-
19
- def get_foreground_window
20
- GetForegroundWindow()
21
- end
22
-
23
- def self.get_text_of_active_window
24
- hwnd = GetForegroundWindow()
25
- buf_size = GetWindowTextLength(hwnd)
26
- str = " " * (buf_size + 1)
27
- GetWindowText(hwnd, str, str.length)
28
- str.encode(Encoding.default_external)
29
- end
30
-
31
- module MB
32
- OK = 1
33
- CANCEL = 1
34
- ABORT = 3
35
- RETRY = 4
36
- IGNORE = 5
37
- YES = 6
38
- NO = 7
39
-
40
- module ICON
41
- ERROR = 16
42
- QUESTION = 32
43
- INFORMATION = 64
44
- WARNING = 128
45
- end
46
-
47
- module BTN
48
- OK = 0
49
- OKCANCEL = 1
50
- ABORTRETRYIGNORE = 2
51
- YESNO = 4
52
- end
53
- end
54
- end
55
-
56
- # msgbox_yesno('Do you want to continue?') do |y|
57
- # if y
58
- # puts 'proceeding with ...'
59
- # else
60
- # puts 'cancelled ...'
61
- # end
62
- # end
63
- #
64
- # msgbox('We are finished here')
65
- #
66
- # loop do
67
- # puts WinAPI.get_text_of_active_window
68
- # sleep 1
69
- # end
70
- module Kernel
71
- module_function
72
-
73
- # @rbs str: String
74
- # @rbs return String
75
- def L(str)
76
- str.encode("UTF-16LE")
77
- end
78
-
79
- # @example
80
- # msg_box_yesno("Do you want to continue") do |y|
81
- # if y
82
- # puts "proceeding"
83
- # else
84
- # puts "cancelled"
85
- # end
86
- # end
87
- def msgbox_yesno(content, title: "Alert")
88
- result = WinAPI::MessageBoxW(0, L(content), L(title), WinAPI::MB::BTN::YESNO) == WinAPI::MB::YES
89
- yield(result)
90
- end
91
-
92
- def msgbox(content, title: "Alert")
93
- WinAPI::MessageBoxW(0, L(content), L(title), WinAPI::MB::BTN::OK)
94
- end
95
- end
1
+ require "fiddle/import"
2
+ require "fiddle/types"
3
+
4
+ module WinAPI
5
+ extend Fiddle::Importer
6
+ dlload "user32.dll"
7
+ include Fiddle::BasicTypes
8
+ include Fiddle::Win32Types
9
+
10
+ typealias "LPCWSTR", "wchar_t*"
11
+
12
+ extern "int MessageBoxA(HWND, LPCSTR, LPCSTR, DWORD)"
13
+ extern "int MessageBoxW(HWND, LPCWSTR, LPCWSTR, DWORD)"
14
+ # window handling
15
+ extern "HWND GetForegroundWindow()"
16
+ extern "int GetWindowText(HWND, char*, int)"
17
+ extern "int GetWindowTextLength(HWND)"
18
+
19
+ def get_foreground_window
20
+ GetForegroundWindow()
21
+ end
22
+
23
+ def self.get_text_of_active_window
24
+ hwnd = GetForegroundWindow()
25
+ buf_size = GetWindowTextLength(hwnd)
26
+ str = " " * (buf_size + 1)
27
+ GetWindowText(hwnd, str, str.length)
28
+ str.encode(Encoding.default_external)
29
+ end
30
+
31
+ module MB
32
+ OK = 1
33
+ CANCEL = 1
34
+ ABORT = 3
35
+ RETRY = 4
36
+ IGNORE = 5
37
+ YES = 6
38
+ NO = 7
39
+
40
+ module ICON
41
+ ERROR = 16
42
+ QUESTION = 32
43
+ INFORMATION = 64
44
+ WARNING = 128
45
+ end
46
+
47
+ module BTN
48
+ OK = 0
49
+ OKCANCEL = 1
50
+ ABORTRETRYIGNORE = 2
51
+ YESNO = 4
52
+ end
53
+ end
54
+ end
55
+
56
+ # msgbox_yesno('Do you want to continue?') do |y|
57
+ # if y
58
+ # puts 'proceeding with ...'
59
+ # else
60
+ # puts 'cancelled ...'
61
+ # end
62
+ # end
63
+ #
64
+ # msgbox('We are finished here')
65
+ #
66
+ # loop do
67
+ # puts WinAPI.get_text_of_active_window
68
+ # sleep 1
69
+ # end
70
+ module Kernel
71
+ module_function
72
+
73
+ # @rbs str: String
74
+ # @rbs return String
75
+ def L(str)
76
+ str.encode("UTF-16LE")
77
+ end
78
+
79
+ # @example
80
+ # msg_box_yesno("Do you want to continue") do |y|
81
+ # if y
82
+ # puts "proceeding"
83
+ # else
84
+ # puts "cancelled"
85
+ # end
86
+ # end
87
+ def msgbox_yesno(content, title: "Alert")
88
+ result = WinAPI::MessageBoxW(0, L(content), L(title), WinAPI::MB::BTN::YESNO) == WinAPI::MB::YES
89
+ yield(result)
90
+ end
91
+
92
+ def msgbox(content, title: "Alert")
93
+ WinAPI::MessageBoxW(0, L(content), L(title), WinAPI::MB::BTN::OK)
94
+ end
95
+ end