99#include " backend/circuit/circuitManager.h"
1010#include " backend/dataUpdateEventManager.h"
1111
12- #include " util/algorithm.h"
1312#include " environment/environment.h"
14-
13+ # include " util/algorithm.h "
1514
1615void makeNumberInputFunc (Rml::Element* element) {
17- element->AddEventListener (" change" , new EventPasser ([element](Rml::Event& event){
16+ element->AddEventListener (" change" , new EventPasser ([element](Rml::Event& event) {
1817 Rml::String value = element->GetAttribute <Rml::String>(" value" , " " );
1918 std::string correctValue;
2019 for (char c : value) {
@@ -28,7 +27,7 @@ void makeNumberInputFunc(Rml::Element* element) {
2827}
2928
3029void makeNumberInputFunc (Rml::Element* element, std::function<void (unsigned int )> callBack = nullptr) {
31- element->AddEventListener (" change" , new EventPasser ([element, callBack](Rml::Event& event){
30+ element->AddEventListener (" change" , new EventPasser ([element, callBack](Rml::Event& event) {
3231 Rml::String value = element->GetAttribute <Rml::String>(" value" , " " );
3332 std::string correctValue;
3433 for (char c : value) {
@@ -60,7 +59,9 @@ BlockCreationWindow::BlockCreationWindow(
6059 ToolManagerManager* toolManagerManager,
6160 Rml::ElementDocument* document,
6261 Rml::Element* menu
63- ) : document(document), dataUpdateEventReceiver(dataUpdateEventManager), circuitManager(circuitManager), environment(environment), mainWindow(mainWindow), toolManagerManager(toolManagerManager) {
62+ ) :
63+ document(document), dataUpdateEventReceiver(dataUpdateEventManager), circuitManager(circuitManager), environment(environment), mainWindow(mainWindow),
64+ toolManagerManager(toolManagerManager) {
6465 // enuTree(document, parent, true, false)
6566 this ->menu = menu;
6667 outputList = menu->GetElementById (" connection-list-output" );
@@ -77,11 +78,11 @@ BlockCreationWindow::BlockCreationWindow(
7778 Rml::Element* addOutputConnection = menu->GetElementById (" connection-list-add-output" );
7879 addOutputConnection->AddEventListener (" click" , new EventPasser (std::bind (&BlockCreationWindow::addListItem, this , false )));
7980 // texture
80- menu->GetElementById (" pick-texture" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event){
81+ menu->GetElementById (" pick-texture" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event) {
8182 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
8283 if (!circuit || !(circuit->isEditable ())) return ;
8384 // static const SDL_DialogFileFilter filters[] = {}; // error C2466: cannot allocate an array of constant size 0
84- SDL_ShowOpenFileDialog ([](void * userData, const char * const * filePaths, int filter){
85+ SDL_ShowOpenFileDialog ([](void * userData, const char * const * filePaths, int filter) {
8586 if (!filePaths || !filePaths[0 ]) return ;
8687
8788 BlockCreationWindow* blockCreationWindow = (BlockCreationWindow*)userData;
@@ -109,11 +110,11 @@ BlockCreationWindow::BlockCreationWindow(
109110 this ->menu ->GetElementById (" block-texture-menu-no-texture" )->SetClass (" invisible" , true );
110111 this ->menu ->GetElementById (" block-texture-menu-has-texture" )->SetClass (" invisible" , false );
111112 }));
112- menu->GetElementById (" pick-new-texture" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event){
113+ menu->GetElementById (" pick-new-texture" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event) {
113114 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
114115 if (!circuit || !(circuit->isEditable ())) return ;
115116 // static const SDL_DialogFileFilter filters[] = {}; // error C2466: cannot allocate an array of constant size 0
116- SDL_ShowOpenFileDialog ([](void * userData, const char * const * filePaths, int filter){
117+ SDL_ShowOpenFileDialog ([](void * userData, const char * const * filePaths, int filter) {
117118 if (!filePaths || !filePaths[0 ]) return ;
118119
119120 BlockCreationWindow* blockCreationWindow = (BlockCreationWindow*)userData;
@@ -134,12 +135,12 @@ BlockCreationWindow::BlockCreationWindow(
134135 if (filePath.empty ()) return ;
135136 blockData->setTexturePath (filePath);
136137 }));
137- menu->GetElementById (" reload-texture" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event){
138+ menu->GetElementById (" reload-texture" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event) {
138139 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
139140 if (!circuit || !(circuit->isEditable ())) return ;
140141 this ->environment ->getBlockRenderDataFeeder ().refreshBlockTexture (circuit->getBlockType ());
141142 }));
142- menu->GetElementById (" remove-texture" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event){
143+ menu->GetElementById (" remove-texture" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event) {
143144 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
144145 if (!circuit || !(circuit->isEditable ())) return ;
145146 BlockData* blockData = this ->circuitManager ->getBlockDataManager ()->getBlockData (circuit->getBlockType ());
@@ -152,7 +153,7 @@ BlockCreationWindow::BlockCreationWindow(
152153 // if (!circuit || !(circuit->isEditable())) return;
153154 // logError("Embed texture not supported yet.");
154155 // }));
155- menu->GetElementById (" texture-uses-tilemap" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event){
156+ menu->GetElementById (" texture-uses-tilemap" )->AddEventListener (" click" , new EventPasser ([this ](Rml::Event& event) {
156157 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
157158 if (!circuit || !(circuit->isEditable ())) {
158159 this ->menu ->GetElementById (" texture-uses-tilemap" )->SetClass (" checked" , false );
@@ -165,41 +166,41 @@ BlockCreationWindow::BlockCreationWindow(
165166 this ->menu ->GetElementById (" texture-uses-tilemap" )->SetClass (" checked" , blockData->getUsesTileMapTexture ());
166167 }));
167168
168- makeNumberInputFunc (menu->GetElementById (" block-texture-tile-size-x" ), [this ](int x){
169+ makeNumberInputFunc (menu->GetElementById (" block-texture-tile-size-x" ), [this ](int x) {
169170 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
170171 if (!circuit || !(circuit->isEditable ())) return ;
171172 BlockData* blockData = this ->circuitManager ->getBlockDataManager ()->getBlockData (circuit->getBlockType ());
172- blockData->setTextureTileSize ({x, blockData->getTextureTileSize ().y });
173+ blockData->setTextureTileSize ({ x, blockData->getTextureTileSize ().y });
173174 });
174- makeNumberInputFunc (menu->GetElementById (" block-texture-tile-size-y" ), [this ](int y){
175+ makeNumberInputFunc (menu->GetElementById (" block-texture-tile-size-y" ), [this ](int y) {
175176 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
176177 if (!circuit || !(circuit->isEditable ())) return ;
177178 BlockData* blockData = this ->circuitManager ->getBlockDataManager ()->getBlockData (circuit->getBlockType ());
178- blockData->setTextureTileSize ({blockData->getTextureTileSize ().x , y});
179+ blockData->setTextureTileSize ({ blockData->getTextureTileSize ().x , y });
179180 });
180- makeNumberInputFunc (menu->GetElementById (" block-texture-smallest-cord-tile-x" ), [this ](int x){
181+ makeNumberInputFunc (menu->GetElementById (" block-texture-smallest-cord-tile-x" ), [this ](int x) {
181182 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
182183 if (!circuit || !(circuit->isEditable ())) return ;
183184 BlockData* blockData = this ->circuitManager ->getBlockDataManager ()->getBlockData (circuit->getBlockType ());
184- blockData->setTextureSmallestCordTile ({x, blockData->getTextureSmallestCordTile ().y });
185+ blockData->setTextureSmallestCordTile ({ x, blockData->getTextureSmallestCordTile ().y });
185186 });
186- makeNumberInputFunc (menu->GetElementById (" block-texture-smallest-cord-tile-y" ), [this ](int y){
187+ makeNumberInputFunc (menu->GetElementById (" block-texture-smallest-cord-tile-y" ), [this ](int y) {
187188 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
188189 if (!circuit || !(circuit->isEditable ())) return ;
189190 BlockData* blockData = this ->circuitManager ->getBlockDataManager ()->getBlockData (circuit->getBlockType ());
190- blockData->setTextureSmallestCordTile ({blockData->getTextureSmallestCordTile ().x , y});
191+ blockData->setTextureSmallestCordTile ({ blockData->getTextureSmallestCordTile ().x , y });
191192 });
192- makeNumberInputFunc (menu->GetElementById (" block-texture-block-tile-size-x" ), [this ](int x){
193+ makeNumberInputFunc (menu->GetElementById (" block-texture-block-tile-size-x" ), [this ](int x) {
193194 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
194195 if (!circuit || !(circuit->isEditable ())) return ;
195196 BlockData* blockData = this ->circuitManager ->getBlockDataManager ()->getBlockData (circuit->getBlockType ());
196- blockData->setTextureBlockTileSize ({x, blockData->getTextureBlockTileSize ().y });
197+ blockData->setTextureBlockTileSize ({ x, blockData->getTextureBlockTileSize ().y });
197198 });
198- makeNumberInputFunc (menu->GetElementById (" block-texture-block-tile-size-y" ), [this ](int y){
199+ makeNumberInputFunc (menu->GetElementById (" block-texture-block-tile-size-y" ), [this ](int y) {
199200 Circuit* circuit = this ->mainWindow ->getActiveCircuitViewWidget ()->getCircuitView ()->getCircuit ();
200201 if (!circuit || !(circuit->isEditable ())) return ;
201202 BlockData* blockData = this ->circuitManager ->getBlockDataManager ()->getBlockData (circuit->getBlockType ());
202- blockData->setTextureBlockTileSize ({blockData->getTextureBlockTileSize ().x , y});
203+ blockData->setTextureBlockTileSize ({ blockData->getTextureBlockTileSize ().x , y });
203204 });
204205
205206 // dataUpdateEvents
@@ -521,7 +522,9 @@ void BlockCreationWindow::addListItem(bool isInput) {
521522 unsigned int endId = 0 ;
522523 while (true ) {
523524 while (blockData->connectionExists (connection_end_id_t (endId))) ++endId;
524- if (inputList->GetElementById (" ConnectionListItem Id: " + std::to_string (endId)) == nullptr && outputList->GetElementById (" ConnectionListItem Id: " + std::to_string (endId)) == nullptr ) break ;
525+ if (inputList->GetElementById (" ConnectionListItem Id: " + std::to_string (endId)) == nullptr &&
526+ outputList->GetElementById (" ConnectionListItem Id: " + std::to_string (endId)) == nullptr )
527+ break ;
525528 ++endId;
526529 }
527530
@@ -560,21 +563,22 @@ void BlockCreationWindow::addListItem(bool isInput) {
560563 Rml::ElementPtr setPositionButton = document->CreateElement (" button" );
561564 setPositionButton->AppendChild (std::move (document->CreateTextNode (" S" )));
562565 setPositionButton->AddEventListener (Rml::EventId::Click, new EventPasser ([this , endId](Rml::Event& event) {
563- auto tool = std::dynamic_pointer_cast<PortSelector>(
564- mainWindow->getActiveCircuitViewWidget ()->getCircuitView ()->getToolManager ().selectTool (std::make_shared<PortSelector>())
565- );
566- if (tool) {
567- tool->setPort (connection_end_id_t (endId), [this , endId](Position position) {
568- Rml::Element* row = document->GetElementById (" ConnectionListItem Id: " + std::to_string (endId));
569- Rml::ElementList elements;
570- row->GetElementsByClassName (elements, " connection-list-item-pos-x" );
571- rmlui_dynamic_cast<Rml::ElementFormControlInput*>(elements.front ())->SetValue (std::to_string (position.x ));
572- elements.clear ();
573- row->GetElementsByClassName (elements, " connection-list-item-pos-y" );
574- rmlui_dynamic_cast<Rml::ElementFormControlInput*>(elements.front ())->SetValue (std::to_string (position.y ));
575- });
576- }
577- }));
566+ auto tool = std::dynamic_pointer_cast<PortSelector>(
567+ mainWindow->getActiveCircuitViewWidget ()->getCircuitView ()->getToolManager ().selectTool (std::make_shared<PortSelector>())
568+ );
569+ if (tool) {
570+ tool->setPort (connection_end_id_t (endId), [this , endId](Position position) {
571+ Rml::Element* row = document->GetElementById (" ConnectionListItem Id: " + std::to_string (endId));
572+ if (row == nullptr ) return ;
573+ Rml::ElementList elements;
574+ row->GetElementsByClassName (elements, " connection-list-item-pos-x" );
575+ rmlui_dynamic_cast<Rml::ElementFormControlInput*>(elements.front ())->SetValue (std::to_string (position.x ));
576+ elements.clear ();
577+ row->GetElementsByClassName (elements, " connection-list-item-pos-y" );
578+ rmlui_dynamic_cast<Rml::ElementFormControlInput*>(elements.front ())->SetValue (std::to_string (position.y ));
579+ });
580+ }
581+ }));
578582 // add children and set classes
579583 row->AppendChild (std::move (name))->SetClass (" connection-list-item-name" , true );
580584 row->AppendChild (std::move (positionOnBlockX))->SetClass (" connection-list-item-on-block-x" , true );
0 commit comments