Ejemplo n.º 1
0
//--------------------------------------------------------------
ofxMtlMapping2DControls::ofxMtlMapping2DControls(int width, const string& file)
{
    // ---- Shapes list
    // set default values
    _selectedShapeId = -1;
    _selectedShapeChanged = false;
    shapeCounter = 0;
    
    _shapesListCanvas = new ofxUIScrollableCanvas(width, 0, width, 720);
    _shapesListCanvas->setScrollArea(width, 0, kControlsMappingShapesListPanelWidth, 720);
    _shapesListCanvas->setScrollableDirections(false, true);
    _shapesListCanvas->setColorBack(ofColor(0, 210, 255, 90));
    _shapesListCanvas->autoSizeToFitWidgets();
    
    ofAddListener(_shapesListCanvas->newGUIEvent, this, &ofxMtlMapping2DControls::shapesListUiEvent);
    
    
    // --- Grid settings
    int gridSettingCanvasWidth = 200.0f;
    _gridSettingsCanvas = new ofxUICanvas();
    _gridSettingsCanvas->setPosition(width, 720 - 90);
    _gridSettingsCanvas->setWidth(gridSettingCanvasWidth);
    _gridSettingsCanvas->setColorFill(ofxUIColor(200));
    _gridSettingsCanvas->setColorFillHighlight(ofxUIColor(255));
    _gridSettingsCanvas->setColorBack(ofColor(0, 210, 255, 90));
    
    ofxUISlider *nSlider;
    _gridSettingsCanvas->addLabel("GRID SETTINGS");
    nSlider = _gridSettingsCanvas->addSlider("NB COLS", 1.0, 20.0, &ofxMtlMapping2DSettings::gridDefaultNbCols);
    nSlider->setIncrement(1.0f);
    nSlider = _gridSettingsCanvas->addSlider("NB ROWS", 1.0, 20.0, &ofxMtlMapping2DSettings::gridDefaultNbRows);
    nSlider->setIncrement(1.0f);
    
    _gridSettingsCanvas->autoSizeToFitWidgets();
    ofAddListener(_gridSettingsCanvas->newGUIEvent, this, &ofxMtlMapping2DControls::gridSettingsListUiEvent);
    _gridSettingsCanvas->disable();
    
    // ---- Tool box
    shapeTypesAsString[MAPPING_2D_SHAPE_QUAD] = "quad";
    shapeTypesAsString[MAPPING_2D_SHAPE_GRID] = "grid";
    shapeTypesAsString[MAPPING_2D_SHAPE_TRIANGLE] = "triangle";
    shapeTypesAsString[MAPPING_2D_SHAPE_MASK] = "mask";
    
    // set default values
    _saveMapping = false;
    _loadMapping = false;
    _editShapes = false;
    _createNewQuad = false;
    _createNewGrid = false;
    _createNewTriangle = false;
    _createNewMask = false;
    _showShapesId = true;
    _mappingModeChanged = true; // initialized to true so that when the app launch the 'shapes' are correctly setted.
    _mappingMode = MAPPING_MODE_OUTPUT;

    
    static const int kWidgetWidth = width - 16;
    
    
    _toolsCanvas = new ofxUIScrollableCanvas(0, 0, width, 720);
    //must have modified ofxUI
    //_toolsCanvas->setStickyDistance(30.0f);
    _toolsCanvas->setScrollableDirections(false, true);
    _toolsCanvas->setColorBack(ofColor(0, 210, 255, 130));
    
    _file = file;
    
    
    // --- Fullscreen
    _fullscreenExpandIcon.loadImage("mapping/GUI/expand.png");
    _fullscreenContractIcon.loadImage("mapping/GUI/contract.png");
    
    //_toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, false, "mapping/GUI/expand.png", kSettingMappingFullscreen));
    
    // Edit
    //_toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, false, "mapping/GUI/edit.png", kSettingMappingEditShapes));
    _toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, false, "mapping/GUI/file-down.png", kSettingMappingSave));
    _toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, false, "mapping/GUI/file-up.png", kSettingMappingLoad));


    // add mapping controls Output / Input
    ofxUISpacer *spacer = new ofxUISpacer(kWidgetWidth, kSpacerHeight);
    spacer->setDrawFill(false);
    
    _toolsCanvas->addWidgetDown(spacer);
    _toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, false, "mapping/GUI/projo.png", kSettingMappingModeOutput));
    _toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, false, "mapping/GUI/texture.png", kSettingMappingModeInput));
    

    // add mapping shape controls
    if (ofxMtlMapping2DSettings::kIsManuallyCreatingShapeEnabled) {
        _toolsCanvas->addWidgetDown(spacer);        
        _toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, _createNewQuad, "mapping/GUI/quad.png", kSettingMappingCreateNewQuad));
        _toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, _createNewGrid, "mapping/GUI/grid.png", kSettingMappingCreateNewGrid));
        _toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, _createNewTriangle, "mapping/GUI/triangle.png", kSettingMappingCreateNewTriangle));
        _toolsCanvas->addWidgetDown(new ofxUIImageToggle(kToggleSize, kToggleSize, _createNewMask, "mapping/GUI/mask.png", kSettingMappingCreateNewMask));
    }
    
    // add mapping shape's details
