2
#include "ViewCanvas.h"
4
const int CAPTION_X_MARGIN = 6;
5
const int X_MARGIN = 4;
6
const int Y_MARGIN = 4;
8
static const int XMARGIN = 20;
9
static const int YMARGIN = 20;
11
static const int NODE_HANDLE_WIDTH = 8;
12
static const int NODE_HANDLE_HEIGHT = 5;
13
static const int NODE_HANDLE_COLOR = 0xFFFFFFFF;
14
//static const NODE_GRID_SPACING = 32;
18
NUX_IMPLEMENT_OBJECT_TYPE(Canvas);
20
Canvas::Canvas(NUX_FILE_LINE_DECL)
21
: View(NUX_FILE_LINE_PARAM)
23
, selected_view_(NULL)
26
NTextureData bitmap_data;
27
bitmap_data.AllocateCheckBoardTexture(16, 16, 1, Color(0xFF444444), Color(0xFF666666), 8, 8);
28
node_background_texture_.Update(&bitmap_data);
30
SetMinimumSize(DEFAULT_WIDGET_WIDTH+5, PRACTICAL_WIDGET_HEIGHT+5);
31
SetBaseSize(DEFAULT_WIDGET_WIDTH+5, PRACTICAL_WIDGET_HEIGHT+5);
36
std::list<View*>::iterator it;
37
for (it = node_list_.begin(); it != node_list_.end(); it++) // Traverse from front to back.
43
void Canvas::Draw(GraphicsEngine& graphics_engine, bool force_draw)
45
Geometry base = GetGeometry();
46
graphics_engine.PushClippingRectangle(base);
48
GetPainter().PaintShape(graphics_engine, base, Color(0xFF191919), eSHAPE_CORNER_ROUND10, false);
50
graphics_engine.PopClippingRectangle();
53
void Canvas::DrawContent(GraphicsEngine& graphics_engine, bool force_draw)
55
graphics_engine.PushClippingRectangle(GetGeometry());
57
// Draw from Back to front
58
std::list<View*>::reverse_iterator rev_iter;
59
for(rev_iter = node_list_.rbegin(); rev_iter != node_list_.rend(); rev_iter++)
61
(*rev_iter)->ProcessDraw(graphics_engine, force_draw);
64
graphics_engine.PopClippingRectangle();
67
void Canvas::PreLayoutManagement()
72
long Canvas::PostLayoutManagement(long LayoutResult)
75
Geometry base = GetGeometry();
77
std::list<View*>::iterator it;
78
for(it = node_list_.begin(); it != node_list_.end(); it++)
80
(*it)->ComputeContentSize();
83
ret = eCompliantHeight | eCompliantWidth;
87
void Canvas::ComputeContentPosition(float offsetX, float offsetY)
89
Geometry base = GetGeometry();
91
std::list<View*>::iterator it;
92
for(it = node_list_.begin(); it != node_list_.end(); it++)
94
(*it)->ComputeContentPosition(0, 0);
98
void Canvas::OnChildQueueDraw(Area* area)
103
void Canvas::AddView(View* node)
105
// Add a unique View in the list, at the top of the stack.
106
std::list<View*>::iterator iter;
107
iter = std::find(node_list_.begin(), node_list_.end(), node);
108
if(iter == node_list_.end())
111
node_list_.push_front(node);
112
node->SetReconfigureParentLayoutOnGeometryChange(false);
114
node->queue_draw.connect(sigc::mem_fun(this, &Canvas::OnChildQueueDraw));
115
node->child_queue_draw.connect(sigc::mem_fun(this, &Canvas::OnChildQueueDraw));
119
void Canvas::RemoveView( View* node)
121
// Remove a View from the list.
122
std::list<View*>::iterator iter;
123
iter = std::find(node_list_.begin(), node_list_.end(), node);
124
if(iter != node_list_.end())
126
node_list_.erase(iter);
130
void Canvas::SetGridSnaping(unsigned int GridSpacing)
132
grid_snapping_ = (GridSpacing > 0) ? GridSpacing : 1;
135
void Canvas::RecvViewMouseDown(int x, int y, long button_flags, long key_flags, View* view)
137
// Make sure the view is a child of the canvas view
138
std::list<View*>::iterator it;
139
it = std::find(node_list_.begin(), node_list_.end(), view);
141
if (it == node_list_.end())
146
hit_point_ = Point(x, y);
148
// // head_view_ holds the node that just received a mouse down. This node will be pushed at the top of the stack;
149
// head_view_ = view;
150
// selected_view_ = view;
153
void Canvas::RecvViewMouseDrag(int x, int y, int dx, int dy, long button_flags, long key_flags, View* view)
155
// Make sure the view is a child of the canvas view
156
std::list<View*>::iterator it;
157
it = std::find(node_list_.begin(), node_list_.end(), view);
159
if (it == node_list_.end())
169
if(x - hit_point_.x > 0 )
170
ddx = x - hit_point_.x;
174
if(x - hit_point_.x < 0 )
175
ddx = x - hit_point_.x;
180
if(y - hit_point_.y > 0)
181
ddy = y - hit_point_.y;
186
if(y - hit_point_.y < 0)
187
ddy = y - hit_point_.y;
191
Geometry geo = view->GetGeometry();
192
geo.OffsetPosition(ddx, ddy);
199
int X = (geo.x/1) * 1;
200
int Y = (geo.y/1) * 1;
204
view->SetGeometry(geo);
209
void Canvas::CanvasNeedRedraw()
212
// All nodes need to be redrawn.
213
std::list<View*>::iterator iter;
214
for(iter = node_list_.begin(); iter != node_list_.end(); iter++)
216
(*iter)->QueueDraw();
220
Area* Canvas::FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type)
222
std::list<View*>::iterator it;
223
bool mouse_inside = TestMousePointerInclusionFilterMouseWheel(mouse_position, event_type);
225
if (mouse_inside == false)
228
if (node_list_.size() == 0)
230
selected_view_ = NULL;
235
if (event_type == NUX_MOUSE_PRESSED)
237
selected_view_ = NULL;
241
if (event_type == NUX_MOUSE_MOVE)
246
Area* target_area = NULL;
247
bool mouse_inside_child_view = false;
249
const Point relative_mouse_position = Point(mouse_position.x - GetX(), mouse_position.y - GetY());
251
for (it = node_list_.begin(); it != node_list_.end(); it++) // Traverse from front to back.
253
mouse_inside_child_view = (*it)->TestMousePointerInclusionFilterMouseWheel(relative_mouse_position, event_type);
254
if (mouse_inside_child_view)
256
target_area = (*it)->FindAreaUnderMouse(relative_mouse_position, event_type);
261
if (mouse_inside_child_view && node_list_.size())
263
// The mouse has landed on a child view. bring that child view to the front.
265
if (event_type == NUX_MOUSE_PRESSED)
268
selected_view_ = head_view_;
270
if(it != node_list_.end())
272
std::list<View*>::iterator iter;
273
iter = std::find(node_list_.begin(), node_list_.end(), head_view_);
274
if (iter != node_list_.end())
276
node_list_.erase(iter);
277
node_list_.push_front(head_view_);
282
// // All nodes need to be redrawn.
283
// for (iter = node_list_.begin(); iter != node_list_.end(); iter++)
285
// (*iter)->QueueDraw();
290
if ((event_type == NUX_MOUSE_WHEEL) && (!AcceptMouseWheelEvent()))