summaryrefslogtreecommitdiff
path: root/fluid/nodes/Tree.h
blob: 052553fa208f901c32ee85513a689687db6b3260 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// Node Tree header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2025 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file.  If this
// file is missing or damaged, see the license at:
//
//     https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
//     https://www.fltk.org/bugs.php
//

#ifndef FLUID_NODES_TREE_H
#define FLUID_NODES_TREE_H

#include "nodes/Widget_Node.h"

class Node;

class Project;

class Tree {

  // A class that can iterate over the entire scene graph.
  class Iterator {
    Node *type_ = 0;
    bool only_selected_ = false;
  public:
    explicit Iterator(Node *t, bool only_selected);
    Node* operator*() { return type_; }
    Iterator& operator++();
    bool operator!=(const Iterator& other) const { return type_ != other.type_; }
  };

  // A container for a node iterator
  class Container {
    Tree &tree_;
    bool only_selected_ = false;
  public:
    Container(Tree &tree, bool only_selected) : tree_(tree), only_selected_(only_selected) { }
    Iterator begin() { return Iterator(tree_.first, only_selected_); }
    Iterator end() { return Iterator(0, only_selected_); }
  };

  // A class that iterate over the scene graph, but returns only nodes of type widget.
  class WIterator {
    Node *type_ = 0;
    bool only_selected_ = false;
  public:
    explicit WIterator(Node *t, bool only_selected);
    Widget_Node* operator*() { return static_cast<Widget_Node*>(type_); }
    WIterator& operator++();
    bool operator!=(const WIterator& other) const { return type_ != other.type_; }
  };

  // A container for a widget node iterator
  class WContainer {
    Tree &tree_;
    bool only_selected_ = false;
  public:
    WContainer(Tree &tree, bool only_selected) : tree_(tree), only_selected_(only_selected) { }
    WIterator begin() { return WIterator(tree_.first, only_selected_); }
    WIterator end() { return WIterator(0, only_selected_); }
  };

  /// Link Tree class to the project.
  Project &proj_;

public:

  Node *first = 0;
  Node *last = 0;
  Node *current = 0;  // most recently picked object
  Node *current_dnd = 0;
  /// If this is greater zero, widgets will be allowed to lay out their children.
  int allow_layout = 0;

public:

  Tree(Project &proj);

  bool empty() { return first == 0; }

  // Iterators for traversing nodes and widgets
  Container all_nodes() { return Container(*this, false); }
  WContainer all_widgets() { return WContainer(*this, false); }
  Container all_selected_nodes() { return Container(*this, true); }
  WContainer all_selected_widgets() { return WContainer(*this, true); }

  Node *find_by_uid(unsigned short uid);
  Node *find_in_text(int text_type, int crsr);
};



#endif // FLUID_NODES_TREE_H