Fix indentation
[platform/core/uifw/inputdelegator.git] / src / MicEffector.cpp
old mode 100755 (executable)
new mode 100644 (file)
index ab4de04..b318e57
  * limitations under the License.
  */
 
+#define EFL_BETA_API_SUPPORT 1
+#define EFL_EO_API_SUPPORT 1
+
+#include <Eo.h>
+
 #include <string.h>
-#include <efl_assist.h>
 #include "MicEffector.h"
 
+#include <Elementary.h>
+#include <Evas.h>
+#include <dlog.h>
+#undef LOG_TAG
+#define LOG_TAG "INPUT_DELEGATOR"
+
+
 using namespace is::ui;
 
 /**
@@ -34,28 +45,27 @@ static float timeout_s = 1.0f / 60.0f;
 
 double cubic_easy_in_out(double index, double start, double end, double duration)
 {
-       index /= duration/2;
-       if (index < 1)
-               return end/2*index*index*index + start;
+    index /= duration/2;
+    if (index < 1)
+        return end/2*index*index*index + start;
 
-       index -= 2;
-       return end/2*(index*index*index + 2) + start;
+    index -= 2;
+    return end/2*(index*index*index + 2) + start;
 }
 
 double cubic_easy_in(double index, double start, double end, double duration)
 {
-       index /= duration;
-       return end*index*index*index*index*index + start;
+    index /= duration;
+    return end*index*index*index*index*index + start;
 }
 
 double cubic_easy_out(double index, double start, double end, double duration)
 {
-       index /= duration;
-       index--;
-       return end*(index*index*index + 1) + start;
+    index /= duration;
+    index--;
+    return end*(index*index*index + 1) + start;
 }
 
-
 /**
  * Constructor
  *
@@ -64,30 +74,32 @@ double cubic_easy_out(double index, double start, double end, double duration)
  * #2. Drawing empty frame to avoid broken screen.
  *
  */
-
 MicEffector::MicEffector(Evas_Object *canvas, Evas_Object *layout, IMicEffector& effect)
-       : drawcount(0)
-       , forcestop(false)
-       , started(false)
-       , fake(false)
-       , timer(NULL)
-       , layout(layout)
-       , ieffect(effect)
+    : drawcount(0)
+    , forcestop(false)
+    , started(false)
+    , fake(false)
+    , timer(NULL)
+    , layout(layout)
+    , ieffect(effect)
 {
-//     path = ea_vector_path_create();
-//     paint = ea_vector_paint_create();
-//     ea_vector_paint_set_style(paint, EA_VECTOR_PAINT_STYLE_STROKE);
-//     ea_vector_paint_set_line_cap(paint, EA_VECTOR_PAINT_LINE_CAP_ROUND);
-//     ea_vector_paint_set_line_join(paint, EA_VECTOR_PAINT_LINE_JOIN_ROUND);
-//     ea_vector_paint_set_line_width(paint, 3.0);
-//     ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, 1.0f);
+    vg = evas_object_vg_add(evas_object_evas_get(canvas));
+    evas_object_show(vg);
 
-//     this->canvas = ea_vector_canvas_create(canvas);
+    root = evas_object_vg_root_node_get(vg);
+    shape = evas_vg_shape_add(root);
+    evas_vg_node_color_set(shape, 80, 80, 80, 80);
 
-       DrawDummyFrame();
-};
+    elm_object_part_content_set(layout, "EFFECT_BG", vg);
 
+    evas_vg_shape_stroke_cap_set(shape, EFL_GFX_CAP_BUTT);
+    evas_vg_shape_stroke_join_set(shape, EFL_GFX_JOIN_MITER);
 
+    evas_vg_shape_stroke_width_set(shape, 3.0);
+    evas_vg_shape_stroke_color_set(shape, 255, 255, 255, 255);
+
+    DrawDummyFrame();
+};
 
 /**
  * Destructor
@@ -97,32 +109,32 @@ MicEffector::MicEffector(Evas_Object *canvas, Evas_Object *layout, IMicEffector&
  */
 MicEffector::~MicEffector()
 {
-       if(timer)
-       {
-               ecore_timer_del(timer);
-               timer = NULL;
-       }
-
-//     ea_vector_path_destroy(path);
-//     ea_vector_paint_destroy(paint);
-//     ea_vector_canvas_destroy(canvas);
+    if (timer) {
+        ecore_timer_del(timer);
+        timer = NULL;
+    }
+    if (vg)
+        evas_object_del(vg);
+
+    if (root)
+        evas_object_del(root);
+
+    if (shape)
+        evas_object_del(shape);
 }
 
