teek 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/Rakefile +120 -22
- data/ext/teek/extconf.rb +19 -1
- data/ext/teek/tcltkbridge.c +38 -2
- data/ext/teek/tcltkbridge.h +3 -0
- data/ext/teek/tkdrop.c +66 -0
- data/ext/teek/tkdrop.h +26 -0
- data/ext/teek/tkdrop_macos.m +141 -0
- data/ext/teek/tkdrop_win.c +232 -0
- data/ext/teek/tkdrop_x11.c +337 -0
- data/ext/teek/tkwin.c +42 -0
- data/lib/teek/platform.rb +29 -0
- data/lib/teek/version.rb +1 -1
- data/lib/teek.rb +49 -3
- data/teek.gemspec +3 -2
- metadata +7 -53
- data/sample/calculator.rb +0 -255
- data/sample/debug_demo.rb +0 -43
- data/sample/gamepad_viewer/assets/controller.png +0 -0
- data/sample/gamepad_viewer/gamepad_viewer.rb +0 -554
- data/sample/goldberg.rb +0 -1803
- data/sample/goldberg_helpers.rb +0 -170
- data/sample/optcarrot/thwaite.nes +0 -0
- data/sample/optcarrot/vendor/optcarrot/apu.rb +0 -856
- data/sample/optcarrot/vendor/optcarrot/config.rb +0 -257
- data/sample/optcarrot/vendor/optcarrot/cpu.rb +0 -1162
- data/sample/optcarrot/vendor/optcarrot/driver.rb +0 -144
- data/sample/optcarrot/vendor/optcarrot/mapper/cnrom.rb +0 -14
- data/sample/optcarrot/vendor/optcarrot/mapper/mmc1.rb +0 -105
- data/sample/optcarrot/vendor/optcarrot/mapper/mmc3.rb +0 -153
- data/sample/optcarrot/vendor/optcarrot/mapper/uxrom.rb +0 -14
- data/sample/optcarrot/vendor/optcarrot/nes.rb +0 -105
- data/sample/optcarrot/vendor/optcarrot/opt.rb +0 -168
- data/sample/optcarrot/vendor/optcarrot/pad.rb +0 -92
- data/sample/optcarrot/vendor/optcarrot/palette.rb +0 -65
- data/sample/optcarrot/vendor/optcarrot/ppu.rb +0 -1468
- data/sample/optcarrot/vendor/optcarrot/rom.rb +0 -143
- data/sample/optcarrot/vendor/optcarrot.rb +0 -14
- data/sample/optcarrot.rb +0 -354
- data/sample/paint/assets/bucket.png +0 -0
- data/sample/paint/assets/cursor.png +0 -0
- data/sample/paint/assets/eraser.png +0 -0
- data/sample/paint/assets/pencil.png +0 -0
- data/sample/paint/assets/spray.png +0 -0
- data/sample/paint/layer.rb +0 -255
- data/sample/paint/layer_manager.rb +0 -179
- data/sample/paint/paint_demo.rb +0 -837
- data/sample/paint/sparse_pixel_buffer.rb +0 -202
- data/sample/sdl2_demo.rb +0 -318
- data/sample/threading_demo.rb +0 -494
- data/sample/yam/assets/MINESWEEPER_0.png +0 -0
- data/sample/yam/assets/MINESWEEPER_1.png +0 -0
- data/sample/yam/assets/MINESWEEPER_2.png +0 -0
- data/sample/yam/assets/MINESWEEPER_3.png +0 -0
- data/sample/yam/assets/MINESWEEPER_4.png +0 -0
- data/sample/yam/assets/MINESWEEPER_5.png +0 -0
- data/sample/yam/assets/MINESWEEPER_6.png +0 -0
- data/sample/yam/assets/MINESWEEPER_7.png +0 -0
- data/sample/yam/assets/MINESWEEPER_8.png +0 -0
- data/sample/yam/assets/MINESWEEPER_F.png +0 -0
- data/sample/yam/assets/MINESWEEPER_M.png +0 -0
- data/sample/yam/assets/MINESWEEPER_X.png +0 -0
- data/sample/yam/assets/click.wav +0 -0
- data/sample/yam/assets/explosion.wav +0 -0
- data/sample/yam/assets/flag.wav +0 -0
- data/sample/yam/assets/music.mp3 +0 -0
- data/sample/yam/assets/sweep.wav +0 -0
- data/sample/yam/yam.rb +0 -587
data/sample/goldberg_helpers.rb
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Canvas and Tcl helpers for the Goldberg demo.
|
|
4
|
-
# Provides a thin wrapper around Tcl canvas commands so the draw/move
|
|
5
|
-
# methods read almost like the original tk-ng version.
|
|
6
|
-
#
|
|
7
|
-
# Including class must provide:
|
|
8
|
-
# @app - Teek::App instance
|
|
9
|
-
# @canvas - Tcl path of the canvas widget (String)
|
|
10
|
-
|
|
11
|
-
module GoldbergHelpers
|
|
12
|
-
|
|
13
|
-
# -- Tcl value formatting ------------------------------------------------
|
|
14
|
-
|
|
15
|
-
def tcl_val(v)
|
|
16
|
-
case v
|
|
17
|
-
when true then '1'
|
|
18
|
-
when false then '0'
|
|
19
|
-
when nil then '{}'
|
|
20
|
-
when Symbol then v.to_s
|
|
21
|
-
when Array
|
|
22
|
-
inner = v.map { |e|
|
|
23
|
-
s = e.is_a?(Symbol) ? e.to_s : e.to_s
|
|
24
|
-
s.include?(' ') ? "{#{s}}" : s
|
|
25
|
-
}.join(' ')
|
|
26
|
-
"{#{inner}}"
|
|
27
|
-
when String
|
|
28
|
-
v.empty? ? '{}' : "{#{v}}"
|
|
29
|
-
when Numeric
|
|
30
|
-
v.to_s
|
|
31
|
-
else
|
|
32
|
-
"{#{v}}"
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def format_font(f)
|
|
37
|
-
return "{#{f}}" if f.is_a?(String)
|
|
38
|
-
parts = f.map { |p|
|
|
39
|
-
s = p.is_a?(Symbol) ? p.to_s : p.to_s
|
|
40
|
-
s.include?(' ') ? "{#{s}}" : s
|
|
41
|
-
}
|
|
42
|
-
"{#{parts.join(' ')}}"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def tcl_opts(opts)
|
|
46
|
-
opts.map { |k, v|
|
|
47
|
-
key = k == :tag ? :tags : k
|
|
48
|
-
val = key == :font ? format_font(v) : tcl_val(v)
|
|
49
|
-
"-#{key} #{val}"
|
|
50
|
-
}.join(' ')
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# -- Canvas item creation ------------------------------------------------
|
|
54
|
-
# All return the Tcl item id (string).
|
|
55
|
-
|
|
56
|
-
def ccreate(type, *coords, **opts)
|
|
57
|
-
c = coords.flatten.join(' ')
|
|
58
|
-
o = opts.empty? ? '' : " #{tcl_opts(opts)}"
|
|
59
|
-
@app.tcl_eval("#{@canvas} create #{type} #{c}#{o}")
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def cline(*coords, **opts) = ccreate(:line, *coords, **opts)
|
|
63
|
-
def cpoly(*coords, **opts) = ccreate(:polygon, *coords, **opts)
|
|
64
|
-
def coval(*coords, **opts) = ccreate(:oval, *coords, **opts)
|
|
65
|
-
def carc(*coords, **opts) = ccreate(:arc, *coords, **opts)
|
|
66
|
-
def crect(*coords, **opts) = ccreate(:rectangle, *coords, **opts)
|
|
67
|
-
def ctext(*coords, **opts) = ccreate(:text, *coords, **opts)
|
|
68
|
-
def cbitmap(*coords, **opts) = ccreate(:bitmap, *coords, **opts)
|
|
69
|
-
|
|
70
|
-
# -- Canvas operations ---------------------------------------------------
|
|
71
|
-
|
|
72
|
-
def cmove(tag, dx, dy)
|
|
73
|
-
@app.tcl_eval("#{@canvas} move #{tag} #{dx} #{dy}")
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def ccoords(tag, new_coords = nil)
|
|
77
|
-
if new_coords
|
|
78
|
-
@app.tcl_eval("#{@canvas} coords #{tag} #{new_coords.flatten.join(' ')}")
|
|
79
|
-
else
|
|
80
|
-
@app.tcl_eval("#{@canvas} coords #{tag}").split.map(&:to_f)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def cdel(*tags)
|
|
85
|
-
tags.each { |t| @app.tcl_eval("#{@canvas} delete #{t}") }
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def cbbox(tag)
|
|
89
|
-
r = @app.tcl_eval("#{@canvas} bbox #{tag}")
|
|
90
|
-
r.empty? ? nil : r.split.map(&:to_f)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def cscale(tag, ox, oy, sx, sy)
|
|
94
|
-
@app.tcl_eval("#{@canvas} scale #{tag} #{ox} #{oy} #{sx} #{sy}")
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def citemconfig(tag, **opts)
|
|
98
|
-
@app.tcl_eval("#{@canvas} itemconfigure #{tag} #{tcl_opts(opts)}")
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def citemcget(tag, opt)
|
|
102
|
-
@app.tcl_eval("#{@canvas} itemcget #{tag} -#{opt}")
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def cfind(tag)
|
|
106
|
-
r = @app.tcl_eval("#{@canvas} find withtag #{tag}")
|
|
107
|
-
r.empty? ? [] : r.split
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def craise(tag, above = nil)
|
|
111
|
-
cmd = "#{@canvas} raise #{tag}"
|
|
112
|
-
cmd += " #{above}" if above
|
|
113
|
-
@app.tcl_eval(cmd)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def clower(tag, below = nil)
|
|
117
|
-
cmd = "#{@canvas} lower #{tag}"
|
|
118
|
-
cmd += " #{below}" if below
|
|
119
|
-
@app.tcl_eval(cmd)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# Bind an event on a canvas item (tag).
|
|
123
|
-
def cbind_item(tag, event, &block)
|
|
124
|
-
id = @app.register_callback(proc { |*| block.call })
|
|
125
|
-
@app.tcl_eval("#{@canvas} bind #{tag} <#{event}> {ruby_callback #{id}}")
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
# Bind an event on the canvas widget itself.
|
|
129
|
-
def canvas_bind(event, &block)
|
|
130
|
-
@app.bind(@canvas, event, &block)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def canvas_bind_remove(event)
|
|
134
|
-
@app.unbind(@canvas, event)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# -- Misc helpers --------------------------------------------------------
|
|
138
|
-
|
|
139
|
-
def winfo_pixels(val)
|
|
140
|
-
@app.tcl_eval("winfo pixels #{@canvas} #{val}").to_i
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def clock_ms
|
|
144
|
-
(Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
# Simple wrapper for a Tcl variable (for -textvariable / -variable binding).
|
|
148
|
-
class TclVar
|
|
149
|
-
attr_reader :name
|
|
150
|
-
|
|
151
|
-
def initialize(app, var_name, initial = '')
|
|
152
|
-
@app = app
|
|
153
|
-
@name = "::gb_#{var_name}"
|
|
154
|
-
set(initial)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def get
|
|
158
|
-
@app.get_variable(@name)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def set(v)
|
|
162
|
-
@app.set_variable(@name, v)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
def to_s = get
|
|
166
|
-
def to_i = get.to_i
|
|
167
|
-
def to_f = get.to_f
|
|
168
|
-
def bool = (get != '0' && !get.empty?)
|
|
169
|
-
end
|
|
170
|
-
end
|
|
Binary file
|