Kattle wrote:
Ok: this is the pseudocode for the operator stacking. I have no idea of how one should create the GUI with a grid on which you can snap the operators you create. Plus, I will do some assumptions you can't rely on (ZGE components), mainly because my understanding of the ZGE codebase is very limited.
Basic idea is: the GUI element himself holds a struct that will be used for creating a tree.
The memory for the node is allocated when the GUI element is created.
Every node in the tree will contain the Producer choosen by the user.
This is the structure (C++ style) on which the GUI part should be based on:
Code: Select all
struct ComponentTree {
TZComponent Producer
ComponentTree * Child //OR: something like "List of Childrens"
ComponentTree * Sibling //should be better instead of Childrens and Siblings
void AddChild(ComponentTree * NewChild) //A function that adds a child to the node
}
struct GUIOperator { //Will contain infos about the operator displayed by the GUI
rect Rectangule //used for representing position & extension
ComponentTree * ContainedComponentTree //Every operator holds a pointer to the TreeStruct
/* stuff like caption or others*/
}
struct GUIOperatorList //just a common list that contains all the operators placed
//in their creation order.
Not sure about this but we should be able to access the producer by something like:
GUIOperator->ContainedComponentTree.Producer
If we can't we are dead because rest of the code is useless
Plus I was wondering if we could use this for displaying and editing everything on the left bar like if the producer itself was selected.
After the user modify something (E.G: moves a rect) we follow this sequence:
Code: Select all
Loop with index i on the GUIOperatorList
with GUIOperatorList[i]
Clean the list of childrens
Loop with index j on the GUIOperatorList //For every component we find his childrens
if GUIOperatorList[j].Rectangule is placed over GUIOperatorList[i].Rectangule //We need very simple criteria
GUIOperatorList[i]->ContainedComponentTree.AddChild(GUIOperatorList[j].ContainedComponentTree)
//we are creating one or more trees that in the end will represent
//the operator stacking Upside-down (see picture)
endif
end Loop
if no child was assigned, assign a default "NewBitmapProducer" as child
//this is what I did using "blank texture" in the example
end Loop
//Now our trees are complete (in the sense that every linked node is represented in the tree)
//We proceed creating the list of producers from the tree
Loop with index i on the GUIOperatorList
with GUIOperatorList[i]
if GUIOperatorList[i]->ContainedComponentTree.Producer == "SaveAs" //looks for operators that will create a bitmap.
Create a bitmap named as the same way the user wanted
TZComponentList TempList
ExploreTreeRecursively (GUIOperatorList[i].ContainedComponentTree->Child, TempList) //See description at bottom
Remove the first element from TempList, since it will be a "NewBitmapProducer" which is not needed
Assign the TempList to the Bitmap. This now cointains all the needed producers.
endif
end Loop
//Idea is: Call the function recursively before adding the producer
//so we get the list of operations in the right order
ExploreTreeRecursively (ComponentTree *Tree, TZComponentList TempList) {
if Tree->Child = NULL {
TempList.Add(Tree->Producer)
return
}
ExploreTreeRecursively (Tree->Child, TempList) //This will be called once for every
//child if the component is "Combine"
TempList.Add(Tree->Producer) //This will be called once for every
//child if the component is "Combine"
}
FINAL CONSIDERATIONS:
Maybe the whole thing could be done without the "support tree" but I did not found a way to manage it in an easy way.
Plus, actual complexity should be O(n^2) which is not that bad.
The "NewBitmapProducer" should be added to the Producers actually ZGE has, but should be quite trivial
When I say "if no child was assigned, assign a default "NewBitmapProducer" as child" there might be a fast way for doing it:
consider using the GUIOperatorList[0] as an always-present invisible GUI element that contains the "NewBitmapProducer" so you can link to it easily.
You just will jump it when it is needed by looping GUIOperatorList from 1 to n.
Some checks should be done: EG: "save" operators SHOULD NOT BE STACKED OVER SOMETHING ELSE or should be ignored within the ExploreTreeRecursively function, otherwise things will get messy.
Feel free to ask for clarifications since I do understand I might have been not so clear