-
-
 /**
  * Draw empty frame to remove or initiate screen
  *
  */
 void MicEffector::DrawDummyFrame()
 {
-//     ea_vector_path_reset(path);
-//     ea_vector_path_move_to(path, 0, 0);
-//     ea_vector_path_line_to(path, 0, 0);
-//     ea_vector_canvas_draw(canvas, path, paint);
-}
-
+    evas_vg_shape_reset(shape);
+    evas_vg_shape_append_move_to(shape, 0, 0);
+    evas_vg_shape_append_line_to(shape, 0, 0);
 
+    evas_object_show(vg);
+}
 
 /**
  * Draw Que animation
@@ -135,83 +147,80 @@ void MicEffector::DrawDummyFrame()
  */
 void MicEffector::DrawQue(int idx, bool is_start)
 {
-//     float margin = spectrum_posx;
-//     float posx = 0.0;
-
-       double speed = cubic_easy_out(idx + 1.0, 0.0, 23.0, 23);
+    float margin = spectrum_posx;
+    float posx = 0.0;
 
-       unsigned int start = start_stop_anim_count - (int) speed;
-       unsigned int end = start_stop_anim_count + (int) speed;
+    double speed = cubic_easy_out(idx + 1.0, 0.0, 23.0, 23);
 
-//     double opacity;
+    unsigned int start = start_stop_anim_count - (int) speed;
+    unsigned int end = start_stop_anim_count + (int) speed;
 
-       if (is_start) {
-//             opacity = cubic_easy_out(idx, 0.0, 1.0, 26.0);
-       } else {
-//             opacity = cubic_easy_out(idx, 0, 1.0, 26.0);
-       }
+    double opacity = 0.0;;
 
-//     ea_vector_path_reset(path);
+    if (is_start) {
+        opacity = cubic_easy_out(idx, 0.0, 1.0, 26.0);
+    } else {
+        opacity = cubic_easy_out(idx, 0, 1.0, 26.0);
+    }
 
-       for(unsigned int i = start; i < end; i++)
-       {
-//             posx = margin + (i * 5);
+    evas_vg_shape_reset(shape);
 
-//             ea_vector_path_move_to(path, posx, 37.0f);
-//             ea_vector_path_line_to(path, posx, 38.0f);
+    for (unsigned int i = start; i < end; i++)
+    {
+        posx = margin + (i * 5);
 
-//             ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity);
-       }
+        evas_vg_shape_append_move_to(shape, posx, 37);
+        evas_vg_shape_append_line_to(shape, posx, 38);
+        evas_vg_shape_stroke_color_set(shape, 255, 255, 255, opacity);
+    }
 
-//     ea_vector_canvas_draw(canvas, path, paint);
+    evas_object_show(vg);
 }
 
