#include <dutree.h>
Inheritance diagram for TreeView:


Public Methods | |
| TreeView (gint x_size=0, gint y_size=0) | |
| Constructor. | |
| EnTree const & | get_EnTree () const |
| Gets the EnTree that the mouse is currently over, or the top EnTree. | |
| void | set_EnTree (EnTree const &newcur) |
| Set the current EnTree for display. | |
| EnTree const & | get_top_EnTree () const |
| Return the EnTree at the top. | |
| void | modified (DirTree const &moddir) |
| Updates the display when the file sizes change significantly. | |
| void | EnTree_rect (EnTree const *curent, bool vertical, gint x, gint y, gint width, gint height) |
| Calculates the position and dimensions of the rectangles, based on the EnTree. | |
| void | draw_rect () |
| Draws the rectangles to the screen from the rectangles vector. | |
| bool | isReady () |
| Determines whether the TreeView is ready for use. | |
| void | test_tree () |
| void | setDrawer (Drawer *d) |
| void | set_cpick (ColorPicker *cp) |
| Drawer * | getDrawer () |
| gint | expose_event_impl (GdkEventExpose *) |
| Displays the space use graph. | |
| gint | delayed_calc () |
| bool | clicked (EntryRect const *, int button) |
| Called when a rectangle is clicked. | |
| virtual bool | region_hover (EntryRect ®ion) |
Public Attributes | |
| RecTransform | rt |
|
||||||||||||
|
Constructor.
00087 : 00088 drawing(false), rt(150,150,0.5,0.5) 00089 { 00090 Context cx1("TreeView::TreeView(gint, gint)"); 00091 size(x_size, y_size); 00092 //treeGen.max_depth=3; 00093 set_events(GDK_ENTER_NOTIFY_MASK| GDK_LEAVE_NOTIFY_MASK|GDK_EXPOSURE_MASK | 00094 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | 00095 GDK_BUTTON_PRESS_MASK); 00096 treeGen.opt_separate_dirs=false; 00097 treeGen.set_watcher(*this); 00098 srandom(1); 00099 my_tree.reset(new EnTree); 00100 cur_tree=NULL; 00101 over_rect=NULL; 00102 firsttime=true; 00103 oldsize=0; 00104 //dwr.reset(new DarkFirst(get_window())); 00105 } |
|
|
Gets the EnTree that the mouse is currently over, or the top EnTree.
|
|
|
Set the current EnTree for display.
00140 {
00141 if (&newcur==cur_tree) return;
00142
00143 cur_tree=&newcur;
00144 rectangles.clear();
00145 EnTree_rect(cur_tree, false, 0,0,width(),height());
00146 draw_rect();
00147 seek_over();
00148 me_modified();
00149 }
|
|
|
Return the EnTree at the top.
|
|
|
Updates the display when the file sizes change significantly.
Implements Watcher< DirTree >.
00156 {
00157 if (cur_tree==NULL || my_tree.get()==NULL) return;
00158 if (oldsize==0)
00159 {
00160 oldsize=my_tree->size;
00161 return;
00162 }
00163 if (my_tree->size*100/oldsize>115)
00164 {
00165 rectangles.clear();
00166 EnTree_rect(cur_tree, false, 0, 0, 300, 300);
00167 draw_rect();
00168 oldsize=my_tree->size;
00169 }
00170 }
|
|
||||||||||||||||||||||||||||
|
Calculates the position and dimensions of the rectangles, based on the EnTree.
00260 {
00261 if(curent==NULL) return;
00262 if (firsttime)
00263 {
00264
00265 cout << curent->name << endl;
00266 cout << "x: " << x << " y: "<< y << " width: " << width << " height: " <<\
00267 height << endl;
00268 }
00269
00270 /* calculate the total size of children */
00271 uintmax_t childsize=0;
00272 for (EnTree *curchild=curent->child; curchild!=NULL;
00273 curchild=curchild->next)
00274 {
00275 childsize+=curchild->size;
00276 }
00277
00278 /* calculate the size of the entry without children */
00279 uintmax_t selfsize=curent->size-childsize;
00280
00281 /* prepare the adjustable dimension and coordinate */
00282 gint &dimension=(vertical)?width:height;
00283 gint &coordinate=(vertical)?x:y;
00284 gint olddimension=dimension;
00285 dimension=(selfsize==0)?0:dimension*selfsize/curent->size;
00286 EntryRect cur(x, y, width+1, height, *curent, *this);
00287 rectangles.push_back(cur);
00288 /* draw the rectangle */
00289
00290
00291 if (firsttime)
00292 {
00293 cout << "x: " << x << " y: "<< y << " width: " << width << " height: " <<\
00294 height << endl << endl;
00295 }
00296
00297 /* ajust the coordiate and dimension for drawing children */
00298 coordinate+=dimension;
00299 dimension=olddimension-dimension;
00300
00301 /* prepare the adjustable (opposite) dimension and coordinate for the child */
00302 gint &child_dimension=(vertical)?height:width;
00303 olddimension=child_dimension;
00304 gint &child_coordinate=(vertical)?y:x;
00305
00306 float fcoord=child_coordinate;
00307
00308 gint oldx, oldy, oldwidth=-1, oldheight=-1;
00309 for (EnTree *curchild=curent->child; curchild!=NULL;
00310 curchild=curchild->next)
00311 {
00312 float fdim;
00313 fdim=(curchild->size==0)?0:1.0f*child_dimension*curchild->size/childsize;
00314 child_dimension=static_cast<int>(fdim);
00315 if (x!=oldx || y!=oldy || width!=oldwidth || height!=oldheight)
00316 EnTree_rect(curchild, vertical, x, y, width, height);
00317 oldx=x;
00318 oldy=y;
00319 oldwidth=width;
00320 oldheight=height;
00321 fcoord+=fdim;
00322 child_coordinate=static_cast<int>(fcoord);
00323 if (firsttime)
00324 {
00325 cout << fcoord << "," << fdim<<endl;
00326 }
00327 child_dimension=olddimension;
00328 }
00329 }
|
|
|
Draws the rectangles to the screen from the rectangles vector.
00335 {
00336
00337 if (drawing)
00338 {
00339 ContException err("Drawing on top!");
00340 throw err;
00341 }
00342 drawing=true;
00343 over_rect=NULL;
00344
00345 for (size_t i=0; i<rectangles.size(); ++i)
00346 {
00347 (*dwr)(rectangles[i], (*cpick)(rectangles[i]));
00348 }
00349 drawing=false;
00350 }
|
|
|
Determines whether the TreeView is ready for use.
00356 {
00357 return (cur_tree!=NULL);
00358 }
|
|
|
00361 {
00362 EnTree *child;
00363 my_tree.reset(new EnTree());
00364 my_tree->set(100, "Top");
00365 child=new EnTree();
00366 child->set(25, "Yark");
00367 my_tree->add_child(child);
00368 child=new EnTree();
00369 child->set(12, "Park");
00370 my_tree->add_child(child);
00371 EnTree *childchild=new EnTree();
00372 childchild->set(6, "Park");
00373 child->add_child(childchild);
00374 child=new EnTree();
00375 child->set(13, "Sark");
00376 my_tree->add_child(child);
00377 }
|
|
|
00218 {
00219 dwr.reset(d);
00220 }
|
|
|
00223 {
00224 cpick.reset(cp);
00225 }
|
|
|
00228 {
00229 return dwr.get();
00230 }
|
|
|
Displays the space use graph.
00179 {
00180 Context cx1("TreeView::expose_event_impl()");
00181 try
00182 {
00183 static int oldwidth=-1, oldheight=-1;
00184 if (cpick.get()==NULL)
00185 cpick.reset(new AgeColor);
00186
00187 if (dwr.get()==NULL)
00188 dwr.reset(new PrettyDrawer(get_window()));
00189 if (firsttime || oldheight!=event->area.height ||
00190 oldwidth!=event->area.width)
00191 {
00192 {
00193 Context cx2("Calculating directories");
00194 firsttime=false;
00195
00196 cur_tree=my_tree.get();
00197 treeGen.calc_EnTree(".", my_tree.get());
00198 }
00199 {
00200 Context cx3("Drawing rectangles");
00201 if (cur_tree==NULL) return true;
00202 rectangles.clear();
00203 EnTree_rect(cur_tree, false, 0,0,width(),height());
00204 me_modified();
00205 oldwidth=width();
00206 oldheight=height();
00207 }
00208 }
00209 draw_rect();
00210 }
00211 catch (ContException &cex)
00212 {
00213 cex.print();
00214 }
00215 return true;
00216 }
|
|
|
00219 {
00220 cur_tree=my_tree.get();
00221 treeGen.calc_EnTree(".", my_tree.get());
00222 return false;
00223 }
|
|
||||||||||||
|
Called when a rectangle is clicked.
Implements ImageMap.
00231 {
00232 if (cur_tree==NULL) return true;
00233 if (rect==NULL) return false;
00234 //left click
00235 if (button == 1 && rect!=NULL)
00236 set_EnTree(rect->get_EnTree());
00237
00238 //right click
00239 if (button == 3)
00240 {
00241 if (cur_tree->parent!=NULL) set_EnTree(*cur_tree->parent);
00242 }
00243 return true;
00244 }
|
|
|
Reimplemented from RegionWatcher< EntryRect >.
00238 {
00239 me_modified();
00240 //set_EnTree(region.get_EnTree());
00241 return true;
00242 }
|
|
|
|
1.2.18