2222#include < cairo/cairo.h>
2323#include < stdlib.h>
2424
25- background* background ::create ()
25+ background_t * background_t ::create ()
2626{
27- auto instance = createCanvasComponent<background >();
27+ auto instance = createCanvasComponent<background_t >();
2828 instance->init ();
2929 return instance;
3030}
3131
32- void background ::init ()
32+ void background_t ::init ()
3333{
34- organizer = new item_organizer (100 , 100 , 5 , 5 );
34+ organizer = new item_organizer_t (100 , 100 , 5 , 5 );
3535
3636 this ->setBufferListener ([this ]()
3737 {
@@ -67,7 +67,7 @@ void background::init()
6767 this ->organize ();
6868}
6969
70- void background ::onMouseMove (const g_point& position)
70+ void background_t ::onMouseMove (const g_point& position)
7171{
7272 for (auto item: items)
7373 {
@@ -80,9 +80,9 @@ void background::onMouseMove(const g_point& position)
8080 }
8181}
8282
83- void background ::onMouseLeftPress (const g_point& position, int clickCount)
83+ void background_t ::onMouseLeftPress (const g_point& position, int clickCount)
8484{
85- item * pressedItem = nullptr ;
85+ item_t * pressedItem = nullptr ;
8686 std::vector<g_rectangle> itemsBounds;
8787 for (auto & item: items)
8888 {
@@ -107,11 +107,16 @@ void background::onMouseLeftPress(const g_point& position, int clickCount)
107107 {
108108 for (auto & item: items)
109109 {
110+ auto wasSelected = item->selected ;
110111 item->selected = false ;
111- item->paint ();
112+ if (wasSelected != item->selected )
113+ item->paint ();
112114 }
115+
116+ auto wasSelected = pressedItem->selected ;
113117 pressedItem->selected = true ;
114- pressedItem->paint ();
118+ if (wasSelected != pressedItem->selected )
119+ pressedItem->paint ();
115120 }
116121
117122 // Store for each selected item the offset in relation to press point
@@ -129,15 +134,17 @@ void background::onMouseLeftPress(const g_point& position, int clickCount)
129134 {
130135 for (auto item: items)
131136 {
137+ auto wasSelected = item->selected ;
132138 item->selected = false ;
133- item->paint ();
139+ if (wasSelected != item->selected )
140+ item->paint ();
134141 }
135142
136143 selectionStart = position;
137144 }
138145}
139146
140- void background ::onMouseDrag (const g_point& position)
147+ void background_t ::onMouseDrag (const g_point& position)
141148{
142149 if (dragItems)
143150 {
@@ -163,32 +170,43 @@ void background::onMouseDrag(const g_point& position)
163170 g_rectangle rect = item->getBounds ();
164171 if (boundsNorm.intersects (rect))
165172 {
173+ auto wasSelected = item->selected ;
166174 item->selected = true ;
167- item->paint ();
175+ if (wasSelected != item->selected )
176+ item->paint ();
168177 }
169178 else
170179 {
180+ auto wasSelected = item->selected ;
171181 item->selected = false ;
172- item->paint ();
182+ if (wasSelected != item->selected )
183+ item->paint ();
173184 }
174185 }
175186 }
176187}
177188
178- void background ::onMouseRelease (const g_point& position)
189+ void background_t ::onMouseRelease (const g_point& position)
179190{
180191 if (dragItems)
181192 dragItems = false ;
182193 selection->setVisible (false );
183194 organize ();
184195}
185196
186- void background ::organize ()
197+ void background_t ::organize ()
187198{
188199 this ->organizer ->organize (items, this ->getBounds ());
189200}
190201
191- void background::paint ()
202+ void background_t::addTaskbar (taskbar_t * taskbar)
203+ {
204+ this ->taskbar = taskbar;
205+ this ->addChild (taskbar);
206+ }
207+
208+
209+ void background_t::paint ()
192210{
193211 auto cr = this ->acquireGraphics ();
194212 if (!cr)
@@ -199,7 +217,7 @@ void background::paint()
199217 auto bounds = this ->getBounds ();
200218
201219 srand (g_millis ());
202- int r = rand () % 128 + 50 ;
220+ static int r = rand () % 128 + 50 ;
203221
204222 cairo_pattern_t * gradient = cairo_pattern_create_linear (bounds.width * 0.4 , 0 , bounds.width * 0.8 ,
205223 bounds.height );
@@ -223,7 +241,7 @@ void background::paint()
223241 this ->releaseGraphics ();
224242}
225243
226- void background ::addItem (item * item)
244+ void background_t ::addItem (item_t * item)
227245{
228246 items.push_back (item);
229247 this ->addChild (item);
0 commit comments