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 "partial_frame_buffer_16bpp_resources.h"
8 #include "partial_frame_buffer_16bpp_specifications.h"
9 
10 extern VOID memory_free(VOID *mem);
11 
12 #define RATIO_ONE 100
13 
14 INT x_ratio = RATIO_ONE;
15 INT y_ratio = RATIO_ONE;
16 
17 GX_RESOURCE_ID   resize_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FOOT;
18 
resize_ratio_format(GX_NUMERIC_PROMPT * prompt,INT value)19 VOID resize_ratio_format(GX_NUMERIC_PROMPT *prompt, INT value)
20 {
21     INT index = 0;
22 
23     /* Transfer float value to string. */
24     prompt->gx_numeric_prompt_buffer[index++] = '0' + (value / RATIO_ONE);
25     prompt->gx_numeric_prompt_buffer[index++] = '.';
26     prompt->gx_numeric_prompt_buffer[index++] = '0' + (value % RATIO_ONE) / 10;
27     prompt->gx_numeric_prompt_buffer[index++] = '0' + (value % RATIO_ONE) % 10;
28     prompt->gx_numeric_prompt_buffer[index] = '\0';
29 }
30 
resize_screen_event_handler(GX_WINDOW * window,GX_EVENT * myevent)31 UINT resize_screen_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
32 {
33     switch (myevent->gx_event_type)
34     {
35     case GX_SIGNAL(ID_SLIDER_WIDTH, GX_EVENT_SLIDER_VALUE):
36         x_ratio = myevent->gx_event_payload.gx_event_longdata;
37         gx_numeric_prompt_value_set(&resize_screen.resize_screen_width, x_ratio);
38         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
39         break;
40 
41     case GX_SIGNAL(ID_SLIDER_HEIGHT, GX_EVENT_SLIDER_VALUE):
42         y_ratio = myevent->gx_event_payload.gx_event_longdata;
43         gx_numeric_prompt_value_set(&resize_screen.resize_screen_height, y_ratio);
44         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
45         break;
46 
47     case GX_SIGNAL(ID_RADIO_FOOT, GX_EVENT_RADIO_SELECT):
48         resize_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FOOT;
49         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
50         break;
51 
52     case GX_SIGNAL(ID_RADIO_FOOT_ALPHA, GX_EVENT_RADIO_SELECT):
53         resize_pixelmap_id = GX_PIXELMAP_ID_ROTATE_APPLE;
54         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
55         break;
56 
57     case GX_SIGNAL(ID_RADIO_FISH, GX_EVENT_RADIO_SELECT):
58         resize_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FISH;
59         gx_system_dirty_mark((GX_WIDGET *)&resize_screen.resize_screen_resize_window);
60         break;
61 
62     default:
63         return gx_window_event_process(window, myevent);
64     }
65     return 0;
66 }
67 
resize_window_draw(GX_WINDOW * window)68 VOID resize_window_draw(GX_WINDOW *window)
69 {
70     INT  xpos;
71     INT  ypos;
72     GX_PIXELMAP *pixelmap;
73     GX_RECTANGLE win_size;
74     GX_PIXELMAP destination;
75     INT width, height;
76 
77     gx_window_draw((GX_WINDOW*)window);
78 
79     gx_context_pixelmap_get(resize_pixelmap_id, &pixelmap);
80     win_size = resize_screen.resize_screen_resize_window.gx_widget_size;
81 
82     xpos = (win_size.gx_rectangle_right + win_size.gx_rectangle_left -pixelmap->gx_pixelmap_width) >> 1;
83     ypos = (win_size.gx_rectangle_top + win_size.gx_rectangle_bottom - pixelmap->gx_pixelmap_height) >> 1;
84 
85     width = (pixelmap->gx_pixelmap_width * x_ratio / RATIO_ONE);
86     height = (pixelmap->gx_pixelmap_height * y_ratio / RATIO_ONE);
87 
88     if (x_ratio == RATIO_ONE && y_ratio == RATIO_ONE)
89     {
90         /* Draw source pixelmap.  */
91         gx_canvas_pixelmap_draw(xpos, ypos, pixelmap);
92     }
93     else if (gx_utility_pixelmap_resize(pixelmap, &destination, width, height) == GX_SUCCESS)
94     {
95         xpos += (pixelmap->gx_pixelmap_width - destination.gx_pixelmap_width) >> 1;
96         ypos += (pixelmap->gx_pixelmap_height - destination.gx_pixelmap_height) >> 1;
97 
98         /* Draw resized pixelmap.  */
99         gx_canvas_pixelmap_draw(xpos, ypos, &destination);
100 
101         if (destination.gx_pixelmap_data)
102         {
103             memory_free((VOID *)destination.gx_pixelmap_data);
104         }
105 
106         if (destination.gx_pixelmap_aux_data)
107         {
108             memory_free((VOID *)destination.gx_pixelmap_aux_data);
109         }
110     }
111 }
112