Piano / src / view /

piano-callbacks.c

  1. /*
  2. * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License);
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. #include "config.h"
  18. #include "view/piano-callbacks.h"
  19. #include "logger.h"
  20. #include "player/piano-impl.h"
  21. #include "player/piano-player.h"
  22. #include "piano-structs.h"
  23.  
  24. void piano_note_touch_down_cb(void *data, Evas *e, Evas_Object *button, void *event_info)
  25. {
  26. RETM_IF(!data, "data is NULL");
  27.  
  28. note_struct *note = (note_struct *)data;
  29.  
  30. Evas_Event_Multi_Down *ev = (Evas_Event_Multi_Down *)event_info;
  31. if (note->ad->previous_button == note) {
  32. return;
  33. }
  34.  
  35. piano_note_touch_down(data, ev->output, EINA_TRUE);
  36. note->ad->previous_button = note;
  37. }
  38.  
  39. void piano_note_touch_up_cb(void *data, Evas *e, Evas_Object *button, void *event_info)
  40. {
  41. RETM_IF(!data, "data is NULL");
  42.  
  43. piano_note_touch_up(data);
  44. }
  45.  
  46. void piano_note_mouse_down_cb(void *data, Evas *e, Evas_Object *button, void *event_info)
  47. {
  48. RETM_IF(!data, "data is NULL");
  49.  
  50. Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down *)event_info;
  51.  
  52. note_struct *note = (note_struct *)data;
  53.  
  54. piano_note_touch_down(data, ev->output, EINA_TRUE);
  55.  
  56. evas_object_focus_set(button, EINA_FALSE);
  57. note->ad->previous_button = note;
  58. }
  59.  
  60. void piano_note_mouse_up_cb(void *data, Evas *e, Evas_Object *button, void *event_info)
  61. {
  62. RETM_IF(!data, "data is NULL");
  63.  
  64. piano_note_touch_up(data);
  65. }
  66.  
  67. void piano_note_mouse_out_cb(void *data, Evas *e, Evas_Object *button, void *event_info)
  68. {
  69. RETM_IF(!data, "data is NULL");
  70.  
  71. piano_note_touch_up(data);
  72. }
  73.  
  74. void piano_note_mouse_in_cb(void *data, Evas *e, Evas_Object *button, void *event_info)
  75. {
  76. RETM_IF(!data, "data is NULL");
  77.  
  78. Evas_Event_Mouse_In *ev = (Evas_Event_Mouse_In *)event_info;
  79.  
  80. piano_note_touch_down(data, ev->output, EINA_FALSE);
  81.  
  82. evas_object_focus_set(button, EINA_FALSE);
  83. }
  84.  
  85. void piano_note_mouse_move_cb(void *data, Evas *e, Evas_Object *button, void *event_info)
  86. {
  87. Evas_Event_Mouse_In *ev = (Evas_Event_Mouse_In *)event_info;
  88. static int old_pos_y = 0;
  89. const int max_pos_y = 50;
  90. if (data && (abs(old_pos_y - ev->output.y) > max_pos_y)) {
  91. old_pos_y = ev->output.y;
  92.  
  93. note_struct *note = (note_struct *)data;
  94. if (note->ad->previous_button == note) {
  95. return;
  96. }
  97.  
  98. piano_note_touch_up(data);
  99. piano_note_touch_down(data, ev->output, EINA_FALSE);
  100.  
  101. note->ad->previous_button = note;
  102. }
  103. }
  104.  
  105. Eina_Bool piano_note_timer_cb(void *data)
  106. {
  107. RETVM_IF(!data, EINA_FALSE, "data is NULL");
  108.  
  109. app_data *ad = (app_data *)data;
  110.  
  111. Eina_List *l = NULL;
  112. note_struct *list_item_note = NULL;
  113. EINA_LIST_FOREACH(ad->buttonList, l, list_item_note) {
  114. const Evas *evas_button = evas_object_evas_get(list_item_note->button);
  115.  
  116. if (evas_button && !evas_pointer_button_down_mask_get(evas_button)) {
  117. elm_object_signal_emit(list_item_note->button, "default", "*");
  118. }
  119. }
  120.  
  121. return EINA_TRUE;
  122. }