-
-
 float MicEffector::GetAmplifyValue(unsigned int idx)
 {
-       float amplify = 0.0;
+    float amplify = 0.0;
 
-       int max[SAMPLE_COUNT] = {
-               /**
-                * dot "A" (9)
-                *
-                */
-               1, 1, 1, 1,
+    int max[SAMPLE_COUNT] = {
+        /**
+         * dot "A" (9)
+         *
+         */
+        1, 1, 1, 1,
 
 
-               1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1,
 
-               /**
-                * dot "B" (9)
-                *
-                */
-               10, 8, 2, 3, 10, 11, 6, 12, 4,
+        /**
+         * dot "B" (9)
+         *
+         */
+        10, 8, 2, 3, 10, 11, 6, 12, 4,
 
-               /**
-                * dot "C" (15)
-                *
-                */
-                3, 5, 9, 12, 11, 8, 14, 15, 13, 11, 12, 6, 8, 3, 2,
+        /**
+         * dot "C" (15)
+         *
+         */
+         3, 5, 9, 12, 11, 8, 14, 15, 13, 11, 12, 6, 8, 3, 2,
 
-               /**
-                * reverse dot "B" (9)
-                *
-                */
-                4, 12, 6, 11, 10, 3, 2, 8, 10,
+        /**
+         * reverse dot "B" (9)
+         *
+         */
+         4, 12, 6, 11, 10, 3, 2, 8, 10,
 
-               /**
-                * dot "A" (9)
-                *
-                */
-               1, 1, 1, 1, 1, 1, 1, 1, 1,
+        /**
+         * dot "A" (9)
+         *
+         */
+        1, 1, 1, 1, 1, 1, 1, 1, 1,
 
-               1, 1, 1, 1
-       };
+        1, 1, 1, 1
+    };
 
-       amplify = (float) max[idx] / 10.0f * 1.9f;
+    amplify = (float) max[idx] / 10.0f * 1.9f;
 
-       return amplify;
+    return amplify;
 }
 
 /**
@@ -223,84 +232,77 @@ float MicEffector::GetAmplifyValue(unsigned int idx)
  */
 void MicEffector::DrawWave(unsigned int idx, int amount, int prev_amount, double opacity, bool is_lastcmd)
 {
-//     float ratio = GetAmplifyValue(idx);
+    float ratio = GetAmplifyValue(idx);
 
-//     float am = ((float) amount) * ratio;
-//     float pam = ((float) prev_amount) * ratio;
-//     float cnt = (float) drawcount;
+    float am = ((float) amount) * ratio;
+    float pam = ((float) prev_amount) * ratio;
+    float cnt = (float) drawcount;
 
-       float posx = spectrum_posx;
+    float posx = spectrum_posx;
 
-//     float height = pam > am?
-//             pam - cubic_easy_in_out(cnt + 1.0, am, pam, 7):
-//             cubic_easy_in_out(cnt + 1.0, pam, am, 7);
+    float height = pam > am?
+        pam - cubic_easy_in_out(cnt + 1.0, am, pam, 7):
+        cubic_easy_in_out(cnt + 1.0, pam, am, 7);
 
-       posx += idx * 5;
+    posx += idx * 8;
 
-//     ea_vector_path_move_to(path, posx, (37.0f - (height / 2.0)));
-//     ea_vector_path_line_to(path, posx, (38.0f + (height / 2.0)));
-
-       if (is_lastcmd) {
-//             ea_vector_paint_set_color(paint, 0.1451f, 0.204f, 0.255f, opacity);//RGB = 37:52:65
-       } else {
-//             ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity);//RGB: 255 255 255
-       }
+    evas_vg_shape_append_move_to(shape, posx, (37.0f - (height / 2.0)));
+    evas_vg_shape_append_line_to(shape, posx, (38.0f + (height / 2.0)));
+    evas_vg_shape_stroke_color_set(shape, 255, 255, 255, opacity);
 }
 
