Dillo v3.1.1-46-g8a360e32
Loading...
Searching...
No Matches
stackingcontextmgr.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2014 Sebastian Geerken <sgeerken@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21#include "core.hh"
22#include "../lout/debug.hh"
23
24using namespace lout::misc;
25using namespace lout::container::typed;
26
27namespace dw {
28
29namespace core {
30
32{
33 DBG_OBJ_CREATE ("dw::core::StackingContextMgr");
34
35 this->widget = widget;
36
37 childSCWidgets = new Vector<Widget> (1, false);
38 DBG_OBJ_SET_NUM ("childSCWidgets.size", childSCWidgets->size());
39
40 numZIndices = 0;
41 zIndices = NULL;
42 DBG_OBJ_SET_NUM ("numZIndices", numZIndices);
43}
44
52
54{
55 DBG_OBJ_ENTER ("common.scm", 0, "addChildSCWidget", "%p [z-index = %d]",
57
58 int pos = findZIndex (widget->getStyle()->zIndex, true);
59 DBG_OBJ_MSGF ("common.scm", 1, "pos = %d", pos);
60 if (pos == -1) {
61 pos = findZIndex (widget->getStyle()->zIndex, false);
62 DBG_OBJ_MSGF ("common.scm", 1, "pos = %d", pos);
63
65 DBG_OBJ_SET_NUM ("numZIndices", numZIndices);
66 zIndices = (int*)(zIndices ?
67 realloc (zIndices, numZIndices * sizeof (int)) :
68 malloc (numZIndices * sizeof (int)));
69
70 for (int i = numZIndices - 1; i >= pos + 1; i--) {
71 zIndices[i] = zIndices[i - 1];
72 DBG_OBJ_ARRSET_NUM ("zIndex", i, zIndices[i]);
73 }
74
75 zIndices[pos] = widget->getStyle()->zIndex;
76 DBG_OBJ_ARRSET_NUM ("zIndex", pos, zIndices[pos]);
77 }
78
80 DBG_OBJ_SET_NUM ("childSCWidgets.size", childSCWidgets->size());
81 DBG_OBJ_ARRSET_PTR ("childSCWidgets", childSCWidgets->size() - 1, widget);
82
84}
85
86int StackingContextMgr::findZIndex (int zIndex, bool mustExist)
87{
88 int result = -123; // Compiler happiness: GCC 4.7 does not handle this?
89
90 if (numZIndices == 0)
91 result = mustExist ? -1 : 0;
92 else {
93 int low = 0, high = numZIndices - 1;
94 bool found = false;
95
96 while (!found) {
97 int index = (low + high) / 2;
98 if (zIndex == zIndices[index]) {
99 found = true;
100 result = index;
101 } else {
102 if (low >= high) {
103 if (mustExist) {
104 found = true;
105 result = -1;
106 } else {
107 found = true;
108 result = zIndex > zIndices[index] ? index + 1 : index;
109 }
110 }
111
112 if (zIndex < zIndices[index])
113 high = index - 1;
114 else
115 low = index + 1;
116 }
117 }
118 }
119
120 return result;
121}
122
123void StackingContextMgr::draw (View *view, Rectangle *area, int startZIndex,
124 int endZIndex, DrawingContext *context)
125{
126 DBG_OBJ_ENTER ("draw", 0, "draw", "[%d, %d, %d * %d], %d, %d",
127 area->x, area->y, area->width, area->height, startZIndex,
128 endZIndex);
129
130 for (int zIndexIndex = 0; zIndexIndex < numZIndices; zIndexIndex++) {
131 // Wrong region of z-indices (top or bottom) is simply ignored
132 // (as well as non-defined zIndices).
133 if (zIndices != NULL && zIndices[zIndexIndex] >= startZIndex &&
134 zIndices[zIndexIndex] <= endZIndex) {
135 DBG_OBJ_MSGF ("draw", 1, "drawing zIndex = %d", zIndices[zIndexIndex]);
137
138 for (int i = 0; i < childSCWidgets->size (); i++) {
139 Widget *child = childSCWidgets->get (i);
140 DBG_OBJ_MSGF ("draw", 2, "widget %p has zIndex = %d",
141 child, child->getStyle()->zIndex);
142
143 Rectangle childArea;
144 if (child->getStyle()->zIndex == zIndices[zIndexIndex] &&
145 child->intersects (widget, area, &childArea))
146 child->draw (view, &childArea, context);
147 }
148
150 }
151 }
152
153 DBG_OBJ_LEAVE ();
154}
155
158 *context,
159 int startZIndex, int endZIndex)
160{
161 DBG_OBJ_ENTER ("events", 0, "getWidgetAtPoint", "%d, %d", x, y);
162
163 Widget *widgetAtPoint = NULL;
164
165 for (int zIndexIndex = numZIndices - 1;
166 widgetAtPoint == NULL && zIndexIndex >= 0; zIndexIndex--) {
167 // Wrong region of z-indices (top or bottom) is simply ignored
168 // (as well as non-defined zIndices).
169 if (zIndices != NULL && zIndices[zIndexIndex] >= startZIndex &&
170 zIndices[zIndexIndex] <= endZIndex) {
171 DBG_OBJ_MSGF ("events", 1, "searching zIndex = %d",
172 zIndices[zIndexIndex]);
174
175 for (int i = childSCWidgets->size () - 1;
176 widgetAtPoint == NULL && i >= 0; i--) {
177 Widget *child = childSCWidgets->get (i);
178 DBG_OBJ_MSGF ("events", 2, "widget %p has zIndex = %d",
179 child, child->getStyle()->zIndex);
180 if (child->getStyle()->zIndex == zIndices[zIndexIndex])
181 widgetAtPoint = child->getWidgetAtPoint (x, y, context);
182 }
183
185 }
186 }
187
188 DBG_OBJ_MSGF ("events", 0, "=> %p", widgetAtPoint);
189 DBG_OBJ_LEAVE ();
190 return widgetAtPoint;
191}
192
193} // namespace core
194
195} // namespace dw
Set at the top when drawing.
Definition types.hh:295
Set at the top when getting the widget at the point.
Definition types.hh:313
dw::core::Shape implemtation for simple rectangles.
Definition types.hh:70
int findZIndex(int zIndex, bool mustExist)
void draw(View *view, Rectangle *area, int startZIndex, int endZIndex, DrawingContext *context)
Widget * getWidgetAtPoint(int x, int y, core::GettingWidgetAtPointContext *context, int startZIndex, int endZIndex)
void addChildSCWidget(Widget *widget)
lout::container::typed::Vector< Widget > * childSCWidgets
An interface to encapsulate platform dependent drawing.
Definition view.hh:17
The base class of all dillo widgets.
Definition widget.hh:44
bool intersects(Widget *refWidget, Rectangle *area, Rectangle *intersection)
Calculates the intersection of the visible allocation (i.
Definition widget.cc:139
virtual void draw(View *view, Rectangle *area, DrawingContext *context)=0
Area is given in widget coordinates.
style::Style * getStyle()
Definition widget.hh:468
virtual Widget * getWidgetAtPoint(int x, int y, GettingWidgetAtPointContext *context)
Definition widget.cc:211
Typed version of container::untyped::Vector.
Definition container.hh:447
#define DBG_OBJ_DELETE()
#define DBG_OBJ_CREATE(klass)
#define DBG_OBJ_MSG_END()
#define DBG_OBJ_MSGF(aspect, prio, fmt,...)
#define DBG_OBJ_SET_NUM(var, val)
#define DBG_OBJ_ARRSET_NUM(var, ind, val)
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt,...)
#define DBG_OBJ_LEAVE()
#define DBG_OBJ_MSG_START()
#define DBG_OBJ_ARRSET_PTR(var, ind, val)
Dw is in this namespace, or sub namespaces of this one.
This namespace provides thin wrappers, implemented as C++ templates, to gain type-safety.
Definition container.hh:387
Miscellaneous stuff, which does not fit anywhere else.
Definition misc.cc:31