Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Forum
1 2 3 4 5 6 7 8 9 10 Previous Next  
Search
Topic Using Window#needs_redraw? By jlnr Date 2017-01-16 15:13
Hmm. Why is it laggy? The interlocked threads shouldn't introduce more than 16ms of delay in the worst case.
If I remove the sleep calls, it runs at 30 FPS, and it'd run at 60 FPS with more careful scheduling of the draw/update blocks, but of course that depends on the game's actual code.

I want to support render-to-image in Gosu (without Ashton) at some point, but that's not something that'll happen in the next months, I'm afraid: https://github.com/gosu/gosu/issues/317

If the only problem with record {} is that it doesn't work with clip_to, can you maybe record several macros and remember with which clip rect the macros need to be rendered?
Topic Using Window#needs_redraw? By jlnr Date 2017-01-16 07:20
Or, you can keep Gosu::Window running in parallel to your thread, and only interlock when you need to run something on the main thread (create images, read a value from button_down? etc.), and when you want to redraw the screen.

https://gist.github.com/jlnr/89953f1199080ccaa5bd8fe6d66ea188

It relies on needs_redraw?, which mysteriously works on my computer but I'm using a dev version of Gosu, so maybe it'll be broken for you until 0.11.1 is out. But does that seem like a good workaround?

Feels like a hack, but was fun to write - I don't usually use Ruby's threading API :)
Topic Using Window#needs_redraw? By jlnr Date 2017-01-16 06:52
#render_to_image would only help you if you could use it on a background thread, which I don't think Ashton allows.

Can you somehow run the expensive MiniMagick file conversions when you build your game, so that it will start fast enough to not appear stuck?
Topic What's the best way to patch in new "draw_foo" methods? By jlnr Date 2017-01-16 06:36
Ah, I see. draw_quad originally was (and still is) an instance method of Gosu::Window, which is why you can call it without Gosu:: or Gosu. inside of your window subclass, but only there.

The fact that everything had to be called on a Gosu::Window instance made it necessary to pass around references to the window everywhere (same thing with the old Image constructors etc.), which was so annoying that many games used a global $window variable instead. So in Gosu 0.9, I've moved all the draw_ methods into module Gosu, along with button_down?.

There are technically two draw_quad methods now, one on Gosu::Window and one in Gosu itself. If you want draw_circle to have the same behaviour, you'll need to implement it twice as well. The method in Gosu::Window would just forward all arguments to the module.

It's a bit of a mess. I was about to deprecate the instance methods on Gosu::Window in favour of Gosu.draw_xxx, but I'm afraid that'll make things even more confusing when someone uses include Gosu.

Related comment on the pull request that'll bring deprecations to Gosu 0.11.1 - https://github.com/gosu/gosu/pull/370#issuecomment-272708027
Topic Using Window#needs_redraw? By jlnr Date 2017-01-16 02:50
Usually tick is used like this from within Window#show:

def show # pseudo-implementation
  while tick
    sleep 0.016
  end
  # stops when tick returns false
end


When tick returns false the game should end, because either Window#close was called, or the user clicked the [x] in the window corner.

If you just keep calling tick, the window will re-appear.

What do you mean by "crashes"? Is there an error? It's hard to understand if the structure works for you because I don't know what happens in # ... Do something :)
Topic What's the best way to patch in new "draw_foo" methods? By jlnr Date 2017-01-16 02:44
I think the trick you are missing is to def self.x instead of def x:

module Gosu
  def self.draw_circle
    ... draw_quad(...) ...
  end
end
Topic Using Window#needs_redraw? By jlnr Date 2017-01-15 14:50
I see how that could work with record, but not without it. You cannot draw outside of Window#draw, and you can only create Gosu resources (Image etc.) on the main thread currently.

I think there's a better solution actually, it's a bit experimental but I added it exactly for this use case: Window#tick

Basically, your game would become:

class Game < Gosu::Window
  def draw
    # drawing needs to happen here, but maybe you can call into another function...
  end
end

game = Game.new(...)

while true
  # ... Do something
  game.tick # this will call Window#update and Window#draw
  break if # ...
end
Topic Using Window#needs_redraw? By jlnr Date 2017-01-15 10:08
You are right, it seems that needs_redraw? is currently broken. Oops! I've opened a ticket here: https://github.com/gosu/gosu/issues/376

What is your use case? In general, everything that involves a Thread is usually a bad idea with Ruby/Gosu, unless you use it purely for game logic. The needs_redraw? method doesn't guarantee that draw will not be called (even though it does that in recent versions of Gosu), it's just an optimisation hint.
Topic Gosu and ChunkyPNG/MiniMagick: Blob length mismatch By jlnr Date 2017-01-12 06:41
Hm, not sure what MiniMagick::Image#to_blob is good for, it just seems to read a file (expand the source code): http://www.rubydoc.info/github/minimagick/minimagick/MiniMagick%2FImage%3Ato_blob

MiniMagick has an import_pixels method that can import a "blob" (as defined by Gosu), but I can't find the other direction.

This StackOverflow answer also doesn't lead anywhere: http://stackoverflow.com/questions/7152362/return-array-of-pixel-values-using-ruby-and-mini-magick-or-rmagick

It's probably easier to read the image from disk with Gosu.
Topic Gosu and ChunkyPNG/MiniMagick: Blob length mismatch By jlnr Date 2017-01-12 06:32
Gosu expects raw RGBA pixel data in the string, and Canvas#to_blob returns compressed data. The return value of to_blob has to have a length of either columns * rows * 4 or columns * rows * 16 (the latter is rare, when float RGBA values).

Looking at the ChunkyPNG docs, I think to_rgba_stream returns something that can be used with Gosu. In that case, you should probably create a wrapper for ChunkyPNG::Canvas instead of monkey-patching Canvas and changing the names. Example (untested):

module ChunkyPNG
  class Canvas
    GosuWrapper = Struct.new(:columns, :rows, :to_blob)
    def to_gosu
      GosuWrapper.new(@width, @height, to_rgba_stream)
    end
  end
end
...
Gosu::Image.new(my_canvas.to_gosu)


Does that work?
Topic Gosu 0.11.0 released By jlnr Date 2017-01-06 16:42
Internally, this is a huge release. The C++ codebase has been completely modernised.

In Ruby/Gosu, the only noticeable change is that it is now possible to resize the window at runtime, and to switch between fullscreen and windowed mode.

If this release turns out to be relatively stable, then I'll build a new Ruby.app for macOS, and Gosu 1.0.0 will be the next step. Everything that is missing is a little refactoring of the text rendering: https://github.com/gosu/gosu/issues?q=is%3Aopen+is%3Aissue+milestone%3A1.0

• Windows: This releases bundles SDL 2.0.5, users on other operating systems should update this library through their package manager
• All: Rename GOSU_COPYRIGHT_NOTICE to Gosu::LICENSES, its content is now platform-specific (thanks @Kjarrigan)
• C++: Use UTF-8 encoded std::string instead of std::wstring throughout Gosu (breaking change)
• C++: Use snake_case for function and method names, just like in Ruby (breaking change)
• All: Window::resize (C++), new setters: Window#width=/#height=/fullscreen= (Ruby); thanks to @Dahrkael for the initial resize implementation
• All: New setter Window#update_interval=
Topic Need Help Actually Releasing a Game By jlnr Date 2016-12-12 14:44
This is the canonical macOS wrapper for Ruby/Gosu code: https://github.com/gosu/ruby-app

Moving code into Ruby.app should work just fine on Linux, as long as you are careful not to lose the executable bit on Ruby.app/Contents/MacOS/Ruby (which can happen if you create a ZIP archive). Just move your code in there, edit Info.plist, create a tarball and mail it to your Mac friends. They'll probably have to right-click and then 'Open' it because the .app isn't code-signed.

