FtkSource* ftk_source_dfb_create(IDirectFB* dfb) { FtkSource* thiz = FTK_ZALLOC(sizeof(FtkSource)+sizeof(PrivInfo)); if(thiz != NULL) { int fd = 0; DECL_PRIV(thiz, priv); IDirectFBEventBuffer* event_buffer = NULL; thiz->get_fd = ftk_source_dfb_get_fd; thiz->check = ftk_source_dfb_check; thiz->dispatch = ftk_source_dfb_dispatch; thiz->destroy = ftk_source_dfb_destroy; dfb->CreateInputEventBuffer( dfb, DICAPS_ALL, DFB_FALSE, &event_buffer ); if(event_buffer != NULL) { event_buffer->CreateFileDescriptor(event_buffer, &fd); } thiz->ref = 1; priv->fd = fd; priv->event_buffer = event_buffer; } return thiz; }
static int ftk_source_primary_get_fd(FtkSource* thiz) { DECL_PRIV(thiz, priv); return_val_if_fail(priv != NULL, -1); return ftk_pipe_get_read_handle(priv->pipe); }
FtkSource* ftk_source_ps2mouse_create(const char* filename, FtkOnEvent on_event, void* user_data, int max_x, int max_y) { FtkSource* thiz = (FtkSource*)FTK_ZALLOC(sizeof(FtkSource) + sizeof(PrivInfo)); if(thiz != NULL) { DECL_PRIV(thiz, priv); thiz->get_fd = ftk_source_ps2mouse_get_fd; thiz->check = ftk_source_ps2mouse_check; thiz->dispatch = ftk_source_ps2mouse_dispatch; thiz->destroy = ftk_source_ps2mouse_destroy; thiz->ref = 1; priv->fd = open(filename, O_RDONLY); ftk_strncpy(priv->filename, filename, sizeof(priv->filename)); open_device(priv, max_x, max_y); if(priv->fd < 0) { FTK_ZFREE(thiz, sizeof(thiz) + sizeof(PrivInfo)); return NULL; } priv->on_event = on_event; priv->user_data = user_data; priv->is_first_move = true; ftk_logd("%s: %d=%s priv->user_data=%p\n", __func__, priv->fd, filename, priv->user_data); } return thiz; }
static Ret ftk_canvas_default_draw_bitmap_normal(FtkCanvas* thiz, FtkBitmap* bitmap, FtkRect* s, FtkRect* d) { int i = 0; int j = 0; int k = 0; int x = s->x; int y = s->y; int w = s->width; int h = s->height; int xoffset = d->x; int yoffset = d->y; FtkColor* src = NULL; FtkColor* dst = NULL; FtkColor* psrc = NULL; FtkColor* pdst = NULL; unsigned char alpha = 0; DECL_PRIV(thiz, priv); int width = priv->w; int height = priv->h; int bitmap_width = ftk_bitmap_width(bitmap); int bitmap_height = ftk_bitmap_height(bitmap); return_val_if_fail(thiz != NULL && bitmap != NULL, RET_FAIL); return_val_if_fail(x < bitmap_width, RET_FAIL); return_val_if_fail(y < bitmap_height, RET_FAIL); return_val_if_fail(xoffset < width, RET_FAIL); return_val_if_fail(yoffset < height, RET_FAIL); src = ftk_bitmap_lock(bitmap); dst = priv->bits; w = (x + w) < bitmap_width ? w : bitmap_width - x; w = (xoffset + w) < width ? w : width - xoffset; h = (y + h) < bitmap_height ? h : bitmap_height - y; h = (yoffset + h) < height ? h : height - yoffset; w += x; h += y; src += y * bitmap_width; dst += yoffset * width; if(thiz->gc.mask & FTK_GC_ALPHA) { for(i = y; i < h; i++) { for(j = x, k = xoffset; j < w; j++, k++) { pdst = dst+k; psrc = src+j; alpha = (psrc->a * thiz->gc.alpha) >> 8; PUT_PIXEL(pdst, psrc, alpha); } src += bitmap_width; dst += width; } } else { for(i = y; i < h; i++)
static Ret ftk_wnd_manager_default_map_panels(FtkWndManager* thiz, int map) { int i = 0; Ret ret = RET_IGNORED; FtkEvent event; FtkWidget* win = NULL; DECL_PRIV(thiz, priv); return_val_if_fail(thiz != NULL && priv->top > 0, RET_FAIL); for(i = 0; i < priv->top; i++) { win = priv->windows[i]; if(ftk_widget_type(win) == FTK_STATUS_PANEL && ftk_widget_is_visible(win)) { if(!(map && ftk_window_is_mapped(win))) { ftk_event_init(&event, map ? FTK_EVT_MAP : FTK_EVT_UNMAP); event.widget = win; ftk_wnd_manager_dispatch_event(thiz, &event); ret = RET_OK; } ftk_widget_invalidate(win); } } return ret; }
static Ret ftk_canvas_default_draw_hline(FtkCanvas* thiz, int x, int y, int w) { int i = 0; int width = 0; int height = 0; FtkColor* bits = NULL; unsigned char alpha = 0; FtkColor* pdst = NULL; FtkColor* color = NULL; DECL_PRIV(thiz, priv); width = priv->w; height = priv->h; bits = priv->bits; return_val_if_fail(bits != NULL && x < width, RET_FAIL); return_val_if_fail(y < height, RET_FAIL); alpha = thiz->gc.mask & FTK_GC_ALPHA ? thiz->gc.alpha : thiz->gc.fg.a; x = x < 0 ? 0 : x; y = y < 0 ? 0 : y; w = (x + w) < width ? w : width - x; color = &(thiz->gc.fg); pdst = bits + y * width + x; for(i = w; i > 0; i--, pdst++) { PUT_PIXEL(pdst, color, alpha); } return RET_OK; }
static Ret ftk_canvas_default_draw_round_rect(FtkCanvas* thiz, int x, int y, int w, int h, int fill) { int width = 0; int height = 0; DECL_PRIV(thiz, priv); width = priv->w; height = priv->h; return_val_if_fail(x < width && y < height, RET_FAIL); return_val_if_fail(w > 8 && h > 8, RET_FAIL); ftk_canvas_default_draw_hline(thiz, x + 2, y, w-4); ftk_canvas_default_draw_hline(thiz, x + 1, y + 1, w-2); ftk_canvas_default_draw_vline(thiz, x, y + 2, h - 4); ftk_canvas_default_draw_vline(thiz, x + 1, y + 1, h - 2); ftk_canvas_default_draw_vline(thiz, x+w-1, y + 2, h - 4); ftk_canvas_default_draw_vline(thiz, x + w -2, y + 1, h - 2); ftk_canvas_default_draw_hline(thiz, x + 1, y + h - 1, w-2); ftk_canvas_default_draw_hline(thiz, x + 2, y + h - 2, w-4); if(fill) { ftk_canvas_default_draw_rect_impl(thiz, x + 2, y + 2, w - 4, h - 4, fill); } return RET_OK; }
static int ftk_display_mem_width(FtkDisplay* thiz) { DECL_PRIV(thiz, priv); return_val_if_fail(priv != NULL, 0); return priv->width; }
static int ftk_display_mem_height(FtkDisplay* thiz) { DECL_PRIV(thiz, priv); return_val_if_fail(priv != NULL, 0); return priv->height; }
Ret ftk_display_mem_update_directly(FtkDisplay* thiz, FtkPixelFormat format, void* bits, size_t width, size_t height, size_t xoffset, size_t yoffset) { size_t w = 0; size_t h = 0; char* src = NULL; char* dst = NULL; DECL_PRIV(thiz, priv); return_val_if_fail(bits != NULL, RET_FAIL); return_val_if_fail(ftk_display_mem_is_active(thiz), RET_FAIL); return_val_if_fail(xoffset < priv->width && yoffset < priv->height, RET_FAIL); w = (xoffset + width) < priv->width ? width : priv->width - xoffset; h = (yoffset + height) < priv->height ? height : priv->height - yoffset; if(format == priv->format) { src = (char*)bits; dst = (char*)priv->bits + priv->width * priv->bpp + xoffset; for(; h; h--) { memcpy(dst, src, priv->bpp * w); dst += priv->width * priv->bpp; src += width * priv->bpp; } } else { /*TODO*/ assert(!"not supprted yet"); } return RET_OK; }
static Ret ftk_display_mem_update(FtkDisplay* thiz, FtkBitmap* bitmap, FtkRect* rect, int xoffset, int yoffset) { Ret ret = RET_OK; DECL_PRIV(thiz, priv); int display_width = priv->width; int display_height = priv->height; return_val_if_fail(priv != NULL, RET_FAIL); ftk_logd("%s: ox=%d oy=%d (%d %d %d %d)\n", __func__, xoffset, yoffset, rect->x, rect->y, rect->width, rect->height); ret = priv->copy_to_data(bitmap, rect, priv->bits, xoffset, yoffset, display_width, display_height); if(priv->sync != NULL && ret == RET_OK) { FtkRect r; r.x = xoffset; r.y = yoffset; r.width = rect->width; r.height = rect->height; priv->sync(priv->sync_ctx, &r); } return ret; }
static FtkBitmap* ftk_app_demo_get_icon(FtkApp* thiz) { DECL_PRIV(thiz, priv); return_val_if_fail(priv != NULL, NULL); return priv->icon; }
static const char* ftk_app_demo_get_name(FtkApp* thiz) { DECL_PRIV(thiz, priv); return_val_if_fail(priv != NULL, NULL); return priv->name; }
FtkInputMethod* ftk_input_method_hw_create(void) { FtkInputMethod* thiz = FTK_ZALLOC(sizeof(FtkInputMethod) + sizeof(PrivInfo)); if(thiz != NULL) { FtkColor c = {0}; DECL_PRIV(thiz, priv); thiz->ref = 1; thiz->name = _("Hand Write"); thiz->set_type = ftk_input_method_hw_set_type; thiz->focus_in = ftk_input_method_hw_focus_in; thiz->focus_out = ftk_input_method_hw_focus_out; thiz->handle_event = ftk_input_method_hw_handle_event; thiz->destroy = ftk_input_method_hw_destroy; c.r = 0xff; c.b = 0xff; priv->painter = ftk_stroke_painter_create(); priv->engine = ftk_hand_write_engine_create(on_handwrite_result, thiz); ftk_input_method_hw_set_rect(thiz, NULL); ftk_input_method_hw_set_pen_width(thiz, 3); ftk_input_method_hw_set_pen_color(thiz, c); ftk_input_method_hw_set_click_timeout(thiz, 300); ftk_input_method_hw_set_commit_timeout(thiz, 1500); } return thiz; }
FtkSource* ftk_source_psp_create(FtkDisplay* display, FtkOnEvent on_event, void* ctx) { FtkSource* thiz = NULL; return_val_if_fail(display != NULL && on_event != NULL, NULL); thiz = (FtkSource*)FTK_ZALLOC(sizeof(FtkSource) + sizeof(PrivInfo)); if(thiz != NULL) { DECL_PRIV(thiz, priv); thiz->get_fd = ftk_source_psp_get_fd; thiz->check = ftk_source_psp_check; thiz->dispatch = ftk_source_psp_dispatch; thiz->destroy = ftk_source_psp_destroy; thiz->ref = 1; priv->ctx = ctx; priv->on_event = on_event; priv->display = display; priv->psp_keypress = 0; } return thiz; }
FtkSource* ftk_source_x11_create(FtkDisplay* display, FtkOnEvent on_event, void* ctx) { FtkSource* thiz = NULL; return_val_if_fail(display != NULL && on_event != NULL, NULL); thiz = (FtkSource*)FTK_ZALLOC(sizeof(FtkSource) + sizeof(PrivInfo)); if(thiz != NULL) { DECL_PRIV(thiz, priv); thiz->get_fd = ftk_source_x11_get_fd; thiz->check = ftk_source_x11_check; thiz->dispatch = ftk_source_x11_dispatch; thiz->destroy = ftk_source_x11_destroy; thiz->ref = 1; priv->ctx = ctx; priv->on_event = on_event; priv->display = display; priv->fd = ConnectionNumber(ftk_display_x11_get_xdisplay(display)); priv->win = (Window)ftk_display_x11_get_xwindow(display); XSetErrorHandler(on_x11_error); } return thiz; }
static Ret ftk_canvas_default_draw_vline(FtkCanvas* thiz, int x, int y, int h) { int i = 0; int width = 0; int height = 0; FtkColor* bits = NULL; unsigned char alpha = 0; FtkColor* pdst = NULL; FtkColor* color = NULL; DECL_PRIV(thiz, priv); width = priv->w; height = priv->h; bits = priv->bits; return_val_if_fail(bits != NULL && y < height, RET_FAIL); alpha = thiz->gc.mask & FTK_GC_ALPHA ? thiz->gc.alpha : thiz->gc.fg.a; x = x < 0 ? 0 : x; y = y < 0 ? 0 : y; h = (y + h) < height ? h : (height - y); pdst = bits + width * y + x; color = &(thiz->gc.fg); for(i = h; i > 0; i--, pdst+=width) { PUT_PIXEL(pdst, color, alpha); } return RET_OK; }
FtkDisplay* ftk_display_android_create(void) { FtkDisplay* thiz = NULL; thiz = (FtkDisplay*)FTK_ZALLOC(sizeof(FtkDisplay) + sizeof(PrivInfo)); if(thiz != NULL) { FtkColor bg; DECL_PRIV(thiz, priv); thiz->update = ftk_display_android_update; thiz->width = ftk_display_android_width; thiz->height = ftk_display_android_height; thiz->snap = ftk_display_android_snap; thiz->destroy = ftk_display_android_destroy; bg.a = 0xff; bg.r = 0xff; bg.g = 0xff; bg.b = 0xff; priv->bitmap = ftk_bitmap_create(screen_width, screen_height, bg); ftk_wnd_manager_add_global_listener(ftk_default_wnd_manager(), (FtkListener)ftk_display_android_handle_event, thiz); Android_InitEGL(); } return thiz; }
static Ret ftk_canvas_default_draw_rect_impl(FtkCanvas* thiz, int x, int y, int w, int h, int fill) { int i = 0; int width = 0; int height = 0; DECL_PRIV(thiz, priv); width = priv->w; height = priv->h; return_val_if_fail(x < width && y < height, RET_FAIL); if(fill) { for(i = 0; i < h; i++) { if((y + i) < height) { ftk_canvas_default_draw_hline(thiz, x, (y+i), w); } } } else { ftk_canvas_default_draw_hline(thiz, x, y, w); ftk_canvas_default_draw_hline(thiz, x, y+h-1, w); ftk_canvas_default_draw_vline(thiz, x, y, h); ftk_canvas_default_draw_vline(thiz, x+w-1, y, h); } return RET_OK; }
static Ret ftk_animation_alpha_step(FtkAnimation* thiz) { FtkRect r = {0}; float percent = 0; DECL_PRIV(thiz, priv); r = priv->back_win_rect; if(r.width > 0 && r.height > 0) { ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->back_win, &r, &r, 0xff); } percent = priv->start + (priv->end - priv->start) * ftk_animation_get_percent(thiz); r = priv->front_win_rect; if(r.width > 0 && r.height > 0) { int alpha = (int)(0xff * percent) & 0xff; ftk_canvas_draw_bitmap(ftk_shared_canvas(), priv->front_win, &r, &r, alpha); } ftk_canvas_show(ftk_shared_canvas(), ftk_default_display(), &r, r.x, r.y); return RET_OK; }
static Ret ftk_canvas_default_draw_rect(FtkCanvas* thiz, int x, int y, int w, int h, int round, int fill) { Ret ret = RET_FAIL; FtkRect rect = {0}; DECL_PRIV(thiz, priv); rect.x = x; rect.y = y; rect.width = w; rect.height = h; if(ftk_rect_and(&rect, &priv->clip->rect, &rect) != RET_OK) { // ftk_logd("%s: skip.\n", __func__); return RET_OK; } x = rect.x; y = rect.y; w = rect.width; h = rect.height; if(round) { ret = ftk_canvas_default_draw_round_rect(thiz, x, y, w, h, fill); } else { ret = ftk_canvas_default_draw_rect_impl(thiz, x, y, w, h, fill); } return ret; }
static Ret ftk_animation_alpha_reset(FtkAnimation* thiz, FtkBitmap* old_win, FtkBitmap* new_win, FtkRect* old_win_rect, FtkRect* new_win_rect) { DECL_PRIV(thiz, priv); const char* src = ftk_animation_get_param(thiz, "src"); return_val_if_fail(src != NULL, RET_FAIL); priv->start = ftk_animation_get_param_float(thiz, "from", 1.0); priv->end = ftk_animation_get_param_float(thiz, "to", 1.0); if(strstr(src, "new_window") != NULL) { priv->back_win = old_win; priv->back_win_rect = *old_win_rect; priv->front_win = new_win; priv->front_win_rect = *new_win_rect; } else { priv->back_win = new_win; priv->back_win_rect = *new_win_rect; priv->front_win = old_win; priv->front_win_rect = *old_win_rect; } ftk_logd("%s: src=%s start=%f end=%f old(%d %d %d %d) new(%d %d %d %d)", __func__, src, priv->start, priv->end, old_win_rect->x, old_win_rect->y, old_win_rect->width, old_win_rect->height, new_win_rect->x, new_win_rect->y, new_win_rect->width, new_win_rect->height); return RET_OK; }
static FtkWidget* ftk_wnd_manager_find_target(FtkWndManager* thiz, int x, int y) { int i = 0; int top = 0; int left = 0; int w = 0; int h = 0; DECL_PRIV(thiz, priv); return_val_if_fail(thiz != NULL && priv->top > 0, NULL); i = priv->top; for(; i > 0; i--) { FtkWidget* win = priv->windows[i-1]; if(!ftk_widget_is_visible(win) || !ftk_window_is_mapped(win)) { continue; } top = ftk_widget_top_abs(win); left = ftk_widget_left_abs(win); w = ftk_widget_width(win); h = ftk_widget_height(win); if(x >= left && y >= top && x < (left + w) && y < (top + h)) { return win; } } return NULL; }
static void ftk_animation_trigger_default_destroy(FtkAnimationTrigger* thiz) { if(thiz != NULL) { int i = 0; DECL_PRIV(thiz, priv); for(i = 0; i < priv->type_and_animations_nr; i++) { size_t j = 0; for(j = 0; j < FTK_MAX_ANIMATION_NR; j++) { if(priv->type_and_animations[i].animations[j] != NULL) { ftk_animation_destroy(priv->type_and_animations[i].animations[j]); } } } ftk_canvas_destroy(priv->old_window); ftk_canvas_destroy(priv->new_window); FTK_FREE(thiz); } return; }
FtkWndManager* ftk_wnd_manager_default_create(FtkMainLoop* main_loop) { FtkWndManager* thiz = NULL; return_val_if_fail(main_loop != NULL, NULL); if((thiz = (FtkWndManager*)FTK_ZALLOC(sizeof(FtkWndManager) + sizeof(PrivInfo))) != NULL) { DECL_PRIV(thiz, priv); priv->main_loop = main_loop; priv->long_press_timer = ftk_source_timer_create(1500, (FtkTimer)ftk_wnd_manager_default_long_press, thiz); ftk_set_primary_source(ftk_source_primary_create((FtkOnEvent)ftk_wnd_manager_default_dispatch_event, thiz)); ftk_sources_manager_add(ftk_default_sources_manager(), ftk_primary_source()); thiz->grab = ftk_wnd_manager_default_grab; thiz->ungrab = ftk_wnd_manager_default_ungrab; thiz->add = ftk_wnd_manager_default_add; thiz->remove = ftk_wnd_manager_default_remove; thiz->restack= ftk_wnd_manager_default_restack; thiz->update = ftk_wnd_manager_default_update; thiz->get_work_area = ftk_wnd_manager_default_get_work_area; thiz->queue_event = ftk_wnd_manager_default_queue_event; thiz->dispatch_event = ftk_wnd_manager_default_dispatch_event; thiz->add_global_listener = ftk_wnd_manager_default_add_global_listener; thiz->remove_global_listener = ftk_wnd_manager_default_remove_global_listener; thiz->destroy = ftk_wnd_manager_default_destroy; #ifndef FTK_SUPPORT_C99 key_tanslate_table_init(); #endif } return thiz; }
static Ret ftk_animation_trigger_default_ensure_canvas(FtkAnimationTrigger* thiz) { int w = 0; int h = 0; FtkColor bg = {0}; DECL_PRIV(thiz, priv); if(priv->old_window && priv->new_window) { return RET_OK; } bg.a = 0xff; w = ftk_display_width(ftk_default_display()); h = ftk_display_height(ftk_default_display()); if(priv->old_window == NULL) { priv->old_window = ftk_canvas_create(w, h, &bg); } if(priv->new_window == NULL) { priv->new_window = ftk_canvas_create(w, h, &bg); } return priv->old_window && priv->new_window ? RET_OK : RET_FAIL; }
static Ret ftk_source_primary_dispatch(FtkSource* thiz) { FtkEvent event = {0}; DECL_PRIV(thiz, priv); int ret = ftk_pipe_read(priv->pipe, &event, sizeof(FtkEvent)); return_val_if_fail(ret == sizeof(FtkEvent), RET_REMOVE); switch(event.type) { case FTK_EVT_NOP: { break; } case FTK_EVT_ADD_SOURCE: { ftk_sources_manager_add(ftk_default_sources_manager(), event.u.extra); break; } case FTK_EVT_REMOVE_SOURCE: { ftk_sources_manager_remove(ftk_default_sources_manager(), event.u.extra); break; } default: { if(priv->on_event != NULL) { priv->on_event(priv->user_data, &event); } } } return RET_OK; }
static Ret ftk_font_freetype_lookup (FtkFont* thiz, unsigned short code, FtkGlyph* glyph) { int index = 0; FT_Error err = 0; DECL_PRIV(thiz, priv); return_val_if_fail(thiz != NULL && glyph != NULL, RET_FAIL); index = FT_Get_Char_Index(priv->face, code); err = FT_Load_Glyph(priv->face, index, FT_LOAD_DEFAULT|FT_LOAD_RENDER); return_val_if_fail(err == 0, RET_FAIL); glyph->code = code; glyph->x = priv->face->glyph->bitmap_left; glyph->y = priv->face->glyph->bitmap_top; glyph->w = priv->face->glyph->bitmap.width; glyph->h = priv->face->glyph->bitmap.rows; glyph->advance_x = priv->face->glyph->advance.x >> 6; glyph->data = priv->face->glyph->bitmap.buffer; // For fix a bug-- the actual bitmap of some fonts is larger than it's font size if (glyph->h > thiz->height(thiz)) { ftk_logw("Bug font code: %04x\n", code); glyph->h = thiz->height(thiz); } return RET_OK; }
static int ftk_font_freetype_height(FtkFont* thiz) { DECL_PRIV(thiz, priv); return_val_if_fail(thiz != NULL, 0); return priv->size; }
static Ret ftk_source_dfb_dispatch(FtkSource* thiz) { int i = 0; int nr = 0; DFBEvent buff[10]; DECL_PRIV(thiz, priv); DFBEvent* event = NULL; int size = read(priv->fd, buff, sizeof(buff)); return_val_if_fail(size > 0, RET_FAIL); nr = size/sizeof(DFBEvent); for(i = 0; i < nr; i++) { event = buff+i; switch(event->clazz) { case DFEC_INPUT: { ftk_source_dfb_dispatch_input_event(thiz, &(event->input)); break; } case DFEC_USER: { break; } case DFEC_WINDOW: { break; } default:break; } } return RET_OK; }