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]. <code>HildonAnimationActor</code> 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 <code>GtkWidget</code>, <code>main</code>, into a <code>HildonAnimationActor</code>.
+
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 <code>main</code> is 320&times;240, and that you want to scale the window to 800&times;424.
+
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&times;240, and that you want to scale the window to 800&times;424.
-
<source lang="c">
+
<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>
-
</source>
+
-
This will scale <code>main</code> and display it over <code>window</code>. <code>HildonAnimationActor</code>, however, does not accept any input events, so all keyboard and mouse events will pass directly through to <code>window</code>. 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.
+
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.
-
<source lang="c">
+
<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>
-
</source>
+
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 <code>HildonAnimationActor</code> and redirects button press and release events to the widget
+
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
-
<source lang="c">
+
<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>
-
</source>
+
[[Category:Development]]
[[Category:Development]]
[[Category:Documentation]]
[[Category:Documentation]]
[[Category:Fremantle]]
[[Category:Fremantle]]

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)