Ocra is the most common solution for Windows, but Releasy has another solution that is supposed to work from Linux:

https://github.com/Spooner/releasy/blob/master/lib/releasy/windows_wrapper_maker.rb

As far as I can tell, it bundles your game with the contents of a RubyInstaller package, and then creates a tiny EXE stub that runs rubyw.exe <your_game.rb>? You could give it a try - even though Releasy's README is outdated, that part of the code might still work with the current version of everything.
Topic New experimental subreddit By jlnr Date 2016-12-11 20:42
Fixed Emoji. ??
Topic New experimental subreddit By jlnr Date 2016-12-10 00:02
Hey everyone. There's an experimental subreddit for Gosu now:

https://www.reddit.com/r/gosu/

I've also linked it from the libgosu.org sidebar and put a big, red badge next to it.

If you like the current board (I do…), don't worry. Its contents aren't going anywhere, and I'll keep fixing little things (Emoji should work after I update to a better MySQL Unicode encoding).

But given that the mwForum software is not being actively developed anymore, I wanted to find out whether there are any redditors among us, and maybe a subreddit will turn out to be more accessible than this oldschool Perl/CGI board.

Let me know your thoughts, here or there :)
Topic We're on Homebrew! By jlnr Date 2016-11-29 20:10
Awesome! Thanks.

Funny coincidence, SDL 2.0.5 was my first contribution to Homebrew just recently. Have you done any research into how to keep the formula up-to-date automatically? Not that I'm releasing a lot recently...

Feel free to edit the Getting Started page before I get to it :) It should probably come before CocoaPods, since all Gosu users on macOS are bound to use Homebrew already for sdl2.

I've been working on the Gosu front page itself for the last couple of evenings. I want to have one separate page for the introduction, Ruby, C++ and iOS each. Mixing Ruby and C++ content on the same page is always so confusing... I'll add a note there too.
Topic We're on Homebrew! By jlnr Date 2016-11-29 20:00
Yeah, I've also found out about that the hard way (truncated post). I guess it is an issue with Unicode support in my MySQL table. A friend has helped me snatch the Gosu subreddit so that's something I might try to replace this forum with in the very, very long term. (The mwForum software has been discontinued.)
Topic How does the Map Class in Captain Ruby work? By jlnr Date 2016-11-16 23:21
Using .times is shorter than the for ... in loop, but I have to agree it's hard to read. Glad that you asked about it, I'll make a note to change it :)
Topic Little Raycaster I Made :) By jlnr Date 2016-11-07 09:07
subimage only uses one or two object allocations, and yes, it only references the texture data.

Looking at the C++ source again, I think that you also render walls line by line, right (vertically)? Then Rubystein probably uses the same logic as your raycaster, except they didn't even bother colouring the floor and ceiling - that's why it's fast enough in Ruby.

The old Gosu Showcase board has a screenshot: https://www.libgosu.org/cgi-bin/mwf/topic_show.pl?pid=557

I don't think that the interop between Ruby and C++ is the issue, after all many core Ruby methods (Array#each etc.) are written in C. It's probably the loop itself that's excruciatingly slow in Ruby.
Topic Little Raycaster I Made :) By jlnr Date 2016-11-06 10:57
Cool stuff! I like your fearless use of calling .subimage() just to create temporary image slices! I've never thought about that before, but performance-wise that's perfectly fine.

Are you aware of this ancient Ruby/Gosu raycaster? https://github.com/zenkalia/rubystein
It was originally written by the Phusion team as a parody of the Rails dev world (lots of in-jokes). To avoid setPixel they used the Wolf3D approach to draw vertical lines. So not W*H setPixel() calls, but W Image#draw calls.

I guess the next step would be a voxel engine :P
Topic Sector Five from Learning Game Programming w/Ruby By jlnr Date 2016-10-30 22:08
def draw needs to be inside the body of class SectorFive to override the empty method "draw" in the Gosu::Window base class:

