News:

Want to praise Simutrans?
Your feedback is important for us ;D.

zoom mode, change - where in code

Started by leopard, March 23, 2009, 08:53:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

leopard

assume, for the sake of argument, that some nitwit wanted to be notified whenever the screen zoom changed.

nothing fancy, just where is the relevant keyboard event handled?

thinking the main event loop, which I've not yet found, that handles the keypress, so if I, sorry a nitwit,  wanted to put a notification hook to a custom function when the screen zoom level changed they could work out where to put it.

also is the current zoom level, or scaling factor held anywhere in an object, or simple variable (in the case of an object so the setter could gain the notification 'event')?

asking since I'd like to replace the 'zoom in' & 'zoom out' buttons on my navigation window with a slider, wouldn't be too hard to make that work to set the zoom level, its just altering it when the game changes it, i.e. the feedback.

as an aside where is the main event loop than handles keypresses? since other feedback events could be inserted.

I've had a scan through the code but not found anything obvious, sadly I speak German with the skill of the average English nitwit (i.e. not at all), and despite a recent trip to Holland indicating just how many Europeans speak multiple languages my lingustic skills are still limited to growling...
My Simutrans on the apple mac homepage http://www.aleopardstail.com/simutrans/Index.html

Dwachs

Quote from: leopard on March 23, 2009, 08:53:07 PM
so if I, sorry a nitwit,  wanted to put a notification hook to a custom function when the screen zoom level changed they could work out where to put it.
look in simwerkz.h / wkz_zoom_in_t::init and wkz_zoom_out_t::init
Quote
also is the current zoom level, or scaling factor held anywhere in an object, or simple variable (in the case of an object so the setter could gain the notification 'event')?
the zoom level is hidden in the simgraph modules. one can use get_tile_raster_width() to get an indication of the zoom.

Quote
asking since I'd like to replace the 'zoom in' & 'zoom out' buttons on my navigation window with a slider, wouldn't be too hard to make that work to set the zoom level, its just altering it when the game changes it, i.e. the feedback.

as an aside where is the main event loop than handles keypresses? since other feedback events could be inserted.

the main loop is in simmain.cc line 824
events are handled in karte_t::interactive() and karte_t::interactive_event() (scrolling, esc, f1)
window events in simwin.cc / check_pos_win()
keyboard events are sent to the window that has the focus
Parsley, sage, rosemary, and maggikraut.

prissi

SInce the simutrans screen code is independent of the zoom of the actual windows, I fail to see the need of a hook. Thinking of interdependence I would avoid it. And a said, bz comparing base tile size and tile size, you can calculate the zoom factor.

leopard

thanks, i'll have a look, calculating the zoom isn't an issue, I hope. just thinking of a GUI slider to adjust it, which would need to know if anything else alters it, so it can update.

simply calling a method to poke the slider to find out what it needs to show whenever the system changes is more than enough. I shall have a fiddle.
My Simutrans on the apple mac homepage http://www.aleopardstail.com/simutrans/Index.html

leopard

part one working, i.e. a GUI with a slider that can set the zoom level in a nice friendly way (not that I have anything against a keyboard interface, but I'm using a laptop)

oh the joys of getting objective-c to talk to c++, they get on like a house on fire, people screaming, running for cover etc.

essentially I'm calling "set_zoom_factor(int z)" directly from the sliders event handler, it works, maybe not the best way to handle it but it works
My Simutrans on the apple mac homepage http://www.aleopardstail.com/simutrans/Index.html

leopard

Now working correctly, few issues to do with getting objective-c to talk to c++, and vice-versa

now have a cocoa window, with a slider. adjusting that slider sets the zoom in the game window, that bit was reasonably simple. it doesn't do it by simulating keypresses though, it calls set_zoom_factor(); directly with a suitable value. this bit was reasonably simple.

the fun bit was getting simutrans to call an objective-c routine, so that when you use the '<' and '>' keys to zoom in & out the GUI slider moves to show the current zoom level.

if any one is interested this will be posted, along with source code, next time I put this up. but there are one or two other bits I want to polish up first. the mothod is actually very simple.

create a basic "c" file, not c++ or objective-c, in this put a few simple functions. simutrans calls these, which then call the objective-c. this works both ways, hence simutrans thinks its calling a "c" function and doesn't know about the objective-c or cocoa bits.

I don't have the resources to do it, but this would allow for example a similar interface to the windows GUI to be implemented. it would also allow code in other languages to be used, e.g. maybe visual basic?

anyway this is what it currently looks like, the compass (which needs a new graphic) provides eight way scrolling via mouse clicks



My Simutrans on the apple mac homepage http://www.aleopardstail.com/simutrans/Index.html