Skip to content

Instantly share code, notes, and snippets.

@brettchalupa
Last active November 22, 2022 01:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettchalupa/10a6835f377c7378415afe1cda0a2bc5 to your computer and use it in GitHub Desktop.
Save brettchalupa/10a6835f377c7378415afe1cda0a2bc5 to your computer and use it in GitHub Desktop.
DragonRuby GTK PadBud Source r1
PADDING = 20
def tick args
args.outputs.background_color = [255, 255, 255]
args.outputs.labels << [PADDING, args.grid.h - PADDING, 'PadBud', 3]
args.outputs.labels << [PADDING, args.grid.h - PADDING * 3, 'A simple tool for viewing DragonRuby gamepad input.']
args.outputs.labels << [PADDING, 140, 'Platform Details', 2]
args.outputs.labels << [PADDING, 110, "OS: #{args.gtk.platform}"]
args.outputs.sprites << { x: PADDING + 80, y: args.grid.h - PADDING - 28, h: 32, w: 32, path: "metadata/icon.png" }
["one", "two", "three", "four"].each_with_index do |slot, i|
i += 1
controller = args.inputs.send("controller_#{slot}")
str = "Controller #{i} connected? #{controller.connected}"
if controller.connected
truthy_keys = controller.key_held.truthy_keys
str += " "
if truthy_keys.any?
str += "Pressed buttons: #{truthy_keys}"
else
str += "No pressed buttons"
end
end
args.outputs.labels << [PADDING, args.grid.h - PADDING - PADDING * 3 - (i * 32), str]
end
args.outputs.debug << [args.grid.w - PADDING * 1.5, args.grid.h - PADDING / 2, "#{args.gtk.current_framerate}", 150, 150, 150].label
end
@computer045
Copy link

I have a suggestion to simplify your code. You could go with this form for slot numbers:

slots = ['one', 'two', 'three', 'four']
slots.each_with_index do |slot, i|
  ...
end

@brettchalupa
Copy link
Author

@computer045 thanks, updated it!

@computer045
Copy link

Also you could use those values instead of your constants above:

args.grid.w # Always equals 1280
args.grid.h # Always equals 720

It's in the DragonRuby documentation.

@brettchalupa
Copy link
Author

@computer045 thanks again, just updated with that change. Much cleaner!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment