EOM / src /

view.c

  1. /*
  2. * Samsung API
  3. * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the License);
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/license/
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an AS IS BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17.  
  18. #include "log.h"
  19. #include "view.h"
  20. #include "eom_sample.h"
  21.  
  22. static Evas_Object *_create_box(Evas_Object *parent)
  23. {
  24. Evas_Object *box = NULL;
  25.  
  26. retv_if(!parent, NULL);
  27.  
  28. box = elm_box_add(parent);
  29. retv_if(!box, NULL);
  30.  
  31. evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  32. evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
  33.  
  34. return box;
  35. }
  36.  
  37. static void _destroy_box(Evas_Object *box)
  38. {
  39. ret_if(!box);
  40.  
  41. evas_object_del(box);
  42. }
  43.  
  44. static Evas_Object *_create_grid(Evas_Object *parent)
  45. {
  46. Evas_Object *grid = NULL;
  47.  
  48. retv_if(!parent, NULL);
  49.  
  50. grid = elm_grid_add(parent);
  51. retv_if(!grid, NULL);
  52.  
  53. evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  54. evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
  55. evas_object_show(grid);
  56.  
  57. return grid;
  58. }
  59.  
  60. static void _destroy_grid(Evas_Object *grid)
  61. {
  62. ret_if(!grid);
  63.  
  64. evas_object_del(grid);
  65. }
  66.  
  67. static Evas_Object *_create_btn(Evas_Object *parent, char *text)
  68. {
  69. Evas_Object *btn = NULL;
  70.  
  71. retv_if(!parent, NULL);
  72.  
  73. btn = elm_button_add(parent);
  74. retv_if(!btn, NULL);
  75.  
  76. elm_object_style_set(btn, "circle");
  77. elm_object_text_set(btn, text);
  78. evas_object_show(btn);
  79.  
  80. return btn;
  81. }
  82.  
  83. static void _destroy_btn(Evas_Object *btn)
  84. {
  85. ret_if(!btn);
  86.  
  87. evas_object_del(btn);
  88. }
  89.  
  90. static Evas_Object *_create_bg(Evas_Object *parent, int type)
  91. {
  92. Evas_Object *bg = NULL;
  93.  
  94. retv_if(!parent, NULL);
  95.  
  96. bg = elm_bg_add(parent);
  97. retv_if(!bg, NULL);
  98.  
  99. evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  100. evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
  101.  
  102. if (type == 1) {
  103. elm_bg_file_set(bg, BG_DIR, NULL);
  104. evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  105. evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
  106. elm_win_resize_object_add(parent, bg);
  107. } else {
  108. elm_bg_color_set(bg, 0, 40, 40);
  109. }
  110. evas_object_show(bg);
  111.  
  112. return bg;
  113. }
  114.  
  115. static void _destroy_bg(Evas_Object *bg)
  116. {
  117. ret_if(!bg);
  118.  
  119. evas_object_del(bg);
  120. }
  121.  
  122. extern Evas_Object *view_create_eom_display(appdata_s *ad)
  123. {
  124. Evas_Object *box = NULL;
  125. Evas_Object *grid = NULL;
  126. Evas_Object *bg = NULL;
  127. viewdata_s *vd = NULL;
  128.  
  129. retv_if(!ad, NULL);
  130.  
  131. box = _create_box(ad->layout);
  132. retv_if(!box, NULL);
  133. grid = _create_grid(box);
  134. goto_if(!grid, ERROR);
  135. bg = _create_bg(grid, 1);
  136. goto_if(!bg, ERROR);
  137. elm_grid_pack(grid, bg, 0, 0, 100, 100);
  138.  
  139. /* memory allocate */
  140. vd = calloc(1, sizeof(viewdata_s));
  141. goto_if(!vd, ERROR);
  142. vd->bg = bg;
  143. ad->vd = vd;
  144.  
  145. /* set label */
  146. vd->text1 = elm_label_add(grid);
  147. goto_if(!vd->text1, ERROR);
  148.  
  149. if (ad->support_external_display)
  150. {
  151. elm_object_text_set(vd->text1, "<font_size=50><color=#ffffff>Supporting EOM.</color></font_size>");
  152. evas_object_show(vd->text1);
  153. elm_grid_pack(grid, vd->text1, 2, 10, 100, 100);
  154.  
  155. vd->text2 = elm_label_add(grid);
  156. goto_if(!vd->text2, ERROR);
  157. if (ad->connected)
  158. {
  159. elm_object_text_set(vd->text2, "<font_size=40><color=#ffffff>HDMI Connected.</color></font_size>");
  160. evas_object_show(vd->text2);
  161. elm_grid_pack(grid, vd->text2, 2, 30, 100, 100);
  162. }
  163. else
  164. {
  165. elm_object_text_set(vd->text2, "<font_size=40><color=#ffffff>Connect HDMI cable.</color></font_size>");
  166. evas_object_show(vd->text2);
  167. elm_grid_pack(grid, vd->text2, 2, 30, 100, 100);
  168. }
  169.  
  170. vd->text3 = elm_label_add(grid);
  171. goto_if(!vd->text3, ERROR);
  172. if (ad->mode == EOM_OUTPUT_MODE_MIRROR)
  173. {
  174. elm_object_text_set(vd->text3, "<font_size=40><color=#ffffff>Mode : mirror</color></font_size>");
  175. evas_object_show(vd->text3);
  176. elm_grid_pack(grid, vd->text3, 2, 45, 100, 100);
  177. }
  178. else
  179. {
  180. elm_object_text_set(vd->text3, "<font_size=40><color=#ffffff>Mode : presentation</color></font_size>");
  181. evas_object_show(vd->text3);
  182. elm_grid_pack(grid, vd->text3, 2, 45, 100, 100);
  183. }
  184. }
  185. else
  186. {
  187. elm_object_text_set(vd->text1, "<font_size=50><color=#ffffff>Not supporting EOM.</color></font_size>");
  188. evas_object_show(vd->text1);
  189. elm_grid_pack(grid, vd->text1, 2, 10, 100, 100);
  190. }
  191.  
  192. elm_box_pack_end(box, grid);
  193.  
  194. return box;
  195.  
  196. ERROR:
  197. if (vd) free(vd);
  198. if (bg) _destroy_bg(bg);
  199. if (grid) _destroy_grid(grid);
  200. if (box) _destroy_box(box);
  201.  
  202. return NULL;
  203.  
  204. }
  205.  
  206. extern Evas_Object *view_create_eom_button(appdata_s *ad)
  207. {
  208. Evas_Object *box = NULL;
  209. Evas_Object *grid = NULL;
  210.  
  211. retv_if(!ad, NULL);
  212.  
  213. box = _create_box(ad->layout);
  214. retv_if(!box, NULL);
  215. grid = _create_grid(box);
  216. goto_if(!grid, ERROR);
  217.  
  218. /* create button */
  219. ad->btn_mirror = _create_btn(grid, "MIRROR");
  220. goto_if(!ad->btn_mirror, ERROR);
  221. elm_grid_pack(grid, ad->btn_mirror, 0, 20, 50, 100);
  222. evas_object_smart_callback_add(ad->btn_mirror, "clicked", eom_button_clicked, ad);
  223.  
  224. ad->btn_presentation = _create_btn(grid, "PRESENTATION");
  225. goto_if(!ad->btn_presentation, ERROR);
  226. elm_grid_pack(grid, ad->btn_presentation, 50, 20, 50, 100);
  227. evas_object_smart_callback_add(ad->btn_presentation, "clicked", eom_button_clicked, ad);
  228.  
  229. elm_box_pack_end(box, grid);
  230.  
  231. return box;
  232.  
  233. ERROR:
  234. if (ad->btn_mirror) _destroy_btn(ad->btn_mirror);
  235. if (grid) _destroy_grid(grid);
  236. if (box) _destroy_box(box);
  237.  
  238. return NULL;
  239. }
  240.  
  241. /* End of file */