class SectorFive < Gosu::Window

  ..
  def draw
    ..
  end
end


You have defined a global method called draw, which is never called by anybody.
Topic Wizardz: the PvP energy management game! By jlnr Date 2016-10-30 10:16
Oooohhh...took me a while to get it, it's like Galcon except that you build your own planets and can add wizards, if that makes sense. :) Will try to find a second player to PvP.

I ran it from source and scrolled around a little, so I have two quick suggestions for saving valuable bytes: There'a draw_rect method now, which is a lot shorter than using draw_quad for rectangles, and array[rand(array.length)] is just array.sample in current Ruby versions (since 1.9.3 maybe? - not sure).
Topic Blank window on Raspberry Pi / Raspbian By jlnr Date 2016-10-19 21:58
Wow, that's great to hear. That's an original Pi, right? The tutorial was written before Jessie, I've quickly updated it:

https://github.com/gosu/gosu/wiki/Getting-Started-on-Raspbian-(Raspberry-Pi)

Does audio work even after disabling pulseaudio and esd?
Topic Controlling window/application focus By jlnr Date 2016-10-15 08:30
Thanks!

If the Pi 3 is running a regular Linux distro, you can use a scriptable window manager that can bring windows to the foreground if necessary. I've built a Kiosk running Gosu and a video player on Linux once and scripted Sawfish to manage windows (z-order, focus, all that):
http://sawfish.tuxfamily.org

On OS X, you should be able to do the same thing with AppleScript :) You probably have to wrap your script as an .app to do so:

osascript -e 'tell application "My App Name" to activate'
Topic Controlling window/application focus By jlnr Date 2016-10-13 20:35
I don't think there's a platform-independent way to handle this. Which version of the Raspberry Pi are you deploying to? The original Pi only supports running Gosu in full-screen and is a little tricky to set up, so you might not be able to reuse the same logic as on your Mac. And the tutorial has not yet been updated for the Pi 2/3. Just a little heads-up that getting Gosu to work on the Pi is still tricky. :(
Topic Cannot install gosu gem on Mac OS X By jlnr Date 2016-09-24 09:05
I am not sure if it was you who provided a fix for this via GitHub, or if it was just fortunate timing :)

Anyway, I've released a pre-release gem that you should be able to install on Yosemite without installing another Ruby version (so disregard what I wrote above):

sudo gem install --pre

Let me know if this fixes the issue.
Topic Cannot install gosu gem on Mac OS X By jlnr Date 2016-09-23 20:39
Edit: See post below!

Oh man, Apple's Ruby is terrible. It's trying to compile Gosu for both 32-bit and 64-bit, even though OS X doesn't even run on 32-bit systems anymore, and the 32-bit build fails. It works on my 10.11 machine though, which doesn't make debugging any easier.

