1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 
3 #include <stdio.h>
4 #include "gx_api.h"
5 #include "gx_canvas.h"
6 
7 #include "all_widgets_1bpp_resources.h"
8 #include "all_widgets_1bpp_specifications.h"
9 
10 extern VOID memory_free(VOID *mem);
11 
12 float            x_ratio = 1;
13 float            y_ratio = 1;
14 GX_RESOURCE_ID   resize_pixelmap_id = GX_PIXELMAP_ID_ICON_FOOT;
15 
update_prompt_text(GX_RESOURCE_ID id,float value)16 VOID update_prompt_text(GX_RESOURCE_ID id, float value)
17 {
18     GX_PROMPT *pp;
19     static GX_CHAR text[10];
20     GX_STRING string;
21     INT index = 0;
22 
23     gx_widget_find((GX_WIDGET *)&resize_screen, (USHORT)id, 0, &pp);
24 
25     if (pp)
26     {
27         /* Transfer float value to string. */
28         text[index++] = '0' + (int)(value);
29         text[index++] = '.';
30         text[index++] = '0' + (int)(value * 10) % 10;
31         text[index++] = '0' + (int)(value * 100) % 10;
32         text[index] = '\0';
33 
34         /* Reset prompt text. */
35         string.gx_string_ptr = text;
36         string.gx_string_length = index;
37         gx_prompt_text_set_ext(pp, &string);
38     }
39 }
40 
resize_screen_event_handler(GX_WINDOW * window,GX_EVENT * myevent)41 UINT resize_screen_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
42 {
43     UINT status = 0;
44     INT  value;
45 
46     switch (myevent->gx_event_type)
47     {
48     case GX_SIGNAL(ID_SLIDER_WIDTH, GX_EVENT_SLIDER_VALUE):
49         value = myevent->gx_event_payload.gx_event_longdata;
50         value -= 50;
51         x_ratio = 1 + (float)value / 100;
52         update_prompt_text(ID_WIDTH_DISPLAY, x_ratio);
53         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
54         break;
55 
56     case GX_SIGNAL(ID_SLIDER_HEIGHT, GX_EVENT_SLIDER_VALUE):
57         value = myevent->gx_event_payload.gx_event_longdata;
58         value -= 50;
59         y_ratio = 1 + (float)value / 100;
60         update_prompt_text(ID_HEIGHT_DISPLAY, y_ratio);
61         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
62         break;
63 
64     case GX_SIGNAL(ID_RADIO_FOOT, GX_EVENT_RADIO_SELECT):
65         resize_pixelmap_id = GX_PIXELMAP_ID_ICON_FOOT;
66         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
67         break;
68 
69     case GX_SIGNAL(ID_RADIO_FOOT_ALPHA, GX_EVENT_RADIO_SELECT):
70         resize_pixelmap_id = GX_PIXELMAP_ID_RED_APPLE;
71         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
72         break;
73 
74     case GX_SIGNAL(ID_RADIO_FISH, GX_EVENT_RADIO_SELECT):
75         resize_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FISH;
76         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
77         break;
78 
79     default:
80         status = next_button_handler(window, myevent);
81         break;
82     }
83     return status;
84 }
85 
resize_window_draw(GX_WINDOW * window)86 VOID resize_window_draw(GX_WINDOW *window)
87 {
88     INT  xpos;
89     INT  ypos;
90     GX_PIXELMAP *pixelmap;
91     GX_RECTANGLE win_size;
92     GX_PIXELMAP destination;
93     INT width, height;
94 
95     gx_window_draw((GX_WINDOW*)window);
96 
97     gx_context_pixelmap_get(resize_pixelmap_id, &pixelmap);
98     win_size = resize_screen.resize_screen_resize_window.gx_widget_size;
99 
100     xpos = (win_size.gx_rectangle_right + win_size.gx_rectangle_left -pixelmap->gx_pixelmap_width) >> 1;
101     ypos = (win_size.gx_rectangle_top + win_size.gx_rectangle_bottom - pixelmap->gx_pixelmap_height) >> 1;
102 
103     width = (int)(pixelmap->gx_pixelmap_width * x_ratio);
104     height = (int)(pixelmap->gx_pixelmap_height * y_ratio);
105 
106     if (x_ratio == 1 && y_ratio == 1)
107     {
108         /* Draw source pixelmap.  */
109         gx_canvas_pixelmap_draw(xpos, ypos, pixelmap);
110     }
111     else if (gx_utility_pixelmap_resize(pixelmap, &destination, width, height) == GX_SUCCESS)
112     {
113         xpos += (pixelmap->gx_pixelmap_width - destination.gx_pixelmap_width) >> 1;
114         ypos += (pixelmap->gx_pixelmap_height - destination.gx_pixelmap_height) >> 1;
115 
116         /* Draw resized pixelmap.  */
117         gx_canvas_pixelmap_draw(xpos, ypos, &destination);
118 
119         if (destination.gx_pixelmap_data)
120         {
121             memory_free((VOID *)destination.gx_pixelmap_data);
122         }
123 
124         if (destination.gx_pixelmap_aux_data)
125         {
126             memory_free((VOID *)destination.gx_pixelmap_aux_data);
127         }
128     }
129 }
130