From 8d000345a3489988e9e86ee9fda9dcc6c70b7012 Mon Sep 17 00:00:00 2001 From: Amir Rajan Date: Sun, 26 Jul 2020 16:31:07 -0500 Subject: added samples to public repo. --- samples/24_http_example/app/main.rb | 53 +++++++++++++++++++++ samples/24_http_example/license-for-sample.txt | 9 ++++ samples/24_http_example/metadata/game_metadata.txt | 6 +++ samples/24_http_example/metadata/icon.png | Bin 0 -> 14417 bytes 4 files changed, 68 insertions(+) create mode 100644 samples/24_http_example/app/main.rb create mode 100644 samples/24_http_example/license-for-sample.txt create mode 100644 samples/24_http_example/metadata/game_metadata.txt create mode 100644 samples/24_http_example/metadata/icon.png (limited to 'samples/24_http_example') diff --git a/samples/24_http_example/app/main.rb b/samples/24_http_example/app/main.rb new file mode 100644 index 0000000..53ece84 --- /dev/null +++ b/samples/24_http_example/app/main.rb @@ -0,0 +1,53 @@ +def tick args + args.outputs.background_color = [0, 0, 0] + + # Show a warning at the start. + args.state.warning_debounce ||= 11 * 60 + if args.state.warning_debounce > 0 + args.state.warning_debounce -= 1 + args.outputs.labels << [640, 600, "This app shows random images from the Internet.", 10, 1, 255, 255, 255] + args.outputs.labels << [640, 500, "Quit in the next few seconds if this is a problem.", 10, 1, 255, 255, 255] + args.outputs.labels << [640, 350, "#{(args.state.warning_debounce / 60.0).to_i}", 10, 1, 255, 255, 255] + return + end + + args.state.download_debounce ||= 0 # start immediately, reset to non zero later. + args.state.photos ||= [] + + # Put a little pause between each download. + if args.state.download.nil? + if args.state.download_debounce > 0 + args.state.download_debounce -= 1 + else + args.state.download = $gtk.http_get 'https://picsum.photos/200/300.jpg' + end + end + + if !args.state.download.nil? + if args.state.download[:complete] + if args.state.download[:http_response_code] == 200 + fname = "sprites/#{args.state.photos.length}.jpg" + $gtk.write_file fname, args.state.download[:response_data] + args.state.photos << [ 100 + rand(1080), 500 - rand(480), fname, rand(80) - 40 ] + end + args.state.download = nil + args.state.download_debounce = (rand(3) + 2) * 60 + end + end + + # draw any downloaded photos... + args.state.photos.each { |i| + args.outputs.primitives << [i[0], i[1], 200, 300, i[2], i[3]].sprite + } + + # Draw a download progress bar... + args.outputs.primitives << [0, 0, 1280, 30, 0, 0, 0, 255].solid + if !args.state.download.nil? + br = args.state.download[:response_read] + total = args.state.download[:response_total] + if total != 0 + pct = br.to_f / total.to_f + args.outputs.primitives << [0, 0, 1280 * pct, 30, 0, 0, 255, 255].solid + end + end +end diff --git a/samples/24_http_example/license-for-sample.txt b/samples/24_http_example/license-for-sample.txt new file mode 100644 index 0000000..100dcec --- /dev/null +++ b/samples/24_http_example/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/24_http_example/metadata/game_metadata.txt b/samples/24_http_example/metadata/game_metadata.txt new file mode 100644 index 0000000..53de213 --- /dev/null +++ b/samples/24_http_example/metadata/game_metadata.txt @@ -0,0 +1,6 @@ +devid=dragonruby +devtitle=DragonRuby LLC +gameid=httpexample +gametitle=DragonRuby GTK HTTP Example +version=0.1 +icon=metadata/icon.png diff --git a/samples/24_http_example/metadata/icon.png b/samples/24_http_example/metadata/icon.png new file mode 100644 index 0000000..57254fe Binary files /dev/null and b/samples/24_http_example/metadata/icon.png differ -- cgit v1.2.3