Skip to content

Commit

Permalink
some fixings
Browse files Browse the repository at this point in the history
  • Loading branch information
d3cod3 committed Sep 10, 2019
1 parent d960f46 commit a2d36db
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
26 changes: 26 additions & 0 deletions src/objects/graphics/ImageExporter.cpp
Expand Up @@ -111,6 +111,10 @@ void ImageExporter::updateObjectContent(map<int,PatchObject*> &patchObjects, ofx
isImageSaved = false;
saveImageFile();
}

if(this->inletsConnected[1] && *(float *)&_inletParams[1] == 1.0){
saveImageFile();
}

}

Expand All @@ -119,6 +123,28 @@ void ImageExporter::drawObjectContent(ofxFontStash *font){
ofSetColor(255);
ofEnableAlphaBlending();

if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
if(static_cast<ofTexture *>(_inletParams[0])->getWidth()/static_cast<ofTexture *>(_inletParams[0])->getHeight() >= this->width/this->height){
if(static_cast<ofTexture *>(_inletParams[0])->getWidth() > static_cast<ofTexture *>(_inletParams[0])->getHeight()){ // horizontal texture
drawW = this->width;
drawH = (this->width/static_cast<ofTexture *>(_inletParams[0])->getWidth())*static_cast<ofTexture *>(_inletParams[0])->getHeight();
posX = 0;
posY = (this->height-drawH)/2.0f;
}else{ // vertical texture
drawW = (static_cast<ofTexture *>(_inletParams[0])->getWidth()*this->height)/static_cast<ofTexture *>(_inletParams[0])->getHeight();
drawH = this->height;
posX = (this->width-drawW)/2.0f;
posY = 0;
}
}else{ // always considered vertical texture
drawW = (static_cast<ofTexture *>(_inletParams[0])->getWidth()*this->height)/static_cast<ofTexture *>(_inletParams[0])->getHeight();
drawH = this->height;
posX = (this->width-drawW)/2.0f;
posY = 0;
}
static_cast<ofTexture *>(_inletParams[0])->draw(posX,posY,drawW,drawH);
}

gui->draw();
ofDisableAlphaBlending();
}
Expand Down
38 changes: 16 additions & 22 deletions src/objects/web/moHttpForm.cpp
Expand Up @@ -35,19 +35,19 @@
//--------------------------------------------------------------
moHttpForm::moHttpForm() : PatchObject(){

this->numInlets = 1;
this->numInlets = 2;
this->numOutlets = 0;

_inletParams[0] = new float(); // bang
*(float *)&_inletParams[0] = 0.0f;
_inletParams[1] = new string(); // url
*static_cast<string *>(_inletParams[1]) = "";

this->initInletsState();

isGUIObject = true;
this->isOverGUI = true;

this->width *= 2;

fm = new HttpFormManager();
img = new ofImage();

Expand All @@ -62,6 +62,7 @@ moHttpForm::moHttpForm() : PatchObject(){
void moHttpForm::newObject(){
this->setName("http form");
this->addInlet(VP_LINK_NUMERIC,"bang");
this->addInlet(VP_LINK_STRING,"url");
}

//--------------------------------------------------------------
Expand All @@ -83,10 +84,6 @@ void moHttpForm::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
header->setUseCustomMouse(true);
header->setCollapsable(true);

host = gui->addTextInput("URL","localhost");
host->setUseCustomMouse(true);
host->setText(filepath);

gui->addBreak();

addFormField = gui->addButton("ADD FIELD");
Expand Down Expand Up @@ -114,7 +111,6 @@ void moHttpForm::updateObjectContent(map<int,PatchObject*> &patchObjects, ofxThr

gui->update();
header->update();
host->update();
addFormField->update();
addFormImage->update();

Expand All @@ -131,19 +127,24 @@ void moHttpForm::updateObjectContent(map<int,PatchObject*> &patchObjects, ofxThr
}
}

if(this->inletsConnected[1]){
form_url = *static_cast<string *>(_inletParams[1]);
filepath = form_url;
}

if(bang && isBangFinished){
isBangFinished = false;

// Send http form
HttpForm f = HttpForm(form_url);

for(int i=1;i<this->getNumInlets();i++){
for(int i=2;i<this->getNumInlets();i++){
if(this->inletsConnected[i]){
if(this->getInletType(i) == VP_LINK_STRING){
f.addFormField(form_labels.at(i-1),*static_cast<string *>(_inletParams[i]));
f.addFormField(form_labels.at(i-2),*static_cast<string *>(_inletParams[i]));
}else if(this->getInletType(i) == VP_LINK_TEXTURE && static_cast<ofTexture *>(_inletParams[i])->isAllocated()){
saveTempImageFile(i);
f.addFile(form_labels.at(i-1), ofToDataPath("temp/tempimage.png",true), "image/png");
//saveTempImageFile(i);
f.addFile(form_labels.at(i-2).c_str(), ofToDataPath("temp/tempimage.jpg",true), "image/jpg");
}
}
}
Expand All @@ -170,7 +171,6 @@ void moHttpForm::removeObjectContent(){
void moHttpForm::mouseMovedObjectContent(ofVec3f _m){
gui->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));
header->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));
host->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));
addFormField->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));
addFormImage->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));

Expand All @@ -179,7 +179,7 @@ void moHttpForm::mouseMovedObjectContent(ofVec3f _m){
}

if(!header->getIsCollapsed()){
this->isOverGUI = header->hitTest(_m-this->getPos()) || host->hitTest(_m-this->getPos()) ||
this->isOverGUI = header->hitTest(_m-this->getPos()) ||
addFormField->hitTest(_m-this->getPos()) || addFormImage->hitTest(_m-this->getPos());

for(size_t l=0;l<labels.size();l++){
Expand All @@ -195,7 +195,6 @@ void moHttpForm::dragGUIObject(ofVec3f _m){
if(this->isOverGUI){
gui->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));
header->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));
host->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));
addFormField->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));
addFormImage->setCustomMousePos(static_cast<int>(_m.x - this->getPos().x),static_cast<int>(_m.y - this->getPos().y));

Expand Down Expand Up @@ -241,9 +240,9 @@ void moHttpForm::initInlets(){
}
if (XML.pushTag("vars")){
int totalOutlets = XML.getNumTags("var");
this->numInlets = totalOutlets+1;
this->numInlets = totalOutlets+2;

int tempCounter = 1;
int tempCounter = 2;
for (int t=0;t<totalOutlets;t++){
if(XML.pushTag("var",t)){
if(tempTypes.at(tempCounter) == 1){ // string
Expand Down Expand Up @@ -344,11 +343,6 @@ void moHttpForm::onButtonEvent(ofxDatGuiButtonEvent e){
//--------------------------------------------------------------
void moHttpForm::onTextInputEvent(ofxDatGuiTextInputEvent e){
if(!header->getIsCollapsed()){
if(e.target == host){
form_url = e.text;
filepath = form_url;
}

for(int i=0;i<labels.size();i++){
if(e.target == labels.at(i)){
this->substituteCustomVar(form_labels.at(i),e.text);
Expand Down
1 change: 0 additions & 1 deletion src/objects/web/moHttpForm.h
Expand Up @@ -71,7 +71,6 @@ class moHttpForm : public PatchObject {

ofxDatGui* gui;
ofxDatGuiHeader* header;
ofxDatGuiTextInput* host;

vector<ofxDatGuiTextInput*> labels;

Expand Down

0 comments on commit a2d36db

Please sign in to comment.