diff options
author | Michal Skorupinski <m.skorupinsk@samsung.com> | 2018-08-31 18:24:48 +0200 |
---|---|---|
committer | Krzysztof Wieclaw <k.wieclaw@samsung.com> | 2018-09-07 14:52:07 +0200 |
commit | f042b0dd4e753da471d9927655214ccd791b0a7c (patch) | |
tree | 7b1abf8a4be9cd782a96db897385d94d73d1a44a /src/view | |
parent | d38b11d4116086a5527447345ff3f23ad4ae90c9 (diff) | |
download | gear-racing-controller-f042b0dd4e753da471d9927655214ccd791b0a7c.tar.gz gear-racing-controller-f042b0dd4e753da471d9927655214ccd791b0a7c.tar.bz2 gear-racing-controller-f042b0dd4e753da471d9927655214ccd791b0a7c.zip |
Camera indicators added. Azimuth indicator animation added
Change-Id: Iaedfdff5f5a6d58f4040a67cd810655130032e86
Signed-off-by: Michal Skorupinski <m.skorupinsk@samsung.com>
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/view_racing.c | 105 |
1 files changed, 102 insertions, 3 deletions
diff --git a/src/view/view_racing.c b/src/view/view_racing.c index 1a75865..b588ede 100644 --- a/src/view/view_racing.c +++ b/src/view/view_racing.c @@ -21,10 +21,22 @@ #include "log.h" #include "math_helper.h" +#define CAM_AZIMUTH_STEP 0.01 + +typedef enum _e_camera_button_action { + CAMERA_BUTTON_RIGHT_UP, + CAMERA_BUTTON_RIGHT_DOWN, + CAMERA_BUTTON_LEFT_UP, + CAMERA_BUTTON_LEFT_DOWN, +} e_camera_button_action; + typedef struct _s_view_racing { s_view_base view_base; Evas_Object *velocity; Evas_Object *direction; + Evas_Object *camera_azimuth_indicator; + Evas_Object *camera_elevation_indicator; + float velocity_angle; float direction_angle; @@ -34,6 +46,10 @@ typedef struct _s_view_racing { float vel_max_angle; bool stop_longpress; + + Ecore_Animator *cam_animator; + bool cam_buttons_pressed[2]; + float cam_azimuth; } s_view_racing; static s_view_racing s_info = { @@ -103,14 +119,14 @@ static void _controller_cb(void *data) } } -void _racing_screen_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source) +static void _racing_screen_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source) { evas_object_hide(s_info.velocity); controller_racing_set_stop(true); } -void _stop_longpress_completed(void *data, Evas_Object *obj, const char *emission, const char *source) +static void _stop_longpress_completed(void *data, Evas_Object *obj, const char *emission, const char *source) { ASSERT_FUNCTION_START; @@ -121,7 +137,7 @@ void _stop_longpress_completed(void *data, Evas_Object *obj, const char *emissio ASSERT_FUNCTION_END; } -void _stop_logpress_up(void *data, Evas_Object *obj, const char *emission, const char *source) +static void _stop_logpress_up(void *data, Evas_Object *obj, const char *emission, const char *source) { ASSERT_FUNCTION_START; @@ -135,6 +151,65 @@ void _stop_logpress_up(void *data, Evas_Object *obj, const char *emission, const ASSERT_FUNCTION_END; } +static Eina_Bool _camera_azimuth_animator_cb(void *data) +{ + float prev = s_info.cam_azimuth; + + if (s_info.cam_buttons_pressed[0] && !s_info.cam_buttons_pressed[1]) { + s_info.cam_azimuth -= CAM_AZIMUTH_STEP; + } else if (!s_info.cam_buttons_pressed[0] && s_info.cam_buttons_pressed[1]) { + s_info.cam_azimuth += CAM_AZIMUTH_STEP; + } + + if (prev * s_info.cam_azimuth < 0) { + s_info.cam_azimuth = 0; + } + + + if (s_info.cam_azimuth < -1) { + s_info.cam_azimuth = 1; + } else if (s_info.cam_azimuth > 1) { + s_info.cam_azimuth = -1; + } + + float angle = math_helper_range_map(s_info.cam_azimuth, -1, 1, -180.0f, 180.0f); + view_base_set_angle(s_info.camera_azimuth_indicator, angle, 180.0, 180.0); + _D("[CAM] AZIMUTH: % f", s_info.cam_azimuth); + + return ECORE_CALLBACK_RENEW; +} + +void _camera_button_cb(void *data, Evas_Object *obj, const char *emission, const char *source) +{ + e_camera_button_action camera_button = (e_camera_button_action)data; + + switch (camera_button) { + case CAMERA_BUTTON_RIGHT_UP: + s_info.cam_buttons_pressed[1] = false; + break; + case CAMERA_BUTTON_RIGHT_DOWN: + s_info.cam_buttons_pressed[1] = true; + break; + case CAMERA_BUTTON_LEFT_UP: + s_info.cam_buttons_pressed[0] = false; + break; + case CAMERA_BUTTON_LEFT_DOWN: + s_info.cam_buttons_pressed[0] = true; + break; + default: + break; + } + + if ((s_info.cam_buttons_pressed[0] || s_info.cam_buttons_pressed[1]) && !s_info.cam_animator) { + s_info.cam_animator = ecore_animator_add(_camera_azimuth_animator_cb, NULL); + } else if (s_info.cam_animator) { + ecore_animator_del(s_info.cam_animator); + s_info.cam_animator= NULL; + } + + _D("Camera button action: %d", camera_button); +} + static void _view_racing_create_gui(Evas_Object *parent) { s_info.view_base.view = view_base_create_layout(parent, "edje/racing.edj", GRP_MAIN); @@ -150,12 +225,30 @@ static void _view_racing_create_gui(Evas_Object *parent) s_info.direction_angle, "images/circle.png", HORIZONTAL_ALIGN_CENTER, VERTICAL_ALIGN_TOP); + s_info.camera_azimuth_indicator = _create_image(parent, 180, -5, 17, 17, + 0.0f, + "images/circle.png", HORIZONTAL_ALIGN_CENTER, VERTICAL_ALIGN_TOP); + evas_object_color_set(s_info.camera_azimuth_indicator, 0, 255, 255, 255); + + s_info.camera_elevation_indicator = _create_image(parent, 180, -5, 17, 17, + 180.0f, + "images/circle.png", HORIZONTAL_ALIGN_CENTER, VERTICAL_ALIGN_TOP); + evas_object_color_set(s_info.camera_elevation_indicator, 255, 0, 0, 255); + + + evas_object_event_callback_add(s_info.view_base.view, EVAS_CALLBACK_DEL, _view_destroyed_cb, NULL); elm_layout_signal_callback_add(s_info.view_base.view, "bg_clicked", "", _racing_screen_clicked_cb, NULL); elm_layout_signal_callback_add(s_info.view_base.view, "stop_pressed", "", _stop_longpress_completed, NULL); elm_layout_signal_callback_add(s_info.view_base.view, "stop_released", "", _stop_logpress_up, NULL); + elm_layout_signal_callback_add(s_info.view_base.view, "cam_right_down", "", _camera_button_cb, (void *)CAMERA_BUTTON_RIGHT_DOWN); + elm_layout_signal_callback_add(s_info.view_base.view, "cam_right_up", "", _camera_button_cb, (void *)CAMERA_BUTTON_RIGHT_UP); + + elm_layout_signal_callback_add(s_info.view_base.view, "cam_left_down", "", _camera_button_cb, (void *)CAMERA_BUTTON_LEFT_DOWN); + elm_layout_signal_callback_add(s_info.view_base.view, "cam_left_up", "", _camera_button_cb, (void *)CAMERA_BUTTON_LEFT_UP); + controller_racing_set_stop(false); } @@ -167,6 +260,9 @@ static void _show_cb(void) evas_object_show(s_info.velocity); evas_object_show(s_info.direction); + evas_object_show(s_info.camera_azimuth_indicator); + evas_object_show(s_info.camera_elevation_indicator); + controller_racing_init(_controller_cb); ASSERT_FUNCTION_END; @@ -178,6 +274,9 @@ static void _hide_cb(void) evas_object_hide(s_info.velocity); evas_object_hide(s_info.direction); + + evas_object_hide(s_info.camera_azimuth_indicator); + evas_object_hide(s_info.camera_elevation_indicator); controller_racing_destroy(); ASSERT_FUNCTION_END; |