|
| 1 | +/*============================================================================== |
| 2 | +
|
| 3 | + ofxVisualProgramming: A visual programming patching environment for OF |
| 4 | +
|
| 5 | + Copyright (c) 2018 Emanuele Mazza aka n3m3da <[email protected]> |
| 6 | +
|
| 7 | + ofxVisualProgramming is distributed under the MIT License. |
| 8 | + This gives everyone the freedoms to use ofxVisualProgramming in any context: |
| 9 | + commercial or non-commercial, public or private, open or closed source. |
| 10 | +
|
| 11 | + Permission is hereby granted, free of charge, to any person obtaining a |
| 12 | + copy of this software and associated documentation files (the "Software"), |
| 13 | + to deal in the Software without restriction, including without limitation |
| 14 | + the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 15 | + and/or sell copies of the Software, and to permit persons to whom the |
| 16 | + Software is furnished to do so, subject to the following conditions: |
| 17 | +
|
| 18 | + The above copyright notice and this permission notice shall be included |
| 19 | + in all copies or substantial portions of the Software. |
| 20 | +
|
| 21 | + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 22 | + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 26 | + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 27 | + DEALINGS IN THE SOFTWARE. |
| 28 | +
|
| 29 | + See https://github.com/d3cod3/ofxVisualProgramming for documentation |
| 30 | +
|
| 31 | +==============================================================================*/ |
| 32 | + |
| 33 | +#ifndef OFXVP_BUILD_WITH_MINIMAL_OBJECTS |
| 34 | + |
| 35 | +#include "StringAt.h" |
| 36 | + |
| 37 | +//-------------------------------------------------------------- |
| 38 | +StringAt::StringAt() : PatchObject("string at"){ |
| 39 | + |
| 40 | + this->numInlets = 2; |
| 41 | + this->numOutlets = 1; |
| 42 | + |
| 43 | + _inletParams[0] = new string(); // input string |
| 44 | + *static_cast<string *>(_inletParams[0]) = ""; |
| 45 | + _inletParams[1] = new float(); // at |
| 46 | + *(float *)&_inletParams[1] = 0.0f; |
| 47 | + |
| 48 | + _outletParams[0] = new string(); // char |
| 49 | + *static_cast<string *>(_outletParams[0]) = ""; |
| 50 | + |
| 51 | + this->initInletsState(); |
| 52 | + |
| 53 | + stringAt = 0; |
| 54 | + loaded = false; |
| 55 | + |
| 56 | +} |
| 57 | + |
| 58 | +//-------------------------------------------------------------- |
| 59 | +void StringAt::newObject(){ |
| 60 | + PatchObject::setName( this->objectName ); |
| 61 | + |
| 62 | + this->addInlet(VP_LINK_STRING,"string"); |
| 63 | + this->addInlet(VP_LINK_NUMERIC,"at"); |
| 64 | + |
| 65 | + this->addOutlet(VP_LINK_STRING,"char"); |
| 66 | + |
| 67 | + this->setCustomVar(static_cast<float>(stringAt),"AT"); |
| 68 | +} |
| 69 | + |
| 70 | +//-------------------------------------------------------------- |
| 71 | +void StringAt::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){ |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | +//-------------------------------------------------------------- |
| 76 | +void StringAt::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){ |
| 77 | + |
| 78 | + |
| 79 | + if(this->inletsConnected[1]){ |
| 80 | + stringAt = static_cast<int>(floor(*(float *)&_inletParams[1])); |
| 81 | + } |
| 82 | + |
| 83 | + if(this->inletsConnected[0]){ |
| 84 | + if(stringAt >= 0 && stringAt < static_cast<string *>(_inletParams[0])->size()){ |
| 85 | + string s(1,static_cast<string *>(_inletParams[0])->at(stringAt)); |
| 86 | + *static_cast<string *>(_outletParams[0]) = s; |
| 87 | + }else{ |
| 88 | + *static_cast<string *>(_outletParams[0]) = ""; |
| 89 | + } |
| 90 | + }else{ |
| 91 | + *static_cast<string *>(_outletParams[0]) = ""; |
| 92 | + } |
| 93 | + |
| 94 | + if(!loaded){ |
| 95 | + loaded = true; |
| 96 | + stringAt = static_cast<int>(floor(this->getCustomVar("AT"))); |
| 97 | + } |
| 98 | + |
| 99 | +} |
| 100 | + |
| 101 | +//-------------------------------------------------------------- |
| 102 | +void StringAt::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){ |
| 103 | + ofSetColor(255); |
| 104 | + |
| 105 | +} |
| 106 | + |
| 107 | +//-------------------------------------------------------------- |
| 108 | +void StringAt::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){ |
| 109 | + |
| 110 | + // CONFIG GUI inside Menu |
| 111 | + if(_nodeCanvas.BeginNodeMenu()){ |
| 112 | + |
| 113 | + ImGui::Separator(); |
| 114 | + ImGui::Separator(); |
| 115 | + ImGui::Separator(); |
| 116 | + |
| 117 | + if (ImGui::BeginMenu("CONFIG")) |
| 118 | + { |
| 119 | + |
| 120 | + drawObjectNodeConfig(); |
| 121 | + |
| 122 | + ImGui::EndMenu(); |
| 123 | + } |
| 124 | + |
| 125 | + _nodeCanvas.EndNodeMenu(); |
| 126 | + } |
| 127 | + |
| 128 | + // Visualize (Object main view) |
| 129 | + if( _nodeCanvas.BeginNodeContent(ImGuiExNodeView_Visualise) ){ |
| 130 | + |
| 131 | + ImGui::Dummy(ImVec2(-1,ImGui::GetWindowSize().y/2 - (26*scaleFactor))); // Padding top |
| 132 | + ImGui::PushItemWidth(-1); |
| 133 | + if(ImGui::DragInt("", &stringAt)){ |
| 134 | + if(stringAt < 0){ |
| 135 | + stringAt = 0; |
| 136 | + } |
| 137 | + this->setCustomVar(static_cast<float>(stringAt),"AT"); |
| 138 | + } |
| 139 | + ImGui::Spacing(); |
| 140 | + ImGui::Text("string[%i] = %s", stringAt,static_cast<string *>(_outletParams[0])->c_str()); |
| 141 | + ImGui::PopItemWidth(); |
| 142 | + |
| 143 | + _nodeCanvas.EndNodeContent(); |
| 144 | + } |
| 145 | + |
| 146 | +} |
| 147 | + |
| 148 | +//-------------------------------------------------------------- |
| 149 | +void StringAt::drawObjectNodeConfig(){ |
| 150 | + ImGuiEx::ObjectInfo( |
| 151 | + "Extracts the char at a particular position from a string", |
| 152 | + "https://mosaic.d3cod3.org/reference.php?r=vector-at", scaleFactor); |
| 153 | +} |
| 154 | + |
| 155 | +//-------------------------------------------------------------- |
| 156 | +void StringAt::removeObjectContent(bool removeFileFromData){ |
| 157 | + |
| 158 | +} |
| 159 | + |
| 160 | + |
| 161 | +OBJECT_REGISTER( StringAt, "string at", OFXVP_OBJECT_CAT_STRING) |
| 162 | + |
| 163 | +#endif |
0 commit comments