void rtgui_server_destroy_application(struct rtgui_event_panel_detach* event) { struct rtgui_panel* panel = event->panel; if (panel != RT_NULL) { if (panel->wm_thread != RT_NULL) { /* notify to workbench */ rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_detach)); } /* send the responses */ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); rtgui_panel_thread_remove(panel, event->parent.sender); { /* get next thread and active it */ rt_thread_t tid = rtgui_panel_get_active_thread(panel); /* let this thread repaint */ struct rtgui_event_paint epaint; RTGUI_EVENT_PAINT_INIT(&epaint); epaint.wid = RT_NULL; rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint)); } } else { /* send the responses - failure */ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC); } }
void rtgui_server_create_application(struct rtgui_event_panel_attach* event) { struct rtgui_panel* panel = rtgui_panel_find(event->panel_name); if (panel != RT_NULL) { struct rtgui_event_panel_info ep; RTGUI_EVENT_PANEL_INFO_INIT(&ep); if (panel->wm_thread != RT_NULL) { /* notify to workbench */ rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_attach)); } /* send the responses - ok */ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); /* send the panel info */ ep.panel = panel; ep.extent = panel->extent; rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&ep, sizeof(ep)); rtgui_panel_thread_add(event->panel_name, event->parent.sender); } else { /* send the responses - failure */ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC); } }
void rtgui_server_thread_panel_show(struct rtgui_event_panel_show* event) { struct rtgui_panel* panel = event->panel; if (panel != RT_NULL) { struct rtgui_event_paint epaint; /* send the responses */ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); if (panel->wm_thread != RT_NULL) { /* notify to workbench */ rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_show)); } rtgui_panel_set_active_thread(panel, event->parent.sender); /* send all topwin clip info */ rtgui_topwin_update_clip_to_panel(panel); /* send paint event */ RTGUI_EVENT_PAINT_INIT(&epaint); epaint.wid = RT_NULL; rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&epaint, sizeof(epaint)); } else { /* send failed */ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); } }
static void calibration_data_post(rt_uint16_t x, rt_uint16_t y) { if (calibration_ptr != RT_NULL) { switch (calibration_ptr->step) { case CALIBRATION_STEP_LEFTTOP: calibration_ptr->data.min_x = x; calibration_ptr->data.min_y = y; break; case CALIBRATION_STEP_RIGHTTOP: calibration_ptr->data.max_x = x; calibration_ptr->data.min_y = (calibration_ptr->data.min_y + y)/2; break; case CALIBRATION_STEP_LEFTBOTTOM: calibration_ptr->data.min_x = (calibration_ptr->data.min_x + x)/2; calibration_ptr->data.max_y = y; break; case CALIBRATION_STEP_RIGHTBOTTOM: calibration_ptr->data.max_x = (calibration_ptr->data.max_x + x)/2; calibration_ptr->data.max_y = (calibration_ptr->data.max_y + y)/2; break; case CALIBRATION_STEP_CENTER: /* calibration done */ { struct rtgui_event_command ecmd; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.command_id = TOUCH_WIN_CLOSE; rtgui_thread_send(calibration_ptr->tid, &ecmd.parent, sizeof(struct rtgui_event_command)); } return; } calibration_ptr->step ++; /* post command event */ { struct rtgui_event_command ecmd; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.command_id = TOUCH_WIN_UPDATE; rtgui_thread_send(calibration_ptr->tid, &ecmd.parent, sizeof(struct rtgui_event_command)); } } }
static void adc_thread_entry(void *parameter) { rt_device_t device; #ifdef RT_USING_RTGUI struct rtgui_event_command ecmd; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_CMD_USER_INT; ecmd.command_id = ADC_UPDATE; #else struct lcd_msg msg; #endif device = rt_device_find("adc"); while(1) { rt_device_control(device, RT_DEVICE_CTRL_ADC_START, RT_NULL); rt_device_control(device, RT_DEVICE_CTRL_ADC_RESULT, &adc_value); pwm_update(adc_value/3); #ifdef RT_USING_RTGUI rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd)); #else msg.type = ADC_MSG; msg.adc_value = adc_value; rt_mq_send(&mq, &msg, sizeof(msg)); #endif rt_thread_delay(20); } }
void rtgui_server_thread_panel_hide(struct rtgui_event_panel_hide* event) { struct rtgui_panel* panel = event->panel; if (panel != RT_NULL) { rt_thread_t tid; struct rtgui_event_paint epaint; /* send the responses */ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); if (panel->thread_list.next != RT_NULL) { struct rtgui_panel_thread* thread; thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); /* remove it */ panel->thread_list.next = thread->list.next; /* append to the tail of thread list */ rtgui_list_append(&(panel->thread_list), &(thread->list)); } /* get new active thread */ tid = rtgui_panel_get_active_thread(panel); /* send all topwin clip info */ rtgui_topwin_update_clip_to_panel(panel); /* send paint event */ RTGUI_EVENT_PAINT_INIT(&epaint); epaint.wid = RT_NULL; rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint)); }
static void cpu_thread_entry(void *parameter) { #ifdef RT_USING_RTGUI struct rtgui_event_command ecmd; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_CMD_USER_INT; ecmd.command_id = CPU_UPDATE; #else struct lcd_msg msg; #endif while (1) { #ifdef RT_USING_RTGUI rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd)); #else msg.type = CPU_MSG; msg.major = cpu_usage_major; msg.minor = cpu_usage_minor; rt_mq_send(&mq, &msg, sizeof(msg)); #endif rt_thread_delay(20); } }
void player_notfiy_functionview() { struct rtgui_event_command ecmd; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_CMD_USER_INT; ecmd.command_id = PLAYER_REQUEST_FUNCTION_VIEW; rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd)); }
void player_notify_stop() { struct rtgui_event_command ecmd; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_CMD_USER_INT; ecmd.command_id = PLAYER_REQUEST_STOP; rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd)); }
void player_set_title(const char* title) { struct rtgui_event_command ecmd; strncpy(tinfo.title, title, 40); RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_CMD_USER_INT; ecmd.command_id = PLAYER_REQUEST_UPDATE_INFO; rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd)); }
void player_notify_info(const char* information) { struct rtgui_event_command ecmd; strncpy(tinfo.artist, information, 40); RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_CMD_USER_INT; ecmd.command_id = PLAYER_REQUEST_UPDATE_INFO; rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd)); }
void player_ui_freeze() { struct rtgui_event_command ecmd; /* check whether UI starts. */ if (home_view == RT_NULL || workbench == RT_NULL) return; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_CMD_USER_INT; ecmd.command_id = PLAYER_REQUEST_FREEZE; rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd)); }
void player_set_buffer_status(rt_bool_t buffering) { struct rtgui_event_command ecmd; if (buffering == RT_TRUE) strncpy(tinfo.artist, "缓冲中...", 40); else strncpy(tinfo.artist, "播放中...", 40); RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_CMD_USER_INT; ecmd.command_id = PLAYER_REQUEST_UPDATE_INFO; rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd)); }
static void rtgui_time_out(void* parameter) { rtgui_timer_t* timer; struct rtgui_event_timer event; timer = (rtgui_timer_t*)parameter; /* * Note: event_timer can not use RTGUI_EVENT_TIMER_INIT to init, for there is no * thread context */ event.parent.type = RTGUI_EVENT_TIMER; event.parent.sender = RT_NULL; event.timer = timer; rtgui_thread_send(timer->tid, &(event.parent), sizeof(struct rtgui_event_timer)); }
void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect) { struct rtgui_event_win_resize event; if (win == RT_NULL || rect == RT_NULL) return; RTGUI_WIDGET(win)->extent = *rect; if (RTGUI_TOPLEVEL(win)->server != RT_NULL) { /* set window resize event to server */ RTGUI_EVENT_WIN_RESIZE_INIT(&event); event.wid = win; event.rect = *rect; rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, &(event.parent), sizeof(struct rtgui_event_win_resize)); } }
/** * @} */ void RTC_IRQHandler(void) { static int delay_cnt; struct rtgui_event_command ecmd; /* enter interrupt */ rt_interrupt_enter(); ++rtc_1s_int_cnt; #if 1 == LCD_TEST_MALOOEI rt_kprintf("rtc:%d\n", rtc_1s_int_cnt); #endif if (delay_cnt < 1) { ++delay_cnt; goto ret_entry; } if (NULL == wb_thread) goto ret_entry; if (RTC_GetITStatus(RTC_IT_SEC) != RESET) { RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.command_id = UPDATE_SYS_TIME; if (RT_EOK != rtgui_thread_send(wb_thread, &ecmd.parent, sizeof(struct rtgui_event_command))) rt_kprintf("[RTC_IRQHandler]send enent cmd fail\n"); } #if 0 if(RTC_GetFlagStatus(RTC_FLAG_ALR) != RESET) { } else { } #endif ret_entry: RTC_ClearITPendingBit(RTC_IT_ALR | RTC_IT_SEC); /* leave interrupt */ rt_interrupt_leave(); return; }
void update_radio_thread(void* parameter) { rt_err_t result; struct player_request request; /* get request from message queue */ result = rt_mq_recv(update_radio_mq, (void*)&request, sizeof(struct player_request), RT_WAITING_FOREVER); if (result == RT_EOK) { switch (request.type) { case PLAYER_REQUEST_UPDATE_RADIO_LIST: if ((strstr(request.fn, "http://") == request.fn || (strstr(request.fn, "HTTP://") == request.fn ))) { struct rtgui_event_command ecmd; if(update_radio_list(request.fn)==0) { update_radio_list_state = UPDATE_RADIO_LIST_SUCCEED; } else { update_radio_list_state = UPDATE_RADIO_LIST_CONNECT_FAILED; } RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_EVENT_PAINT; ecmd.command_id = PLAYER_REQUEST_UPDATE_RADIO_LIST; rtgui_thread_send(rt_thread_find("ply_ui"), &ecmd.parent, sizeof(ecmd)); } break; } } rt_mq_delete(update_radio_mq); update_radio_mq = RT_NULL; }
struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner) { struct rtgui_dc* dc; rtgui_widget_t* widget; /* adjudge owner */ if (owner == RT_NULL || owner->toplevel == RT_NULL) return RT_NULL; if (!RTGUI_IS_TOPLEVEL(owner->toplevel)) return RT_NULL; dc = RTGUI_WIDGET_DC(owner); /* set init visible as true */ RTGUI_WIDGET_DC_SET_VISIBLE(owner); /* check widget visible */ widget = owner; while (widget != RT_NULL) { if (RTGUI_WIDGET_IS_HIDE(widget)) { RTGUI_WIDGET_DC_SET_UNVISIBLE(owner); break; } widget = widget->parent; } if (RTGUI_IS_WINTITLE(owner->toplevel)) { rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing ++; if (top->drawing == 1) { #ifdef RTGUI_USING_MOUSE_CURSOR #ifdef __WIN32__ rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER); rt_kprintf("hide cursor\n"); rtgui_mouse_hide_cursor(); #else /* hide cursor */ rtgui_mouse_hide_cursor(); #endif #endif } } else if (RTGUI_IS_WORKBENCH(owner->toplevel) || RTGUI_IS_WIN(owner->toplevel)) { rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing ++; if (top->drawing == 1) { #ifdef __WIN32__ #ifdef RTGUI_USING_MOUSE_CURSOR rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER); rt_kprintf("hide cursor\n"); rtgui_mouse_hide_cursor(); #endif #else /* send draw begin to server */ struct rtgui_event_update_begin eupdate; RTGUI_EVENT_UPDATE_BEGIN_INIT(&(eupdate)); eupdate.rect = RTGUI_WIDGET(top)->extent; rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate)); #endif } } return dc; }
static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc) { rtgui_widget_t* owner; if (dc == RT_NULL || dc->type != RTGUI_DC_CLIENT) return RT_FALSE; /* get owner */ owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type); if (RTGUI_IS_WINTITLE(owner->toplevel)) { /* update title extent */ rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing --; if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner)) { #ifdef __WIN32__ #ifdef RTGUI_USING_MOUSE_CURSOR rt_mutex_release(&cursor_mutex); /* show cursor */ rtgui_mouse_show_cursor(); rt_kprintf("show cursor\n"); #endif /* update screen */ rtgui_graphic_driver_screen_update(hw_driver, &(owner->extent)); #else #ifdef RTGUI_USING_MOUSE_CURSOR /* show cursor */ rtgui_mouse_show_cursor(); #endif /* update screen */ rtgui_graphic_driver_screen_update(hw_driver, &(owner->extent)); #endif } } else if (RTGUI_IS_WORKBENCH(owner->toplevel) || RTGUI_IS_WIN(owner->toplevel)) { rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing --; if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner)) { #ifdef __WIN32__ #ifdef RTGUI_USING_MOUSE_CURSOR rt_mutex_release(&cursor_mutex); /* show cursor */ rtgui_mouse_show_cursor(); rt_kprintf("show cursor\n"); #endif /* update screen */ rtgui_graphic_driver_screen_update(hw_driver, &(owner->extent)); #else /* send to server to end drawing */ struct rtgui_event_update_end eupdate; RTGUI_EVENT_UPDATE_END_INIT(&(eupdate)); eupdate.rect = owner->extent; rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate)); #endif } } return RT_TRUE; }
static void calibration_data_post(rt_uint16_t x, rt_uint16_t y) { if (calibration_ptr != RT_NULL) { switch (calibration_ptr->step) { case CALIBRATION_STEP_LEFTTOP: calibration_ptr->data.min_x = x; calibration_ptr->data.min_y = y; break; case CALIBRATION_STEP_RIGHTTOP: calibration_ptr->data.max_x = x; calibration_ptr->data.min_y = (calibration_ptr->data.min_y + y)/2; break; case CALIBRATION_STEP_LEFTBOTTOM: calibration_ptr->data.min_x = (calibration_ptr->data.min_x + x)/2; calibration_ptr->data.max_y = y; break; case CALIBRATION_STEP_RIGHTBOTTOM: calibration_ptr->data.max_x = (calibration_ptr->data.max_x + x)/2; calibration_ptr->data.max_y = (calibration_ptr->data.max_y + y)/2; break; case CALIBRATION_STEP_CENTER: /* calibration done */ { rt_uint16_t w, h; struct rtgui_event_command ecmd; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.command_id = TOUCH_WIN_CLOSE; /* calculate calibrated data */ if (calibration_ptr->data.max_x > calibration_ptr->data.min_x) w = calibration_ptr->data.max_x - calibration_ptr->data.min_x; else w = calibration_ptr->data.min_x - calibration_ptr->data.max_x; w = (w/(calibration_ptr->width - 2 * CALIBRATION_WIDTH)) * CALIBRATION_WIDTH; if (calibration_ptr->data.max_y > calibration_ptr->data.min_y) h = calibration_ptr->data.max_y - calibration_ptr->data.min_y; else h = calibration_ptr->data.min_y - calibration_ptr->data.max_y; h = (h/(calibration_ptr->height - 2 * CALIBRATION_HEIGHT)) * CALIBRATION_HEIGHT; rt_kprintf("w: %d, h: %d\n", w, h); if (calibration_ptr->data.max_x > calibration_ptr->data.min_x) { calibration_ptr->data.min_x -= w; calibration_ptr->data.max_x += w; } else { calibration_ptr->data.min_x += w; calibration_ptr->data.max_x -= w; } if (calibration_ptr->data.max_y > calibration_ptr->data.min_y) { calibration_ptr->data.min_y -= h; calibration_ptr->data.max_y += h; } else { calibration_ptr->data.min_y += h; calibration_ptr->data.max_y -= h; } rt_kprintf("calibration data: (%d, %d), (%d, %d)\n", calibration_ptr->data.min_x, calibration_ptr->data.max_x, calibration_ptr->data.min_y, calibration_ptr->data.max_y); rtgui_thread_send(calibration_ptr->tid, &ecmd.parent, sizeof(struct rtgui_event_command)); } return; } calibration_ptr->step ++; /* post command event */ { struct rtgui_event_command ecmd; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.command_id = TOUCH_WIN_UPDATE; rtgui_thread_send(calibration_ptr->tid, &ecmd.parent, sizeof(struct rtgui_event_command)); } } }
rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { struct rtgui_win* win = (struct rtgui_win*)widget; RT_ASSERT((win != RT_NULL) && (event != RT_NULL)); switch (event->type) { case RTGUI_EVENT_WIN_SHOW: rtgui_win_show(win, RT_FALSE); break; case RTGUI_EVENT_WIN_HIDE: rtgui_win_hiden(win); break; case RTGUI_EVENT_WIN_CLOSE: if (win->on_close != RT_NULL) { if (win->on_close(widget, event) == RT_FALSE) return RT_TRUE; } if (win->style & RTGUI_WIN_STYLE_MODAL) { rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL); } else { /* destroy window */ rtgui_win_destroy(win); } /* exit event loop */ return RT_TRUE; case RTGUI_EVENT_WIN_MOVE: { struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event; /* move window */ rtgui_win_move(win, emove->x, emove->y); } break; case RTGUI_EVENT_WIN_ACTIVATE: if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win))) { /* activate a hide window */ return RT_TRUE; } win->style |= RTGUI_WIN_STYLE_ACTIVATE; #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); else #endif rtgui_widget_update(RTGUI_WIDGET(win)); if (win->on_activate != RT_NULL) { win->on_activate(widget, event); } break; case RTGUI_EVENT_WIN_DEACTIVATE: if (win->style & RTGUI_WIN_STYLE_MODAL) { /* do not deactivate a modal win, re-send win-show event */ struct rtgui_event_win_show eshow; RTGUI_EVENT_WIN_SHOW_INIT(&eshow); eshow.wid = win; rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow), sizeof(struct rtgui_event_win_show)); } else { win->style &= ~RTGUI_WIN_STYLE_ACTIVATE; #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); else #endif rtgui_win_ondraw(win); if (win->on_deactivate != RT_NULL) { win->on_deactivate(widget, event); } } break; case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); else #endif rtgui_win_ondraw(win); break; case RTGUI_EVENT_MOUSE_BUTTON: if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL) { if (win->modal_widget != RT_NULL) return win->modal_widget->event_handler(win->modal_widget, event); } else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win), (struct rtgui_event_mouse*)event) == RT_FALSE) { #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_mouseclick != RT_NULL) { return widget->on_mouseclick(widget, event); } #endif } break; case RTGUI_EVENT_MOUSE_MOTION: #if 0 if (rtgui_widget_dispatch_mouse_event(widget, (struct rtgui_event_mouse*)event) == RT_FALSE) { #ifndef RTGUI_USING_SMALL_SIZE /* handle event in current widget */ if (widget->on_mousemotion != RT_NULL) { return widget->on_mousemotion(widget, event); } #endif } else return RT_TRUE; #endif break; case RTGUI_EVENT_KBD: if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL) { if (win->modal_widget != RT_NULL) return win->modal_widget->event_handler(win->modal_widget, event); } else if (RTGUI_CONTAINER(win)->focused != widget) { RTGUI_CONTAINER(win)->focused->event_handler(RTGUI_CONTAINER(win)->focused, event); } break; default: /* call parent event handler */ return rtgui_toplevel_event_handler(widget, event); } return RT_FALSE; }