As a workaround, you can install Ruby from homebrew (brew install ruby), or use rbenv/ruby-install (also in homebrew) to install a specific version of Ruby. Gosu should build without issues then (you won't need the sudo before gem install anymore, though).
That way, you'll have be running the most recent version of Gosu (0.10.8 is the latest) AND Ruby! :)

Also, you don't need to brew install libogg libvorbis anymore. sdl2 is the only dependency.
Topic Problem when creating a window By jlnr Date 2016-09-19 13:09
Thanks! I'll try to trigger some errors here and there on my system. I suspect that there is a useful error message somewhere, but Gosu's (slightly hacky) error handling turns the more useful error into a stack overflow.
Topic Problem Installing Gosu on Raspberry Pi By jlnr Date 2016-09-17 09:48
Hm. :/ The one thing I can still suggest is to re-compile SDL2 without OpenGL, just to be sure it doesn't try to use normal (non-ES) OpenGL. There's a full command-line here for the Pi 2 (which should also apply for the Pi 3): https://solarianprogrammer.com/2015/01/22/raspberry-pi-raspbian-getting-started-sdl-2/

If that doesn't help, I'm out of ideas - no idea how to debug the black screen.
Topic Problem when creating a window By jlnr Date 2016-09-17 09:11
Strange. As for the stack overflow bug, could you please retry with a different version of Ruby? 2.3.1 or 2.2.x.

The second case sounds a bit more complicated =/
Topic Problem when creating a window By jlnr Date 2016-09-17 07:16
Ouch. What operating system are these computers running? Was it windowed or fullscreen mode that failed? Was there more information in the system stack error in the first case?
Topic 1010! - a Gosu Based Board Game By jlnr Date 2016-09-11 09:01
The drag and drop is nice but tiles do still appear at an unpredictable offset. And after dragging the pink L for a few times, I ended up with a pink square in the preview area - see screenshot.

I thought it was interesting that you use Marshal for saving, but only in MRI, not mruby. Later I found out that Marshal doesn't come with mruby by default. I guess that explains it :) If you want to keep mruby compatibility but don't want to use any mruby gems (Marshal, JSON, YAML etc.), then I think I'd just go with string parsing in both versions of Ruby. That would make it more consistent at least.

Re: mruby and Gosu, that doesn't work yet, sorry. I've given it a try when mruby was really new (and crashy) and then simply forgot about it. It's good to see that mruby has a better concept for gems now, but I'm not sure if wrapping a heavy C++ library like Gosu will be easy. It's definitely on my list of potential weekend projects, but that list hasn't gotten any shorter in the last years ;(
Attachment: pinksquare.png (32k)
Topic Problem Installing Gosu on Raspberry Pi By jlnr Date 2016-09-11 08:07
Ouch, this line is the actual error:

/usr/bin/ld: /opt/SDL2/lib/libSDL2.a(SDL_dynapi.o): relocation R_ARM_THM_MOVW_ABS_NC against 'a local symbol' can not be used when making a shared object; recompile with -fPIC

Do you have a /opt/SDL2/lib/libSDL2.so file as well? Can you please try passing that in, instead of the static .a library?
Topic Trying a simple Atlantis remake By jlnr Date 2016-09-11 08:04
Not sure about the second stage. But if you add retro: true to every Image.new call, the game will look splendid in full-screen mode ;)
Topic Problem Installing Gosu on Raspberry Pi By jlnr Date 2016-09-10 18:18
I forgot to escape the quotes, can you please try this instead:

sudo gem install gosu -- --with-cppflags=\"-I/opt/SDL2/include -I/opt/vc/include\" --with-ldflags=\"/opt/SDL2/lib/libSDL2.a /opt/SDL2/lib/libSDL2_ttf.a\"

If it still doesn't work - what's the output in the mkmf.log / gem_make.out file that are mentioned in the error?
Topic Problem Installing Gosu on Raspberry Pi By jlnr Date 2016-09-10 09:06
Should be:
--with-cppflags="-I/opt/SDL2/include -I/opt/vc/include", without the GLES because the #include already includes that part.

Thinking about it, you shouldn't need --with-cflags= at all since Gosu only uses C++, no C.
Topic Problem Installing Gosu on Raspberry Pi By jlnr Date 2016-09-10 08:10
I have no experience with the later Raspberry Pi models, only the original one running Raspbian.

Do you have any idea where the GLES headers might be?

../../src/Graphics/Common.hpp:20:21: fatal error: GLES/gl.h: No such file or directory

Maybe they're in the popular /opt/vc/include directory again? If you can find gl.h and pass the directory in via --with-cflags/--with-cppflags, you should get one step further. Not sure what comes next - probably finding the right library to link against :)
Topic Allow SW fullscreen mode ? By jlnr Date 2016-08-31 19:40
Sorry about that. Automatically downscaling the window has caused all sorts of confusion, and I'm not sure if it's even necessary anymore. I added it as a hotfix for some version of Windows, where windows larger than the desktop were completely unusable (Windows always force-minimised them).

I've created an enhancement ticket here: https://github.com/gosu/gosu/issues/341

Also, Gosu 0.8+ should use software fullscreen (like video players...), does it not work for you? Which version of SDL 2 are you using?
Topic Clipping bug on fullscreen By jlnr Date 2016-08-31 19:36
Hmm, using the right coordinates for clip_to is a little tricky, but I see what I can do. I've opened https://github.com/gosu/gosu/issues/340 to track this issue.

Thanks for reminding me - I've seen it before in my own game and ignored it *cough* ;)
Topic Gosu 0.10.8 released By jlnr Date 2016-08-21 11:01
There's also a new Ruby.app wrapper with Gosu 0.10.8 and Ruby 2.3.1, for OS X 10.7+:

https://github.com/gosu/ruby-app/releases
Topic Billiard (pool) game By jlnr Date 2016-08-17 20:17
It's a pity that this is such a low-traffic place, because this little game is great. Really solid work on the controls & fantastic physics without using a physics engine :) Thanks for sharing!
Topic Gosu 0.10.8 released By jlnr Date 2016-08-15 21:57
This is a minor maintenance release:

• Mac: Fix several compilation issues
• All: Map analog trigger buttons in SDL_GameController API to GpButton constants
• Ruby: Gosu::Color can now safely be used as a Hash key (thanks to @shawn42 for the contribution)
Topic Marco - An isometric exploration/city building game By jlnr Date 2016-08-14 10:31
The shader is a great idea and a really nice touch, I wonder if it could be animated too. Thanks for sharing this little detail! Good luck with your game :)
Topic Billiard (pool) game By jlnr Date 2016-08-14 07:23
The download from mega.nz doesn't work for me, can you please attach the file to your posting? ("attach" link in the post's footer.)
Topic 1010! - a Gosu Based Board Game By jlnr Date 2016-08-13 17:53
Ah, turn-based 2D tetris, in a way! I think it's a clever concept, and it could work really well with some more polish.