-
-
 /**
  * Effect Start
  *
  */
 void MicEffector::Start()
 {
-       if(timer) {
-               ecore_timer_del(timer);
-               timer = NULL;
-       }
-
-       drawcount = 0;
-
-       prev.clear();
-       current.clear();
-
-       for(size_t i = 0; i < spectrum_count; i++)
-       {
-               prev.push_back(0);
-               current.push_back(0);
-       }
-
-       Listening();
-
-       /**
-        * Que animation
-        *
-        */
-       timer = ecore_timer_add(timeout_s,
-                               [](void *data)->Eina_Bool
-                               {
-                                       MicEffector *effector = static_cast<MicEffector*>(data);
-
-                                       effector->DrawQue(effector->drawcount);
-
-                                       if(effector->drawcount < (int) start_stop_anim_count) {
-                                               effector->drawcount += 2;
-                                               return ECORE_CALLBACK_RENEW;
-                                       } else {
-                                               for(unsigned int i = 0; i < spectrum_count; i++)
-                                                       effector->DrawWave(i, 0, 0);
-
-//                                             ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint);
-
-                                               effector->drawcount = 0;
-                                               effector->timer = NULL;
-                                               effector->VolumeCheck();
-                                               effector->Effect();
-                                               return ECORE_CALLBACK_CANCEL;
-                                       }
-                               },
-                               this);
+    if (timer) {
+        ecore_timer_del(timer);
+        timer = NULL;
+    }
+
+    drawcount = 0;
+
+    prev.clear();
+    current.clear();
+
+    for (size_t i = 0; i < spectrum_count; i++)
+    {
+        prev.push_back(0);
+        current.push_back(0);
+    }
+
+    Listening();
+
+    /**
+     * Que animation
+     *
+     */
+    timer = ecore_timer_add(timeout_s,
+                [](void *data)->Eina_Bool
+                {
+                    MicEffector *effector = static_cast<MicEffector*>(data);
+
+                    effector->DrawQue(effector->drawcount);
+
+                    if (effector->drawcount < (int) start_stop_anim_count) {
+                        effector->drawcount += 2;
+                        return ECORE_CALLBACK_RENEW;
+                    } else {
+                        for (unsigned int i = 0; i < spectrum_count; i++)
+                            effector->DrawWave(i, 0, 0);
+
+                        evas_object_show(effector->vg);
+
+                        effector->drawcount = 0;
+                        effector->timer = NULL;
+                        effector->VolumeCheck(true);
+                        effector->Effect();
+                        return ECORE_CALLBACK_CANCEL;
+                    }
+                },
+                this);
 }
 
 /**
@@ -309,90 +311,83 @@ void MicEffector::Start()
  */
 void MicEffector::Effect(bool fake)
 {
-       /**
-        * Volume effect animation
-        *
-        */
-       if ( timer ) {
-                       ecore_timer_del(timer);
-                       timer = NULL;
-       }
-
-       timer = ecore_timer_add(timeout_s,
-                               [](void *data)->Eina_Bool
-                               {
-                                       MicEffector *effector = static_cast<MicEffector *>(data);
-
-                                       bool is_empty_prev = effector->prev.empty();
-
-
-//                                     ea_vector_path_reset(effector->path);
-
-                                       for(unsigned int i = 0; i < effector->current.size(); i++)
-                                       {
-                                               if (is_empty_prev)
-                                                       effector->DrawWave(i, effector->current.at(i), 0);
-                                               else
-                                                       effector->DrawWave(i, effector->current.at(i), effector->prev.at(i));
-                                       }
-//                                     ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint);
-
-                                       if (effector->drawcount < 7)    {
-                                               effector->drawcount++;
-                                       } else {
-                                               effector->drawcount = 0;
-                                               effector->VolumeCheck(effector->fake);
-                                       }
-
-                                       return ECORE_CALLBACK_RENEW;
-                               }, this);
+    /**
+     * Volume effect animation
+     *
+     */
+    if ( timer ) {
+            ecore_timer_del(timer);
+            timer = NULL;
+    }
+
+    timer = ecore_timer_add(timeout_s,
+                [](void *data)->Eina_Bool
+                {
+                    MicEffector *effector = static_cast<MicEffector *>(data);
+
+                    bool is_empty_prev = effector->prev.empty();
+
+                    evas_vg_shape_reset(effector->shape);
+
+                    for (unsigned int i = 0; i < effector->current.size(); i++)
+                    {
+                        if (is_empty_prev) {
+                            effector->DrawWave(i, effector->current.at(i), 0);
+                        } else {
+                            effector->DrawWave(i, effector->current.at(i), effector->prev.at(i));
+                        }
+                    }
+                    evas_object_show(effector->vg);
+
+                    if (effector->drawcount < 7)    {
+                        effector->drawcount++;
+                        effector->VolumeCheck(true);
+                    } else {
+                        effector->drawcount = 0;
+                        effector->VolumeCheck(true);
+                    }
+
+                    return ECORE_CALLBACK_RENEW;
+                }, this);
 }
 
