static void remove_non_root(node_ptr node, Compare cmp = Compare()) { assert(nullptr != get_parent(node)); node_ptr parent = get_parent(node); bool was_last_child = get_last_child(parent) == node; unlink_with_older_siblings(node); node_ptr older_sibling = get_older_sibling(node); // if node has older siblings they must be now disconnected if(nullptr != older_sibling) unlink_with_older_siblings(older_sibling); node_ptr to_be_linked = pop(node, cmp); if(nullptr != older_sibling) { if(nullptr != to_be_linked) link_older_sibling(to_be_linked, older_sibling); else to_be_linked = older_sibling; } if(nullptr == to_be_linked) return; if(was_last_child) link_last_child(parent, to_be_linked); else link_older_sibling(parent, to_be_linked); }
//--------------------------------------------------------------------------- bool uv_group::mouse_action_childs(int x, int y, int button, int what) { uv_widget *child; set_end_child(); while((child=get_last_child()) != NULL) { if(child->get_x() < x && child->get_y() < y && (child->get_x()+child->get_w()) > x && (child->get_y()+child->get_h()) > y && child->get_visible()) { bool focus = child->mouse_action(x-(child->get_x()), y-(child->get_y()), button, what); if(focus&&child->kann_focus_haben()&&what==SDL_MOUSEBUTTONDOWN) { set_to_end(); } if(child->kann_focus_haben()) break; //Da nur ein Objekt den Klick erhalten kann } if(what==SDL_MOUSEBUTTONUP) //Damit nur bei ursprünglichem Widget up break; }; uv_widget::mouse_action(x,y,button,what); return true; };
//--------------------------------------------------------------------------- void uv_group::set_mouse_over_off() { uv_widget *child; set_end_child(); while((child=get_last_child()) != NULL) { child->set_mouse_over_off(); }; uv_widget::set_mouse_over_off(); }
static node_ptr pop(node_ptr root, Compare cmp = Compare()) { assert(nullptr != root); assert(nullptr == get_older_sibling(root)); node_ptr first_child = get_last_child(root); if(nullptr == first_child) return nullptr; unlink_with_older_siblings(first_child); return merge_pairs(first_child, cmp); }
//--------------------------------------------------------------------------- bool uv_group::mouse_move_rel_childs(int rel_x, int rel_y) { uv_widget *child; set_end_child(); while((child=get_last_child()) != NULL) { child->mouse_move_rel(rel_x, rel_y); }; return true; };
/*!*************************************************************************** \fn sort(node **root) \brief - The sorting function \param **root - tree root \return - void *****************************************************************************/ void sort(node **root) { int i = 10; node *lc = NULL; while(NULL != *root) { /* Get last node which is one of the largest nodes (definitely larger than our current root) and make it the root of the tree. Then normalize tree so the next smallest number can float to the top */ lc = get_last_child(*root); /* Reached the root, last element */ if(lc == *root) { printf("Extracting %d\n Done sorting!!\n", lc->data); free(*root); lc = *root = NULL; } if(lc) { int data = lc->data; /* Extract the current root which is the smallest number currently */ printf("Extracting %d\n", (*root)->data); /* Set root to the larger child, which is brought up from below */ (*root)->data = data; /* Free the child's old node as it is now at the root position. Make sure we set it's parent's link to it to NULL. Don't really need to check if its parent is NULL or not (its not as its not the tree root), but we do it for sanity check. */ if(NULL != lc->parent) { if(NULL != lc->parent->link[LEFT]) if(lc->parent->link[LEFT]->data == lc->data) lc->parent->link[LEFT] = NULL; if(NULL != lc->parent->link[RIGHT]) if(lc->parent->link[RIGHT]->data == lc->data) lc->parent->link[RIGHT] = NULL; } /* Parent link to this is now NULL, free it */ free(lc); lc = NULL; /* The child which is one of the largest nodes in this tree is sitting at the root, normalize tree so that it sinks to the bottom and next smallest node floats to the top */ normalize_tree_root(*root); } } }
static void add_child(node_ptr parent, node_ptr child) { node_ptr first_child = get_last_child(parent); if(nullptr == first_child) { link_last_child(parent, child); return; } unlink_with_older_siblings(first_child); link_last_child(parent, child); link_older_sibling(child, first_child); }
static node_ptr pop_child(node_ptr parent) { node_ptr first_child = get_last_child(parent); assert(nullptr != first_child); node_ptr second_child = get_older_sibling(first_child); unlink_with_older_siblings(first_child); if(nullptr == second_child) return; unlink_with_older_siblings(second_child); link_last_child(parent, second_child); }
static bool check_heap_property(node_ptr r, Compare cmp = Compare()) { bool ok = true; auto checker = [&ok, &cmp](node &n) { node_ptr child = get_last_child(&n); while(nullptr != child) { ok &= !cmp(n, *child); child = get_older_sibling(child); } }; visit(r, checker); return ok; }