Editing Documentation/Maemo 5 Developer Guide/Porting Software/Scaling Fixed Size Windows
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
+ | = Scaling Fixed-size Windows = | ||
+ | |||
When porting existing applications to Maemo, it is sometimes necessary to scale a fixed-size interface to the target screen size. For example, many games written for a specific gaming platform assume the screen size of that platform. Scaling the interface allows you to port the application without completely rewriting it. | When porting existing applications to Maemo, it is sometimes necessary to scale a fixed-size interface to the target screen size. For example, many games written for a specific gaming platform assume the screen size of that platform. Scaling the interface allows you to port the application without completely rewriting it. | ||
- | You can scale a window with [http://maemo.org/api_refs/5.0/5.0-final/hildon/hildon-HildonAnimationActor.html HildonAnimationActor]. < | + | You can scale a window with <tt>[http://maemo.org/api_refs/5.0/5.0-final/hildon/hildon-HildonAnimationActor.html HildonAnimationActor]</tt>. <tt>HildonAnimationActor</tt> creates an overlay window that can be positioned anywhere on the screen and scaled to any size. The following code demonstrates how to embed a fixed-size <tt>GtkWidget</tt>, main into a <tt>HildonAnimationActor</tt>. |
- | In this code snippet, window is a top-level <tt>[http://maemo.org/api_refs/5.0/5.0-final/hildon/HildonWindow.html HildonWindow]</tt>. It assumes that the original size of < | + | In this code snippet, window is a top-level <tt>[http://maemo.org/api_refs/5.0/5.0-final/hildon/HildonWindow.html HildonWindow]</tt>. It assumes that the original size of <tt>main</tt> is 320×240, and that you want to scale the window to 800×424. |
- | < | + | <pre>actor = HILDON_ANIMATION_ACTOR (hildon_animation_actor_new()); |
- | actor = HILDON_ANIMATION_ACTOR (hildon_animation_actor_new()); | + | |
gtk_container_add (GTK_CONTAINER (actor), main); | gtk_container_add (GTK_CONTAINER (actor), main); | ||
gtk_window_resize (GTK_WINDOW (actor), 320, 240); | gtk_window_resize (GTK_WINDOW (actor), 320, 240); | ||
Line 12: | Line 13: | ||
hildon_animation_actor_set_parent (actor, window); | hildon_animation_actor_set_parent (actor, window); | ||
hildon_animation_actor_set_scale (actor, 2.5, 1.77); | hildon_animation_actor_set_scale (actor, 2.5, 1.77); | ||
- | gtk_widget_show_all (GTK_WIDGET (actor)); | + | gtk_widget_show_all (GTK_WIDGET (actor));</pre> |
- | </ | + | |
- | This will scale < | + | This will scale <tt>main</tt> and display it over <tt>window</tt>. <tt>HildonAnimationActor</tt>, however, does not accept any input events, so all keyboard and mouse events will pass directly through to <tt>window</tt>. To make the application respond to user input, you must capture the relevant events on window and pass them to main. For events which have associated screen coordinates, such as mouse clicks, you must transform the coordinates based on the scaling factor. |
The following code demonstrates how to capture button press and release events from a pointing device. On Maemo-based devices, this corresponds to the press and release of a tap on the screen. | The following code demonstrates how to capture button press and release events from a pointing device. On Maemo-based devices, this corresponds to the press and release of a tap on the screen. | ||
- | < | + | <pre>static void |
- | static void | + | |
window_button_proxy (GtkWidget *widget, | window_button_proxy (GtkWidget *widget, | ||
GdkEventButton *event, | GdkEventButton *event, | ||
Line 34: | Line 33: | ||
G_CALLBACK (window_button_proxy), main); | G_CALLBACK (window_button_proxy), main); | ||
g_signal_connect (window, "button-release-event", | g_signal_connect (window, "button-release-event", | ||
- | G_CALLBACK (window_button_proxy), main); | + | G_CALLBACK (window_button_proxy), main);</pre> |
- | </ | + | |
In this example, we've scaled the original application by different scale factors on the horizontal and vertical axes. To maintain the aspect ratio, you may need to use less than the entire available screen space. In this case, you will need to do more sophisticated coordinate transformations in your event-handling code. | In this example, we've scaled the original application by different scale factors on the horizontal and vertical axes. To maintain the aspect ratio, you may need to use less than the entire available screen space. In this case, you will need to do more sophisticated coordinate transformations in your event-handling code. | ||
- | Finally, the following code implements a simple that draws circles for button presses and releases. It scales this widget with | + | Finally, the following code implements a simple that draws circles for button presses and releases. It scales this widget with HildonAnimationActor and redirects button press and release events to the widget |
- | < | + | <pre>/* |
- | /* | + | |
window-scaler.c | window-scaler.c | ||
gcc -Wall -o window-scaler window-scaler.c \ | gcc -Wall -o window-scaler window-scaler.c \ | ||
Line 158: | Line 155: | ||
gtk_main (); | gtk_main (); | ||
return 0; | return 0; | ||
- | } | + | }</pre> |
- | </ | + | |
[[Category:Development]] | [[Category:Development]] | ||
[[Category:Documentation]] | [[Category:Documentation]] | ||
[[Category:Fremantle]] | [[Category:Fremantle]] |
Learn more about Contributing to the wiki.