-
-
 /**
  * Stop volume animation effect
  *
  */
 void MicEffector::Stop(bool forced)
 {
-       if(timer)
-       {
-               ecore_timer_del(timer);
-               timer = NULL;
-       }
-
-       if(!started)
-       {
-               Idle();
-               return;
-       }
-
-       forcestop = forced;
-
-       timer = ecore_timer_add(timeout_s,
-               [](void *data)->Eina_Bool
-               {
-                       MicEffector *effector = static_cast<MicEffector*>(data);
-
-                       effector->DrawQue(start_stop_anim_count - effector->drawcount, false);
-
-                       if(effector->drawcount < (int) start_stop_anim_count) {
-                               effector->drawcount += 2;
-                               return ECORE_CALLBACK_RENEW;
-                       } else {
-                               if(!effector->forcestop) {
-                                       effector->Processing();
-                               } else {
-                                       effector->Idle();
-                               }
-
-                               effector->forcestop = false;
-                               effector->drawcount = 0;
-                               effector->timer = NULL;
-                               return ECORE_CALLBACK_CANCEL;
-                       }
-               }, this);
+    if (timer)
+    {
+        ecore_timer_del(timer);
+        timer = NULL;
+    }
+
+    if (!started)
+    {
+        Idle();
+        return;
+    }
+
+    forcestop = forced;
+
+    timer = ecore_timer_add(timeout_s,
+        [](void *data)->Eina_Bool
+        {
+            MicEffector *effector = static_cast<MicEffector*>(data);
+
+            effector->DrawQue(start_stop_anim_count - effector->drawcount, false);
+
+            if (effector->drawcount < (int) start_stop_anim_count) {
+                effector->drawcount += 2;
+                return ECORE_CALLBACK_RENEW;
+            } else {
+                effector->forcestop = false;
+                effector->drawcount = 0;
+                effector->timer = NULL;
+                return ECORE_CALLBACK_CANCEL;
+            }
+        }, this);
 }
 
 /**
@@ -401,79 +396,73 @@ void MicEffector::Stop(bool forced)
  */
 void MicEffector::VolumeCheck(bool fake)
 {
-       std::vector<int> volumes;
+    std::vector<int> volumes;
 
-       this->fake = fake;
+    this->fake = fake;
 
-       if(!fake) {
-               volumes = ieffect.GetVolume();
-       } else {
-               for(unsigned int i = 0; i < spectrum_count; i++) {
-                       volumes.push_back(rand_r((unsigned int*)time(NULL)) % 2);
-               }
-       }
+    if (!fake) {
+        volumes = ieffect.GetVolume();
+    } else {
+        for (unsigned int i = 0; i < spectrum_count; i++) {
+            unsigned int seed = time(NULL);
+            volumes.push_back(rand_r(&seed) % 6);
+        }
+    }
 
-       prev.clear();
-       prev.assign(current.begin(), current.end());
+    prev.clear();
+    prev.assign(current.begin(), current.end());
 
-       current.clear();
-       current.assign(volumes.begin(), volumes.end());
+    current.clear();
+    current.assign(volumes.begin(), volumes.end());
 }
 
-
-
 /**
  * Signal. Listening effect
  *
  */
 void MicEffector::Listening()
 {
-       started = true;
+    started = true;
 
-       elm_object_signal_emit(layout, "elm,state,eq,show", "eq");
-       elm_object_signal_emit(layout, "elm,state,listening", "elm");
+    elm_object_signal_emit(layout, "elm,state,listening", "elm");
+    elm_object_signal_emit(layout, "elm,state,eq,show", "eq");
 }
 
-
-
 /**
  * Signal. Processing effect
  *
  */
 void MicEffector::Processing()
 {
-       started = false;
+    started = false;
 
-       elm_object_signal_emit(layout, "elm,state,eq,hide", "eq");
-       elm_object_signal_emit(layout, "elm,state,processing", "elm");
+    elm_object_signal_emit(layout, "elm,state,eq,hide", "eq");
+    elm_object_signal_emit(layout, "elm,state,processing", "elm");
 
-       ieffect.ProcessingAnimationStart();
+    ieffect.ProcessingAnimationStart();
 }
 
-
-
 /**
  * Signal. Idle effect
  *
  */
 void MicEffector::Idle()
 {
-       const char *text;
-       const char *state;
-       double val;
+    const char *text;
+    const char *state;
+    double val;
 
-       started = false;
+    started = false;
 
-       elm_object_signal_emit(layout, "elm,state,eq,hide", "eq");
+    elm_object_signal_emit(layout, "elm,state,eq,hide", "eq");
 
-       text = elm_object_part_text_get(layout, "elm.text");
-       state = edje_object_part_state_get(elm_layout_edje_get(layout), "guide_text_block", &val);
+    text = elm_object_part_text_get(layout, "elm.text");
+    state = edje_object_part_state_get(elm_layout_edje_get(layout), "guide_text_block", &val);
 
-       if ((text && strlen(text) > 0) && (state && !strcmp(state, "bottom")))
-               elm_object_signal_emit(layout, "elm,state,init_message", "elm");
-       else
-               elm_object_signal_emit(layout, "elm,state,init", "elm");
+    if ((text && strlen(text) > 0) && (state && !strcmp(state, "bottom")))
+        elm_object_signal_emit(layout, "elm,state,init_message", "elm");
+    else
+        elm_object_signal_emit(layout, "elm,state,init", "elm");
 
-       ieffect.ProcessingAnimationStop();
+    ieffect.ProcessingAnimationStop();
 }
-