summaryrefslogtreecommitdiffhomepage
path: root/samples/02_input_basics/06_touch
diff options
context:
space:
mode:
authorAmir Rajan <[email protected]>2020-11-13 01:29:16 -0600
committerAmir Rajan <[email protected]>2020-11-13 01:29:16 -0600
commit128fa1d90cea6289605a49daf56a0cbb72e2dd28 (patch)
tree5cfdb499d275e2b43075e4d6a076365fc58ff0f7 /samples/02_input_basics/06_touch
parent05cbef7fb8224332795e5685be499d81d20e7d93 (diff)
downloaddragonruby-game-toolkit-contrib-128fa1d90cea6289605a49daf56a0cbb72e2dd28.tar.gz
dragonruby-game-toolkit-contrib-128fa1d90cea6289605a49daf56a0cbb72e2dd28.zip
synced from DRGTK 1.27
Diffstat (limited to 'samples/02_input_basics/06_touch')
-rw-r--r--samples/02_input_basics/06_touch/app/main.rb42
-rw-r--r--samples/02_input_basics/06_touch/license-for-sample.txt9
-rw-r--r--samples/02_input_basics/06_touch/metadata/game_metadata.txt6
-rw-r--r--samples/02_input_basics/06_touch/metadata/icon.pngbin0 -> 14417 bytes
4 files changed, 57 insertions, 0 deletions
diff --git a/samples/02_input_basics/06_touch/app/main.rb b/samples/02_input_basics/06_touch/app/main.rb
new file mode 100644
index 0000000..8b006c7
--- /dev/null
+++ b/samples/02_input_basics/06_touch/app/main.rb
@@ -0,0 +1,42 @@
+def tick args
+ args.outputs.background_color = [ 0, 0, 0 ]
+ args.outputs.primitives << [640, 700, "Touch your screen.", 5, 1, 255, 255, 255].label
+
+ # If you don't want to get fancy, you can just look for finger_one
+ # (and _two, if you like), which are assigned in the order new touches hit
+ # the screen. If not nil, they are touching right now, and are just
+ # references to specific items in the args.input.touch hash.
+ # If finger_one lifts off, it will become nil, but finger_two, if it was
+ # touching, remains until it also lifts off. When all fingers lift off, the
+ # the next new touch will be finger_one again, but until then, new touches
+ # don't fill in earlier slots.
+ if !args.inputs.finger_one.nil?
+ args.outputs.primitives << [640, 650, "Finger #1 is touching at (#{args.inputs.finger_one.x}, #{args.inputs.finger_one.y}).", 5, 1, 255, 255, 255].label
+ end
+ if !args.inputs.finger_two.nil?
+ args.outputs.primitives << [640, 600, "Finger #2 is touching at (#{args.inputs.finger_two.x}, #{args.inputs.finger_two.y}).", 5, 1, 255, 255, 255].label
+ end
+
+ # Here's the more flexible interface: this will report as many simultaneous
+ # touches as the system can handle, but it's a little more effort to track
+ # them. Each item in the args.input.touch hash has a unique key (an
+ # incrementing integer) that exists until the finger lifts off. You can
+ # tell which order the touches happened globally by the key value, or
+ # by the touch[id].touch_order field, which resets to zero each time all
+ # touches have lifted.
+
+ args.state.colors ||= [
+ 0xFF0000, 0x00FF00, 0x1010FF, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0xFFFFFF
+ ]
+
+ size = 100
+ args.inputs.touch.each { |k,v|
+ color = args.state.colors[v.touch_order % 7]
+ r = (color & 0xFF0000) >> 16
+ g = (color & 0x00FF00) >> 8
+ b = (color & 0x0000FF)
+ args.outputs.primitives << [v.x - (size / 2), v.y + (size / 2), size, size, r, g, b, 255].solid
+ args.outputs.primitives << [v.x, v.y + size, k.to_s, 0, 1, 0, 0, 0].label
+ }
+end
+
diff --git a/samples/02_input_basics/06_touch/license-for-sample.txt b/samples/02_input_basics/06_touch/license-for-sample.txt
new file mode 100644
index 0000000..100dcec
--- /dev/null
+++ b/samples/02_input_basics/06_touch/license-for-sample.txt
@@ -0,0 +1,9 @@
+Copyright 2019 DragonRuby LLC
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/samples/02_input_basics/06_touch/metadata/game_metadata.txt b/samples/02_input_basics/06_touch/metadata/game_metadata.txt
new file mode 100644
index 0000000..88e7d96
--- /dev/null
+++ b/samples/02_input_basics/06_touch/metadata/game_metadata.txt
@@ -0,0 +1,6 @@
+devid=dragonruby
+devtitle=DragonRuby LLC
+gameid=touchexample
+gametitle=DragonRuby GTK Touch Example
+version=0.1
+icon=metadata/icon.png
diff --git a/samples/02_input_basics/06_touch/metadata/icon.png b/samples/02_input_basics/06_touch/metadata/icon.png
new file mode 100644
index 0000000..57254fe
--- /dev/null
+++ b/samples/02_input_basics/06_touch/metadata/icon.png
Binary files differ