pathtest.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "evasapp.h"
  19. #include"vpath.h"
  20. #include<iostream>
  21. using namespace std;
  22. EvasApp *APP;
  23. static void
  24. _on_resize(Ecore_Evas *ee)
  25. {
  26. int w, h;
  27. ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
  28. APP->resize(w, h);
  29. }
  30. class PathTest
  31. {
  32. public:
  33. PathTest(EvasApp *app) {
  34. mApp = app;
  35. mShape = evas_vg_shape_add(mApp->root());
  36. }
  37. void setColor(int r, int g, int b, int a) {
  38. evas_vg_node_color_set(mShape, r, g, b, a);
  39. }
  40. void setStrokeColor(int r, int g, int b, int a) {
  41. evas_vg_shape_stroke_color_set(mShape, r, g, b, a);
  42. }
  43. void setStrokeWidth(int w) {
  44. evas_vg_shape_stroke_width_set(mShape, w);
  45. }
  46. void setPath(const VPath &path) {
  47. Efl_VG *shape = mShape;
  48. evas_vg_shape_reset(shape);
  49. const std::vector<VPath::Element> &elm = path.elements();
  50. const std::vector<VPointF> &pts = path.points();
  51. int i=0;
  52. for (auto e : elm) {
  53. switch(e) {
  54. case VPath::Element::MoveTo:
  55. {
  56. VPointF p = pts[i++];
  57. evas_vg_shape_append_move_to(shape, p.x(), p.y());
  58. break;
  59. }
  60. case VPath::Element::LineTo:
  61. {
  62. VPointF p = pts[i++];
  63. evas_vg_shape_append_line_to(shape, p.x(), p.y());
  64. break;
  65. }
  66. case VPath::Element::CubicTo:
  67. {
  68. VPointF p = pts[i++];
  69. VPointF p1 = pts[i++];
  70. VPointF p2 = pts[i++];
  71. evas_vg_shape_append_cubic_to(shape, p.x(), p.y(), p1.x(), p1.y(), p2.x(), p2.y());
  72. break;
  73. }
  74. case VPath::Element::Close:
  75. {
  76. evas_vg_shape_append_close(shape);
  77. break;
  78. }
  79. }
  80. }
  81. }
  82. public:
  83. EvasApp *mApp;
  84. Efl_VG *mShape;
  85. };
  86. int
  87. main(void)
  88. {
  89. APP = new EvasApp(800, 800);
  90. ecore_evas_callback_resize_set(APP->mEcoreEvas, _on_resize);
  91. APP->setup();
  92. VPath path;
  93. path.addRoundRect(VRectF(100, 100, 200, 200), 20, 20, VPath::Direction::CCW);
  94. path.addCircle(50, 50, 20, VPath::Direction::CCW);
  95. path.addOval(VRectF(300, 100, 100, 50), VPath::Direction::CCW);
  96. path.addPolystar(15.0, 106.0, 34.0, 0.0, 150,
  97. 150, 231.0, 88.0, VPath::Direction::CW);
  98. PathTest test(APP);
  99. test.setPath(path);
  100. test.setColor(255, 0, 0, 255);
  101. test.setStrokeColor(200, 200, 0, 200);
  102. test.setStrokeWidth(5);
  103. APP->run();
  104. delete APP;
  105. return 0;
  106. }