//    _toolsCanvas->addWidgetDown(spacer);
//    _toolsCanvas->addWidgetDown(new ofxUILabel("SHAPE DATA", OFX_UI_FONT_MEDIUM));
//    _toolsCanvas->addWidgetDown(new ofxUIToggle(kToggleSize, kToggleSize, _editShapes, kSettingMappingShowShapesId));

    
    // ----
    ofAddListener(_toolsCanvas->newGUIEvent, this, &ofxMtlMapping2DControls::toolsUiEvent);
    
    load();
    
    if (getToggleValue(kSettingMappingModeOutput)) {
        _mappingMode = MAPPING_MODE_OUTPUT;
    } else if (getToggleValue(kSettingMappingModeInput)) {
        _mappingMode = MAPPING_MODE_INPUT;
    }
    
    // ---
    //((ofxUIToggle *)_toolsCanvas->getWidget(kSettingMappingEditShapes))->setValue(false);
    setUIShapeEditingState(true);
}
Ejemplo n.º 2
0
//--------------------------------------------------------------
void ControlsMapping::uiEvent(ofxUIEventArgs &event)
{
    string name = event.widget->getName();
        
    // ----
    if (name == kSettingMappingSave) {
        _saveMapping = getToggleValue(name);
    }
    else if (name == kSettingMappingLoad) {
        _loadMapping = getToggleValue(name);
    }
    
    // ---- Editing
    else if (name == kSettingMappingEditShapes) {
        _editShapes = getToggleValue(name);

        ((ofxUILabel *)_canvas->getWidget("MAPPING MODE"))->setVisible(_editShapes);
        ((ofxUIToggle *)_canvas->getWidget(kSettingMappingModeInput))->setVisible(_editShapes);
        ((ofxUIToggle *)_canvas->getWidget(kSettingMappingModeOutput))->setVisible(_editShapes);
        
        ((ofxUILabel *)_canvas->getWidget("SHAPE DATA"))->setVisible(_editShapes);
        ((ofxUIToggle *)_canvas->getWidget(kSettingMappingShowShapesId))->setVisible(_editShapes);
        
        ((ofxUILabel *)_canvas->getWidget("ADD SHAPE"))->setVisible(_editShapes);
        ((ofxUIToggle *)_canvas->getWidget(kSettingMappingCreateNewQuad))->setVisible(_editShapes);
        ((ofxUIToggle *)_canvas->getWidget(kSettingMappingCreateNewTriangle))->setVisible(_editShapes);
    }
    else if (name == kSettingMappingShowShapesId) {
        _showShapesId = getToggleValue(name);
    }
    
    
    // ---- Creating a new shape
    else if (name == kSettingMappingCreateNewQuad) {
        // will happen only if mtl2dMappingSettings::kIsManuallyCreatingShapeEnabled is true
        _createNewQuad = getToggleValue(name);
    }
    else if (name == kSettingMappingCreateNewTriangle) {
        // will happen only if mtl2dMappingSettings::kIsManuallyCreatingShapeEnabled is true
        _createNewTriangle = getToggleValue(name);
    }
    
    
    // ----
    if (getToggleValue(name)) {
        if (name == kSettingMappingModeOutput) {
            _mappingModeChanged = true;
            _mappingMode = MAPPING_MODE_OUTPUT;

            ((ofxUIToggle *)_canvas->getWidget(kSettingMappingModeInput))->setValue(false);
            
            // ----
            if (mtl2dMappingSettings::kIsManuallyCreatingShapeEnabled) {
                ((ofxUILabel *)_canvas->getWidget("ADD SHAPE"))->setVisible(true);
                ((ofxUIToggle *)_canvas->getWidget(kSettingMappingCreateNewQuad))->setVisible(true);
                ((ofxUIToggle *)_canvas->getWidget(kSettingMappingCreateNewTriangle))->setVisible(true);
            }
        }
        else if (name == kSettingMappingModeInput) {
            _mappingModeChanged = true;
            _mappingMode = MAPPING_MODE_INPUT;
            
            ((ofxUIToggle *)_canvas->getWidget(kSettingMappingModeOutput))->setValue(false);
            
            // ----
            if (mtl2dMappingSettings::kIsManuallyCreatingShapeEnabled) {
                ((ofxUILabel *)_canvas->getWidget("ADD SHAPE"))->setVisible(false);
                ((ofxUIToggle *)_canvas->getWidget(kSettingMappingCreateNewQuad))->setVisible(false);
                ((ofxUIToggle *)_canvas->getWidget(kSettingMappingCreateNewTriangle))->setVisible(false);
            }
        }
    }
}
Ejemplo n.º 3
0
//--------------------------------------------------------------
void ofxMtlMapping2DControls::toolsUiEvent(ofxUIEventArgs &event)
{
    string name = event.widget->getName();
    
    if (name == kSettingMappingFullscreen) {        
        ofSetFullscreen(getToggleValue(name));
    }
    
    
    // ----
    else if (name == kSettingMappingSave) {
        _saveMapping = getToggleValue(name);
    }
    else if (name == kSettingMappingLoad) {
        _loadMapping = getToggleValue(name);
    }
    
    // ---- Editing
    else if (name == kSettingMappingEditShapes) {
        setUIShapeEditingState(getToggleValue(name));
        
    }
//    else if (name == kSettingMappingShowShapesId) {
//        _showShapesId = getToggleValue(name);
//    }
    
    // ---- Creating a new shape
    else if (name == kSettingMappingCreateNewQuad) {
        // will happen only if ofxMtlMapping2DSettings::kIsManuallyCreatingShapeEnabled is true
        if(getToggleValue(name)) {
            _createNewQuad = true;
        }
    }
    else if (name == kSettingMappingCreateNewGrid) {
        // will happen only if ofxMtlMapping2DSettings::kIsManuallyCreatingShapeEnabled is true
        if(getToggleValue(name)) {
            _createNewGrid = true;
        }
    }
    else if (name == kSettingMappingCreateNewTriangle) {
        // will happen only if ofxMtlMapping2DSettings::kIsManuallyCreatingShapeEnabled is true
        if(getToggleValue(name)) {
            _createNewTriangle = true;
        }
    }
    else if (name == kSettingMappingCreateNewMask) {
        // will happen only if ofxMtlMapping2DSettings::kIsManuallyCreatingShapeEnabled is true
        if(getToggleValue(name)) {
            _createNewMask = true;
        }
    }
    
    // ----
    if (getToggleValue(name)) {
        unselectShapesToggles();
        ofxMtlMapping2DShape::resetActiveShapeVars();
        ofxMtlMapping2DPolygon::resetActivePolygonVars();
        
        _mappingModeChanged = true;

        if (name == kSettingMappingModeOutput) {
            _mappingMode = MAPPING_MODE_OUTPUT;
            
            ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingModeInput))->setValue(false);
            
            // ---
            if (ofxMtlMapping2DSettings::kIsManuallyCreatingShapeEnabled) {
                ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingCreateNewQuad))->setVisible(true);
                ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingCreateNewGrid))->setVisible(true);
                ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingCreateNewTriangle))->setVisible(true);
                ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingCreateNewMask))->setVisible(true);
            }
            
            // ---
            showGridSettingsCanvas();
        }
        else if (name == kSettingMappingModeInput) {
            _mappingMode = MAPPING_MODE_INPUT;
            
            ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingModeOutput))->setValue(false);
            
            // ---
            if (ofxMtlMapping2DSettings::kIsManuallyCreatingShapeEnabled) {
                ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingCreateNewQuad))->setVisible(false);
                ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingCreateNewGrid))->setVisible(false);
                ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingCreateNewTriangle))->setVisible(false);
                ((ofxUIImageToggle *)_toolsCanvas->getWidget(kSettingMappingCreateNewMask))->setVisible(false);
            }
            
            // ---
            hideGridSettingsCanvas();
        }
        
        refreshShapesListForMappingMode(_mappingMode);

    }
}
Ejemplo n.º 4
0
//--------------------------------------------------------------
ControlsMapping::ControlsMapping(int width, const string& file)
    : ControlsInterface(width, ofColor(0, 0, 255, 130), file)
{
    // set default values
    _saveMapping = false;
    _loadMapping = false;
    _editShapes = false;
    _createNewQuad = false;
    _createNewTriangle = false;
    _showShapesId = false;
    _mappingModeChanged = true; // initialized to true so that when the app launch the 'shapes' are correctly setted.
    _mappingMode = MAPPING_MODE_OUTPUT;
    
    static const int kWidgetWidth = width - 16;
    
    // add save / load controls
    _canvas->addWidgetDown(new ofxUILabel("SAVE MAPPING", OFX_UI_FONT_MEDIUM)); 
    _canvas->addWidgetDown(new ofxUIButton(kToggleSize, kToggleSize, false, kSettingMappingSave));
    _canvas->addWidgetDown(new ofxUIButton(kToggleSize, kToggleSize, false, kSettingMappingLoad));
        
    // add mapping controls
    ofxUISpacer *spacer = new ofxUISpacer(kWidgetWidth, kSpacerHeight);
    spacer->setDrawFill(false);
    _canvas->addWidgetDown(spacer);
    _canvas->addWidgetDown(new ofxUILabel("MAPPING", OFX_UI_FONT_MEDIUM)); 
    _canvas->addWidgetDown(new ofxUIToggle(kToggleSize, kToggleSize, _editShapes, kSettingMappingEditShapes));
    
    // add mapping mode controls
    _canvas->addWidgetDown(spacer);
    _canvas->addWidgetDown(new ofxUILabel("MAPPING MODE", OFX_UI_FONT_MEDIUM)); 
    _canvas->addWidgetDown(new ofxUIToggle(kToggleSize, kToggleSize, false, kSettingMappingModeOutput));
    _canvas->addWidgetDown(new ofxUIToggle(kToggleSize, kToggleSize, false, kSettingMappingModeInput));
    
    // add mapping shape controls
    if (mtl2dMappingSettings::kIsManuallyCreatingShapeEnabled) {
        _canvas->addWidgetDown(spacer);
        _canvas->addWidgetDown(new ofxUILabel("ADD SHAPE", OFX_UI_FONT_MEDIUM)); 
        _canvas->addWidgetDown(new ofxUIToggle(kToggleSize, kToggleSize, _editShapes, kSettingMappingCreateNewQuad));
        _canvas->addWidgetDown(new ofxUIToggle(kToggleSize, kToggleSize, _editShapes, kSettingMappingCreateNewTriangle));
    }
    
    // add mapping shape's details
    _canvas->addWidgetDown(spacer);
    _canvas->addWidgetDown(new ofxUILabel("SHAPE DATA", OFX_UI_FONT_MEDIUM));
    _canvas->addWidgetDown(new ofxUIToggle(kToggleSize, kToggleSize, _editShapes, kSettingMappingShowShapesId));

    
    // ----
    ofAddListener(_canvas->newGUIEvent, this, &ControlsMapping::uiEvent);
    
    load();
    
    if (getToggleValue(kSettingMappingModeOutput)) {
        _mappingMode = MAPPING_MODE_OUTPUT;
    } else if (getToggleValue(kSettingMappingModeInput)) {
        _mappingMode = MAPPING_MODE_INPUT;
    }
    
    // ---- So that nobody touch those
    ((ofxUIToggle *)_canvas->getWidget(kSettingMappingLoad))->setVisible(false);
    
}