The game would be much easier to play if one could see the currently selected tile as an overlay next to the mouse cursor.

The save-game code is really interesting, and you have some checks for mruby in there - have you built an mruby version a well?
Topic Simple card memory game demo By jlnr Date 2016-08-01 19:28

> Re: the distribution thing, you should check out Releasy. There's a link on the Gosu homepage.


I would like to add: if you get stuck using Releasy, you can also try using Ocra first (Releasy wraps the Ocra tool, among others). Ocra is conceptually simple - all it does is to stuff your game into a self-extracting EXE file that will run your game out of a temporary folder. If everything works with Ocra but not with Releasy, you know it's an issue with your Releasy configuration.

https://github.com/larsch/ocra
Topic Simple card memory game demo By jlnr Date 2016-08-01 19:21
I haven't run the game, only scrolled over it on GitHub, but this is what I noticed:

It is not necessary to spell out the ".rb" when using require or require_relative:
https://github.com/boyanpn/gosu_memory/blob/cba1ae6d93d76bd661b03a70216f3ae15de2f2ed/start.rb#L3-L4

Because there's usually only one Window, you don't need to use @@class_variables here:
https://github.com/boyanpn/gosu_memory/blob/cba1ae6d93d76bd661b03a70216f3ae15de2f2ed/start.rb#L18-L19
Likewise, $current_room doesn't need to be a global variable, I think.

You don't need the {} around hash argument lists:
https://github.com/boyanpn/gosu_memory/blob/cba1ae6d93d76bd661b03a70216f3ae15de2f2ed/start.rb#L62-L78
Just Font.new(18, :name => "foo") is enough.

When you call Window#close, it's usually best to return from the method (instead of forwarding the button press, in this case):
https://github.com/boyanpn/gosu_memory/blob/cba1ae6d93d76bd661b03a70216f3ae15de2f2ed/start.rb#L41-L47

