static void _rtgui_plot_draw_curve(struct rtgui_plot *plot, struct rtgui_event *event) { int i; struct rtgui_dc *dc; dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(plot)); if (dc == RT_NULL) return; if (RTGUI_MV_VIEW(plot)->model_number == 1) { _rtgui_plot_curve_onpaint(dc, plot, RTGUI_PLOT_CURVE(RTGUI_MV_VIEW(plot)->model), 0, RTGUI_MV_MODEL(RTGUI_MV_VIEW(plot)->model)->length); } else { void **curve_array = (void **)RTGUI_MV_VIEW(plot)->model; for (i = 0; i < RTGUI_MV_VIEW(plot)->model_number; i++) { _rtgui_plot_curve_onpaint(dc, plot, RTGUI_PLOT_CURVE(curve_array[i]), 0, RTGUI_MV_MODEL(curve_array[i])->length); } } rtgui_dc_end_drawing(dc); }
struct rtgui_container* demo_plot(void) { struct rtgui_container *cnt; struct rtgui_plot_curve *curve1, *curve2, *curve3; struct rtgui_plot *plot; struct rtgui_rect rect; cnt = demo_view("ÇúÏß»æͼ"); plot = rtgui_plot_create(); curve1 = rtgui_plot_curve_create(); rtgui_plot_curve_set_y(curve1, sin_ydata); RTGUI_MV_MODEL(curve1)->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]); curve1->min_x = 0; curve1->max_x = sizeof(sin_ydata)/sizeof(sin_ydata[0]); curve1->min_y = -100; curve1->min_y = 100; curve1->color = red; rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve1), RTGUI_MV_VIEW(plot)); curve2 = rtgui_plot_curve_create(); rtgui_plot_curve_set_y(curve2, cos_ydata); RTGUI_MV_MODEL(curve2)->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]); curve2->min_x = 0; curve2->max_x = sizeof(cos_ydata)/sizeof(cos_ydata[0]); curve1->min_y = -50; curve1->min_y = 50; curve2->color = blue; rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve2), RTGUI_MV_VIEW(plot)); curve3 = rtgui_plot_curve_create(); rtgui_plot_curve_set_x(curve3, cos_ydata); rtgui_plot_curve_set_y(curve3, sin_ydata); RTGUI_MV_MODEL(curve3)->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]); curve3->color = black; rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve3), RTGUI_MV_VIEW(plot)); rtgui_widget_get_rect(RTGUI_WIDGET(cnt), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(plot), &rect); rtgui_plot_set_base(plot, -rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2); rtgui_container_add_child(cnt, RTGUI_WIDGET(plot)); return cnt; }
static void _rtgui_plot_update_scale(struct rtgui_plot *plot) { struct rtgui_plot_curve *curve; struct rtgui_rect rect; rtgui_plot_curve_dtype max_x = 0; rtgui_plot_curve_dtype min_x = 0; rtgui_plot_curve_dtype max_y = 0; rtgui_plot_curve_dtype min_y = 0; rt_uint32_t iter = 0; rtgui_widget_get_rect(RTGUI_WIDGET(plot), &rect); curve = RTGUI_PLOT_CURVE( rtgui_mv_view_foreach_in_model(RTGUI_MV_VIEW(plot), &iter)); max_x = curve->max_x; min_x = curve->min_x; max_y = curve->max_y; min_y = curve->min_y; while (curve) { if (curve->max_x > max_x) max_x = curve->max_x; if (curve->min_x < min_x) min_x = curve->min_x; if (curve->max_y > max_y) max_y = curve->max_y; if (curve->min_y < min_y) min_y = curve->min_y; curve = RTGUI_PLOT_CURVE( rtgui_mv_view_foreach_in_model(RTGUI_MV_VIEW(plot), &iter)); } plot->scale_x = (max_x - min_x + rtgui_rect_width(rect)) / rtgui_rect_width(rect); plot->scale_y = (max_y - min_y + rtgui_rect_height(rect)) / rtgui_rect_height(rect); }
void rtgui_plot_destroy(struct rtgui_plot *plot) { rtgui_mv_view_destroy(RTGUI_MV_VIEW(plot)); }
struct rtgui_mv_view *rtgui_mv_view_create(void) { return RTGUI_MV_VIEW(rtgui_widget_create(RTGUI_MV_VIEW_TYPE)); }