Ophidian
 All Classes Namespaces Functions
canvas.h
1 /*
2  * Copyright 2016 Ophidian
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0
12 
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19  */
20 
21 #ifndef OPHIDIAN_GUI_CANVAS_H
22 #define OPHIDIAN_GUI_CANVAS_H
23 
24 #include <SFML/Graphics.hpp>
25 #include "../geometry/geometry.h"
26 #include "drawable_batch.h"
27 
28 namespace ophidian {
29 namespace gui {
30 
31 struct line {
32  entity_system::entity entity;
33 };
34 
35 struct quad {
36  entity_system::entity entity;
37  bool operator==(const quad & o) const {
38  return entity == o.entity;
39  }
40 };
41 
42 struct wire_quad {
43  std::array<line, 4> lines;
44 };
45 
46 struct thick_line {
47  quad q;
48 };
49 
50 
51 }}
52 namespace std
53 {
54 template<> struct hash<ophidian::gui::quad>
55 {
56  typedef ophidian::gui::quad argument_type;
57  typedef std::size_t result_type;
58  result_type operator()(argument_type const& s) const
59  {
60  hash<ophidian::entity_system::entity> hash1;
61  return hash1(s.entity);
62  }
63 };
64 }
65 
66 
67 namespace ophidian {
68 namespace gui {
69 
70 
71 class arrow;
72 class canvas : public sf::Drawable
73 {
74  drawable_batch<2> m_lines{sf::Lines};
75  drawable_batch<4> m_quads{sf::Quads};
76  drawable_batch<4> m_arrow_lines{sf::Quads};
77 
78  std::vector< arrow > m_arrows;
79 
80 public:
81  canvas();
82  virtual ~canvas();
83  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
84 
85  line line_create(const geometry::point<double> & p1, const geometry::point<double> & p2);
86  void destroy(line the_line);
87  void transform(line the_line, const sf::Transform & transformation);
88  void paint(line the_line, sf::Color color);
89 
90  quad quad_create(const geometry::point<double> & p1, const geometry::point<double> & p2, const geometry::point<double> & p3, const geometry::point<double> & p4);
91  void destroy(quad the_quad);
92  void transform(quad the_quad, const sf::Transform & transformation);
93  void paint(quad the_quad, sf::Color color);
94 
95  thick_line thick_line_create(const geometry::point<double> & p1, const geometry::point<double> & p2, std::size_t thickness);
96  void destroy(thick_line the_line);
97  void transform(thick_line the_line, const sf::Transform & transformation);
98  void paint(thick_line the_line, sf::Color color);
99  void thick_line_update(thick_line the_line, const geometry::point<double> & p1, const geometry::point<double> & p2);
100 
101 
102  void arrow_create(thick_line line, quad q1, quad q2, const geometry::point<double> & offset1, const geometry::point<double> & offset2);
103  void clear_arrows();
104 
105 
106  void quad_update(quad the_quad, const geometry::point<double> & p1, const geometry::point<double> & p2, const geometry::point<double> & p3, const geometry::point<double> & p4);
107  void quads_animate(batch_animation *animation);
108  const std::array<sf::Vertex, 4> & quad_points(quad the_quad) const {
109  return m_quads.points(the_quad.entity);
110  }
111 
112 
113 
114 
115  void destroy(const wire_quad & the_wirequad);
116 
117  void update();
118 
119  drawable_batch<4>& quads() {
120  return m_quads;
121  }
122 
123 
124  bool has_animation() const;
125 
126  void clear();
127 
128 };
129 
130 struct arrow {
131  struct endpoint {
132  gui::quad quad;
133  geometry::point<double> offset;
134  };
135  gui::thick_line m_line;
136  endpoint m_p1;
137  endpoint m_p2;
138  void update(ophidian::gui::canvas &canvas);
139 };
140 
141 }
142 }
143 
144 #endif // OPHIDIAN_GUI_CANVAS_H
Definition: canvas.h:131
Definition: drawable_batch.h:12
Definition: canvas.h:35
Definition: canvas.h:130
Definition: canvas.h:46
Definition: canvas.h:42
Definition: canvas.h:31
Definition: canvas.h:72