#include "clipdrawer.h"
#include "scrcapture.h"
+#include <appcore-efl.h>
+
// FIXME: how to remove g_main_ad?
static struct appdata *g_main_ad = NULL;
-
static Evas_Object* create_win(void *data, const char *name);
static Evas_Object* load_edj(Evas_Object *parent, const char *file, const char *group);
elm_exit();
}
+static int lang_changed(void *data)
+{
+ return 0;
+}
+
void* g_get_main_appdata()
{
return (void*)g_main_ad;
void set_focus_for_app_window(Evas_Object *win, Eina_Bool enable)
{
- Eina_Bool accepts_focus;
- Ecore_X_Window_State_Hint initial_state;
- Ecore_X_Pixmap icon_pixmap;
- Ecore_X_Pixmap icon_mask;
- Ecore_X_Window icon_window;
- Ecore_X_Window window_group;
- Eina_Bool is_urgent;
-
- ecore_x_icccm_hints_get (elm_win_xwindow_get (win),
- &accepts_focus, &initial_state, &icon_pixmap, &icon_mask, &icon_window, &window_group, &is_urgent);
- ecore_x_icccm_hints_set (elm_win_xwindow_get (win),
- enable, initial_state, icon_pixmap, icon_mask, icon_window, window_group, is_urgent);
+ Eina_Bool accepts_focus;
+ Ecore_X_Window_State_Hint initial_state;
+ Ecore_X_Pixmap icon_pixmap;
+ Ecore_X_Pixmap icon_mask;
+ Ecore_X_Window icon_window;
+ Ecore_X_Window window_group;
+ Eina_Bool is_urgent;
+
+ ecore_x_icccm_hints_get (elm_win_xwindow_get (win),
+ &accepts_focus, &initial_state, &icon_pixmap, &icon_mask, &icon_window, &window_group, &is_urgent);
+ ecore_x_icccm_hints_set (elm_win_xwindow_get (win),
+ enable, initial_state, icon_pixmap, icon_mask, icon_window, window_group, is_urgent);
DTRACE("set focus mode = %d\n", enable);
}
+int get_rotation_degree()
+{
+ int angle;
+ enum appcore_rm mode;
+ appcore_get_rotation_state(&mode);
+ if (mode == -1)
+ return 0;
+
+ switch (mode)
+ {
+ case APPCORE_RM_LANDSCAPE_NORMAL:
+ angle = -90;
+ break;
+
+ case APPCORE_RM_LANDSCAPE_REVERSE:
+ angle = 90;
+ break;
+
+ case APPCORE_RM_PORTRAIT_REVERSE:
+ angle = 180;
+ break;
+
+ case APPCORE_RM_UNKNOWN:
+ case APPCORE_RM_PORTRAIT_NORMAL:
+ default:
+ angle = 0;
+ break;
+ }
+
+ return angle;
+}
+
+static int _rotation_cb(enum appcore_rm mode, void *data)
+{
+ struct appdata *ad = (struct appdata *)data;
+ int angle;
+
+ switch (mode)
+ {
+ case APPCORE_RM_LANDSCAPE_NORMAL:
+ angle = -90;
+ break;
+
+ case APPCORE_RM_LANDSCAPE_REVERSE:
+ angle = 90;
+ break;
+
+ case APPCORE_RM_PORTRAIT_REVERSE:
+ angle = 180;
+ break;
+
+ case APPCORE_RM_UNKNOWN:
+ case APPCORE_RM_PORTRAIT_NORMAL:
+ default:
+ angle = 0;
+ break;
+ }
+
+ elm_win_rotation_set(ad->win_main, angle);
+
+ // This is need for customized rotation process.
+ set_rotation_to_clipdrawer(ad, angle);
+
+ return 0;
+}
+
static Evas_Object* create_win(void *data, const char *name)
{
struct appdata *ad = (struct appdata *) data;
eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
if (eo)
- {
+ {
elm_win_title_set(eo, name);
elm_win_borderless_set(eo, EINA_TRUE);
ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
}
static Evas_Object* load_edj(Evas_Object *parent, const char *file, const char *group)
-{
+{
Evas_Object *eo;
int ret;
if (ad->ly_main)
evas_object_del(ad->ly_main);
+}
+
+static void init_ad(struct appdata *ad)
+{
+ g_main_ad = ad;
+}
+
+static int app_create(void *data)
+{
+ struct appdata *ad = data;
+
+ init_ad(ad);
+
+ init(ad);
+
+ lang_changed(ad);
+
+ /* add system event callback */
+ appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE,
+ lang_changed, ad);
+
+ return 0;
+}
+
+
+static int app_terminate(void *data)
+{
+ struct appdata *ad = data;
+
+ fini(ad);
if (ad->win_main)
evas_object_del(ad->win_main);
+
+ return 0;
}
-static void init_ad(struct appdata *ad)
+static int app_pause(void *data)
{
- memset(ad, 0x0, sizeof(struct appdata));
- g_main_ad = ad;
+ return 0;
}
+static int app_resume(void *data)
+{
+ return 0;
+}
+
+static int app_reset(bundle *b, void *data)
+{
+ struct appdata *ad = data;
+
+ if (ad->win_main)
+ elm_win_activate(ad->win_main);
+
+ return 0;
+}
+
+/*
EAPI int elm_main(int argc, char **argv)
{
struct appdata ad;
return EXIT_SUCCESS;
}
+*/
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
{
- elm_init(argc, argv);
+ struct appdata ad;
+ struct appcore_ops ops = {
+ .create = app_create,
+ .terminate = app_terminate,
+ .pause = app_pause,
+ .resume = app_resume,
+ .reset = app_reset,
+ };
+
+ memset(&ad, 0x0, sizeof(struct appdata));
+ ops.data = &ad;
+
+ appcore_set_i18n(PACKAGE, LOCALEDIR);
+ appcore_set_rotation_cb(_rotation_cb, &ad);
- return elm_main(argc, argv);
+ return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
}
}
}
+void set_rotation_to_clipdrawer(void *data, int angle)
+{
+ struct appdata *ad = data;
+ double wh, wy;
+ int wposx, wwidth;
+
+ if (angle == 180) // reverse
+ {
+ wh = (1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h;
+ wy = 0;
+ wwidth = ad->root_w;
+ wposx = CLIPDRAWER_POS_X;
+ }
+ else if (angle == 90) // right rotate
+ {
+ wh = (1.0*CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w;
+ wy = (1.0*CLIPDRAWER_POS_X/SCREEN_WIDTH)*ad->root_w;
+ wwidth = ad->root_h;
+ wposx = CLIPDRAWER_WIDTH-CLIPDRAWER_HEIGHT_LANDSCAPE;
+ }
+ else if (angle == -90) // left rotate
+ {
+ wh = (1.0*CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w;
+ wy = (1.0*CLIPDRAWER_POS_X/SCREEN_WIDTH)*ad->root_w;
+ wwidth = ad->root_h;
+ wposx = CLIPDRAWER_POS_X;
+ }
+ else // angle == 0
+ {
+ wh = (1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h;
+ wy = (1.0*CLIPDRAWER_POS_Y/SCREEN_HEIGHT)*ad->root_h;
+ wwidth = ad->root_w;
+ wposx = CLIPDRAWER_POS_X;
+ }
+
+ evas_object_resize(ad->win_main, wwidth, (int)wh);
+ evas_object_move(ad->win_main, wposx, (int)wy);
+ evas_object_resize(ad->ly_main, wwidth, (int)wh);
+ evas_object_move(ad->ly_main, wposx, (int)wy);
+}
+
int clipdrawer_init(void *data)
{
struct appdata *ad = data;
// for elm_check
elm_theme_extension_add(NULL, APP_EDJ_FILE);
- cdy = (1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h;
- cdw = (1.0*CLIPDRAWER_POS_Y/SCREEN_HEIGHT)*ad->root_h;
-
- evas_object_resize(ad->win_main, ad->root_w, (int)cdy);
- evas_object_move(ad->win_main, CLIPDRAWER_POS_X, (int)cdw);
- evas_object_resize(ad->ly_main, ad->root_w, (int)cdy);
- evas_object_move(ad->ly_main, CLIPDRAWER_POS_X, (int)cdw);
+ set_rotation_to_clipdrawer(ad, get_rotation_degree());
edje_object_signal_callback_add(elm_layout_edje_get(ad->ly_main),
"mouse,up,1", "*", clipdrawer_ly_clicked, ad);
return 0;
}
-Eina_Bool anim_pos_calc_cb(void *data)
+Eina_Bool _get_anim_pos(void *data, int *sp, int *ep)
{
+ if (!sp || !ep)
+ return EINA_FALSE;
+
struct appdata *ad = data;
+ int angle = get_rotation_degree();
+ int anim_start, anim_end, delta;
- static int anim_count = 0;
- int anim_starty, anim_endy, deltay;
+ switch (ad->anim_status)
+ {
+ case HIDE_ANIM:
+ if (angle == 180) // reverse
+ {
+ anim_start = 0;
+ anim_end = (int)(((double)CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
+ anim_end = ad->root_h-anim_end;
+ anim_end = -anim_end;
+ }
+ else if (angle == 90) // right rotate
+ {
+ anim_end = ad->root_w;
+ anim_start = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
+ anim_start = ad->root_w-anim_start;
+ }
+ else if (angle == -90) // left rotate
+ {
+ anim_start = 0;
+ anim_end = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
+ anim_end = ad->root_w-anim_end;
+ anim_end = -anim_end;
+ }
+ else // angle == 0
+ {
+ anim_start = (int)((1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
+ anim_end = ad->root_h;
+ anim_start = anim_end-anim_start;
+ }
+ break;
+ case SHOW_ANIM:
+ if (angle == 180) // reverse
+ {
+ anim_start = (int)(((double)CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
+ anim_start = ad->root_h - anim_start;
+ anim_start = -anim_start;
+ anim_end = 0;
+ }
+ else if (angle == 90) // right rotate
+ {
+ anim_start = ad->root_w;
+ anim_end = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
+ anim_end = anim_start-anim_end;
+ }
+ else if (angle == -90) // left rotate
+ {
+ anim_start = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
+ anim_start = ad->root_w-anim_start;
+ anim_start = -anim_start;
+ anim_end = 0;
+ }
+ else // angle == 0
+ {
+ anim_start = ad->root_h;
+ anim_end = (int)(((double)CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
+ anim_end = anim_start-anim_end;
+ }
+ break;
+ }
+ *sp = anim_start;
+ *ep = anim_end;
+ return EINA_TRUE;
+}
+
+Eina_Bool _do_anim_delta_pos(void *data, int sp, int ep, int ac, int *dp)
+{
+ if (!dp)
+ return EINA_FALSE;
+
+ struct appdata *ad = data;
+ int angle = get_rotation_degree();
+ int delta;
double posprop;
+ posprop = 1.0*ac/ANIM_DURATION;
switch (ad->anim_status)
{
case HIDE_ANIM:
- anim_starty = (int)((1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
- anim_endy = ad->root_h;
- anim_starty = anim_endy - anim_starty;
+ if (angle == 180) // reverse
+ {
+ delta = (int)((sp-ep)*posprop);
+ evas_object_move(ad->win_main, 0, sp-delta);
+ }
+ else if (angle == 90) // right rotate
+ {
+ delta = (int)((sp-ep)*posprop);
+ evas_object_move(ad->win_main, sp-delta, 0);
+ }
+ else if (angle == -90) // left rotate
+ {
+ delta = (int)((sp-ep)*posprop);
+ evas_object_move(ad->win_main, sp-delta, 0);
+ }
+ else // angle == 0
+ {
+ delta = (int)((ep-sp)*posprop);
+ evas_object_move(ad->win_main, 0, sp+delta);
+ }
+
break;
case SHOW_ANIM:
- anim_starty = ad->root_h;
- anim_endy = (int)((1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
- anim_endy = anim_starty-anim_endy;
+ if (angle == 180) // reverse
+ {
+ delta = (int)((ep-sp)*posprop);
+ evas_object_move(ad->win_main, 0, sp+delta);
+ }
+ else if (angle == 90) // right rotate
+ {
+ delta = (int)((ep-sp)*posprop);
+ evas_object_move(ad->win_main, sp+delta, 0);
+ }
+ else if (angle == -90) // left rotate
+ {
+ delta = (int)((ep-sp)*posprop);
+ evas_object_move(ad->win_main, sp+delta, 0);
+ }
+ else // angle == 0
+ {
+ delta = (int)((sp-ep)*posprop);
+ evas_object_move(ad->win_main, 0, sp-delta);
+ }
break;
- default:
- return EINA_FALSE;
}
+
+ *dp = delta;
+
+ return EINA_TRUE;
+}
+
+Eina_Bool anim_pos_calc_cb(void *data)
+{
+ struct appdata *ad = data;
+
+ static int anim_count = 0;
+ int anim_start, anim_end, delta;
+
+ _get_anim_pos(ad, &anim_start, &anim_end);
if (anim_count > ANIM_DURATION)
{
return EINA_FALSE;
}
- posprop = 1.0*anim_count/ANIM_DURATION;
- switch (ad->anim_status)
- {
- case HIDE_ANIM:
- deltay = (int)((anim_endy-anim_starty)*posprop);
- evas_object_move(ad->win_main, 0, anim_starty+deltay);
- break;
- case SHOW_ANIM:
- deltay = (int)((anim_starty-anim_endy)*posprop);
- evas_object_move(ad->win_main, 0, anim_starty-deltay);
- break;
- default:
- return EINA_FALSE;
- }
+ _do_anim_delta_pos(ad, anim_start, anim_end, anim_count, &delta);
anim_count++;
return EINA_TRUE;