Loading each image individually leads to a lot of copy & paste here:
https://github.com/boyanpn/gosu_memory/blob/cba1ae6d93d76bd661b03a70216f3ae15de2f2ed/start.rb#L62-L65
Probably better to create these images from an array of names:
%w(camel-head donkey frog ...).each_with_index do |name, index|
  @images[index + 1] = Gosu::Image.new("images_animals/#{filename}.png", :retro => true)
end


This can be simplified to if @cards.compact.empty?:
https://github.com/boyanpn/gosu_memory/blob/cba1ae6d93d76bd661b03a70216f3ae15de2f2ed/state_playgame.rb#L98
I think the design of this method is unconventional too, it both answers a question (is the game over?) as well as setting the best_time. I'd rename it to game_ended? and move the assignment to best_time into button_up, into the if game_ended... block.

Most of it is nitpicking, but I think that's what you asked for - hope that helps :)

You could also try the Rubocop tool for (very superficial) feedback on the way you format and structure your code. I don't agree with its default settings at all, but sometimes it'll point out something useful.

Edit: One more thing, you might want to look into Bundler and commit the Gemfile and Gemfile.lock. That way, it is clear (without reading the README) which version of Gosu you used to develop your game. This makes it a lot easier to other people to debug issues such as running the game with a version of Gosu that's too old (say, 0.7.50). This applies to all sorts of Ruby projects.
Topic get clicked pixel color By jlnr Date 2016-07-20 20:01
Yes, but enable_undocumented_retrofication was a only temporary hack while I was working on the :retro flag, which is the new way of doing things: Image.new("filename.png", retro: true)
Topic get clicked pixel color By jlnr Date 2016-07-05 23:36
You can use gl_tex_info to read out the pixels in an image using OpenGL, but that's exactly what Image#to_blob is doing for you, except that you need an extension to make use of gl_tex_info (the opengl gem).

The Image#[] method I've linked to is the exact equivalent of the Löve2D function you've mentioned. But if you need a way to read out an individual image's pixels _under the mouse cursor_, you also need to know where each image has been drawn. You can't take a screenshot of the window and read individual pixels from that (at least not without extensions).

When implementing a Risk map, you have all the information you need: An image for each country plus its x/y coordinate on the world map. When the user clicks, you can iterate over all your images and read out the pixel using @country_image[(mouse_x - @image_left).to_i, (mouse_y - @image_top).to_i]. If pixel[3].ord != 0, the pixel is not transparent.

(I've extended Image#[] with some bounds checking in the old post I've linked to above. Also, :retro only sets a few OpenGL parameters that change how the image is rendered when it is stretched or rotated, it does not affect the image's pixel data.)
Topic get clicked pixel color By jlnr Date 2016-07-05 16:31
This question came up just last month, hidden in this thread:

https://www.libgosu.org/cgi-bin/mwf/topic_show.pl?pid=8924#pid8924

You will still need to remember which image was drawn at which position, though.
Topic Any way for a file drag and drop ? By jlnr Date 2016-06-20 19:37
There is an SDL event we could use for this: https://wiki.libsdl.org/SDL_DropEvent

...but I would still prefer it if a Ruby GUI toolkit finally emerged that handled all of this for us :(

If you only need to do this on Windows, you can probably use the funky win32-api gem to install a hook of type WH_CALLWNDPROC:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx

And then when you receive the WM_DROPFILES message, you need to call the Drag* functions to figure out the filename:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774303(v=vs.85).aspx

It will be either easy or hard depending on how familiar you are with this gem :)
https://github.com/cosmo0920/win32-api

Edit: It turns out that the DragQueryFile function is already defined in this companion gem:
https://github.com/cosmo0920/windows-pr/blob/master/lib/windows/shell.rb#L141

And here is someone who has successfully used SetWindowsHookEx with the win32-api gem:
https://github.com/ffi/ffi/issues/283#issuecomment-24902987

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill