rtt-f030/examples/gui/demo_view_instrument_panel.c

150 lines
3.7 KiB
C
Raw Normal View History

/*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>container<EFBFBD>Ͻ<EFBFBD><EFBFBD><EFBFBD>DC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
*/
#include "demo_view.h"
#include <rtgui/dc.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/slider.h>
#include <rtgui/image_hdc.h>
#include <math.h>
/*
* container<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
rt_bool_t instrument_panel_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
char ac[4];
int i;
int x0 = 120;
int y0 = 170;
int x, y;
int default_color;
/* <20><><EFBFBD><EFBFBD>PAINT<4E>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD> */
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
rtgui_rect_t rect;
const int arrowx[] = {120+75, 120+75, 120+85};
const int arrowy[] = {170-5, 170+5, 170};
/*
* <EFBFBD><EFBFBD>Ϊ<EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>demo container<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ֿؼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ͼʱ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>demo container
* <EFBFBD>Ȼ<EFBFBD>ͼ
*/
rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
/************************************************************************/
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44>IJ<EFBFBD><C4B2><EFBFBD> */
/************************************************************************/
/* <20><><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC */
dc = rtgui_dc_begin_drawing(widget);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44><43><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC>򸸿ؼ<F2B8B8BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>DC<44>ǻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ɹ<EFBFBD><C9B9>ģ<EFBFBD> */
if (dc == RT_NULL)
return RT_FALSE;
/* <20><><EFBFBD><EFBFBD>demo container<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
/* <20><>ʾGUI<55>İ汾<C4B0><E6B1BE>Ϣ */
#ifdef RTGUI_USING_SMALL_SIZE
rtgui_dc_draw_text(dc, "RT-Thread/GUIС<49>Ͱ汾", &rect);
#else
rtgui_dc_draw_text(dc, "RT-Thread/GUI<55><49>׼<EFBFBD>", &rect);
#endif
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_CENTER_HORIZONTAL;
RTGUI_DC_FC(dc) = blue;
rect.y2 = 270;
rtgui_dc_draw_text(dc, "rtgui-panel", &rect);
for(i = 0; i < 6; i++)
{
rtgui_dc_draw_arc(dc, x0, y0, 117-i, 150, 30);
}
RTGUI_DC_FC(dc) = black;
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_LEFT;
for(i = 0; i <= 23; i++)
{
if(i < 12)
{
x = x0 + 105 * cos((150 + i * 10) * 3.1415926 / 180);
y = y0 + 105 * sin((150 + i * 10) * 3.1415926 / 180);
rect.x1 = x;
rect.y1 = y;
rect.x2 = rect.x1 + 12 * 3;
rect.y2 = rect.y1 + 12;
rt_sprintf(ac, "%d", 10 * i);
rtgui_dc_draw_text(dc, ac, &rect);
}
else
{
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_RIGHT;
x = x0 + 105 * cos((160 + i * 10) * 3.1415926 / 180);
y = y0 + 105 * sin((160 + i * 10) * 3.1415926 / 180);
rect.x1 = x - 12 * 3;
rect.y1 = y;
rect.x2 = rect.x1 + 12 * 3;
rect.y2 = rect.y1 + 12;
rt_sprintf(ac, "%d", 10 * i);
rtgui_dc_draw_text(dc, ac, &rect);
}
x = x0 + 107 * cos((150 + i * 10) * 3.1415926 / 180);
y = y0 + 107 * sin((150 + i * 10) * 3.1415926 / 180);
rtgui_dc_fill_circle(dc, x, y, 3);
}
RTGUI_DC_FC(dc) = RTGUI_RGB(166, 0, 166);
rtgui_dc_fill_circle(dc, x0, y0, 3);
RTGUI_DC_FC(dc) = RTGUI_RGB(120, 141, 30);
rtgui_dc_draw_circle(dc, x0, y0, 5);
default_color = RTGUI_DC_BC(dc);
RTGUI_DC_BC(dc) = red;
rect.x1 = x0 + 7;
rect.y1 = y0 - 1;
rect.x2 = x0 + 75;
rect.y2 = y0 + 1;
rtgui_dc_fill_rect(dc, &rect);
RTGUI_DC_BC(dc) = default_color;
rtgui_dc_fill_polygon(dc, arrowx, arrowy, 3);
/* <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD> */
rtgui_dc_end_drawing(dc);
}
else
{
/* <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
return rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
}
return RT_FALSE;
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ͼ */
rtgui_container_t *demo_view_instrument_panel(void)
{
rtgui_container_t *container;
container = demo_view("instrument panel Demo");
if (container != RT_NULL)
/* <20><><EFBFBD>ó<EFBFBD><C3B3>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
rtgui_object_set_event_handler(RTGUI_OBJECT(container), instrument_panel_event_handler);
return container;
}