Re: interactive map?




> i'm currently working on a game using gtk.
> i have the following problem and not much ideas how to overcome it:
> 
> one of the windows will be a map window. it's the main window actually, that's
> why there's a menubar on it. so the layout roughly is:
> 
> 
>         +--------------------+
>         | file options  help |
>         |--------------------|
>         |                    |
>         |       the map      |
>         |      comes here    |
>         |                    |
>         |--------------------|
>         | statusbar          |
>         +--------------------+
> 
> the problems:
> 
> - the map is loaded from an xpm (or other image file). different maps have
>   different sizes. maps can be loaded without leaving this window. so how do
>   i find out the image size and how do i automatically resize this window
>   so it fits the map?

Well, one way of doing it is just to make a Pixmap widget from
the map, and let that handle the size. Or you could query the
size yourself with gdk_window_get_size (pixmap, &x, &y), and
set the usize on whatever you are drawing.
 
> - is there a somewhat simple and elegant way to automatically scale the map
>   if the window is resized? to allow only proportional resizes of the window?

Not really - X does have WM hints way of doing this. (You define
a base size for the window, then an aspect ratio for the remaining
part). But GTK doesn't support this, and I'm not sure most WM's
do either. But what you can do is let the user pick any size they
want, and then use an AspectFrame to make sure that the map you
actually draw has the right aspect ratio.
 
For scaling the map, see imlib, as people have said.

> - how do i get events on the map? the map shall be interactive, so i have to
>   know that the player clicked on it, where he clicked and with what button.
>   but pixmaps don't seem to receive events.

Put the pixmap in an EventBox and get events on the event box.
 
> - the most simple one last: if the map is so small that even after resizing
>   it doesn't fill all of the map-window (i.e. width is smaller than the min
>   width of the menubar), how do i fill the background with, say, black? i
>   tried it with styles, but oddly it changed the style of the menubar instead.

If you leave the eventbox there, you can just change its style,
or perhaps easier, force realize it, (gtk_widget_realize),
set its background to black (gdk_window_set_background), and
clear the window so that it changes to that color 
(gdk_window_clear).

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]