//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
    ofPoint mouse = ofPoint(x, y);
    if (mode == MODE_NORMAL){

        for (int i = 0; i < buttons.size(); i++){
            buttons[i]->checkMousePressed(mouse);
        }
        
        //-------------------------------------
        // 0 = sketch name
        //-------------------------------------
//        if (buttons[0].bMouseOver == true){
//            string text = ofSystemTextBoxDialog("choose sketch name", buttons[0].text);
//            fixStringCharacters(text);
//            setStatus("sketch name set to: " + text);
//            buttons[0].setText(text);
//        }

        //-------------------------------------
        // 1 = sketch path
        //-------------------------------------
        if (buttons[1]->bMouseOver == true){

            string command = "";

            ofDirectory dir(ofFilePath::join(getOFRoot(),defaultLoc));

            if (!dir.exists()){
                dir.create();
            }
          	
        #ifdef TARGET_WIN32
                    ofFileDialogResult res = ofSystemLoadDialog("please select sketch folder", true, windowsFromUnixPath(dir.path()));
        #else 
                    ofFileDialogResult res = ofSystemLoadDialog("please select sketch folder", true, dir.path());
        #endif
            

            if (res.bSuccess){
                string result = res.filePath;
                convertWindowsToUnixPath(result);
                buttons[1]->setText( result );
                
                setStatus("path set to: " + result);
            }
        }

        //-------------------------------------
        // 2 = platform  (disabled)
        //-------------------------------------
        if (buttons[2]->bMouseOver == true){
            // platform is diabled for now
             mode = MODE_PLATFORM;
        }

        //-------------------------------------
        // 3 = addon
        //-------------------------------------
        if (buttons[3]->bMouseOver == true){
            mode = MODE_ADDON;
        }
        
        //-------------------------------------
        // 4 = genearate
        //-------------------------------------
        if (generateButton.bMouseOver == true){
            generateProject();
        }
    }

    if (mode == MODE_ADDON ){
        
        coreAddonsList.checkMousePressed(mouse);
        if(bHaveNonCoreAddons)
            otherAddonsList.checkMousePressed(mouse);
        
        //-------------------------------------
        // if we hit he back button, collect the addons for display
        //-------------------------------------

        if (backButton.bMouseOver){
            string addons = coreAddonsList.getSelectedAsString() + otherAddonsList.getSelectedAsString();
            buttons[3]->setText(addons);
            setStatus("addons set to: " + addons);

            backButton.bMouseOver = false;
            mode = MODE_NORMAL;
        }
    }

    if (mode == MODE_PLATFORM){
        platformsList.checkMousePressed(mouse);
        
        if (backButton.bMouseOver){
            string platforms = platformsList.getSelectedAsString();
            buttons[2]->setText( platforms );
            setStatus("Platform targets set to: " + platforms);
            
            backButton.bMouseOver = false;
            mode = MODE_NORMAL;
        }
    }
}
示例#2
0
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

    if (mode == MODE_NORMAL){


        // check the mouse for press

        for (int i = 0; i < buttons.size(); i++){
            buttons[i].checkMousePressed(ofPoint(x, y));
        }
        

        //-------------------------------------
        // 4 = genearate
        //-------------------------------------

        
        if (generateButton.bMouseOver == true){
            generateProject();
        }

        //-------------------------------------
        // 0 = sketch name
        //-------------------------------------

        if (buttons[0].bMouseOver == true){
            string text = ofSystemTextBoxDialog("choose sketch name", buttons[0].myText);
            fixStringCharacters(text);
            setStatus("sketch name set to: " + text);
            buttons[0].setText(text);
        }

        //-------------------------------------
        // 1 = sketch path
        //-------------------------------------

        if (buttons[1].bMouseOver == true){

            string command = "";

            ofDirectory dir(ofFilePath::join(getOFRoot(),defaultLoc));

            if (!dir.exists()){
                dir.create();
            }

          	
        #ifdef TARGET_WIN32
                    ofFileDialogResult res = ofSystemLoadDialog("please select sketch folder", true, windowsFromUnixPath(dir.path()));
        #else 
                    ofFileDialogResult res = ofSystemLoadDialog("please select sketch folder", true, dir.path());
        #endif
            

            if (res.bSuccess){
                string result = res.filePath;
                convertWindowsToUnixPath(result);
                buttons[1].setText( result );
                
                setStatus("path set to: " + result);
            }


        }


        //-------------------------------------
        // 2 = platform  (disabled)
        //-------------------------------------


        if (buttons[2].bMouseOver == true){
            // platform is diabled for now
             mode = 2;
        }

        //-------------------------------------
        // 3 = addon
        //-------------------------------------

        if (buttons[3].bMouseOver == true){
            mode = MODE_ADDON;

        }
    }

    //-------------------------------------
    // handle addon mode
    //-------------------------------------

    if (mode == MODE_ADDON ){

        //-------------------------------------
        // if we hit he back button, collect the addons for display
        //-------------------------------------

        if (addonButton.bMouseOver){

            string addons = "";

            for (int i = 0; i < panelCoreAddons.getNumControls(); i++){
                if (*((ofxToggle *)panelCoreAddons.getControl(i))){
                   if (addons.length() > 0) addons+=", ";
                    addons += ((ofxToggle *)panelCoreAddons.getControl(i))->getName();

                }

            }
            for (int i = 0; i < panelOtherAddons.getNumControls(); i++){
                if (*((ofxToggle *)panelOtherAddons.getControl(i))){
                    if (addons.length() > 0) addons+=", ";
                    addons += ((ofxToggle *)panelOtherAddons.getControl(i))->getName();

                }

            }
            buttons[3].setText(addons);

            setStatus("addons set to: " + addons);

            addonButton.bMouseOver = false;
            mode = MODE_NORMAL;
        }
    }

    if (mode == MODE_PLATFORM){

    }
}
//--------------------------------------------------------------
void testApp::setup(){
    ofEnableAlphaBlending();
    ofEnableSmoothing();
    ofSetLogLevel(OF_LOG_VERBOSE);
    ofSetVerticalSync(true);
    
    //  Default Settings
    //
    mode                = MODE_NORMAL;
    project             = NULL;
    statusEnergy        = 0;
    float   margin      = 64;
    string  sketchName  = "mySketch";
    
    ofBackground(230,230,230);
    logo.loadImage("images/ofw-logo.png");
    
    //  XML Settings
    //
    ofxXmlSettings XML;
    XML.loadFile("settings/projectGeneratorSettings.xml");
    appToRoot = XML.getValue("appToRoot", "../../../../");
    defaultLoc = XML.getValue("defaultNewProjectLocation", "apps/myApps");
    
    //-------------------------------------
    // calculate the bin path (../../../ on osx) and the sketch path (bin -> root - > defaultLoc)
    //-------------------------------------
    // if appToRoot is wrong, we have alot of issues.  all these paths are used in this project:
    //
#ifdef TARGET_OSX
    string binPath = ofFilePath::getAbsolutePath(ofFilePath::join(ofFilePath::getCurrentWorkingDirectory(), "../../../"));
#else
    string binPath = ofFilePath::getCurrentExeDir();
#endif
    
    string ofRoot = ofFilePath::getAbsolutePath(ofFilePath::join(binPath, appToRoot));
    addonsPath = ofFilePath::getAbsolutePath(ofFilePath::join(ofRoot,"addons"));
    string sketchPath = ofFilePath::getAbsolutePath(ofFilePath::join(ofRoot, defaultLoc));
    
    convertWindowsToUnixPath(ofRoot);
    convertWindowsToUnixPath(addonsPath);
    convertWindowsToUnixPath(sketchPath);
    
    // there's some issues internally in OF with non unix paths for OF root
    //
    setOFRoot(ofRoot);
    
    //------------------------------------- GUI
    //
    
    //  load font and setup the buttons
    //
    font.loadFont("fonts/Inconsolata.otf", 14, true,false,false,0.3,90);
    titleFont.loadFont("fonts/Inconsolata.otf", 28, true,false,false,0.3,90);
    secondFont.loadFont("fonts/Inconsolata.otf", 11, true,false,false,0.3,90);
    
    //  Sketch button
    //
    textButton  *buttonName = new textButton();
    buttonName->font = &font;
    buttonName->secondFont = &secondFont;
    buttonName->prefix = "Name: ";
    buttonName->enableEditing();
	buttonName->topLeftAnchor.set(margin+12, 160+40); //set top button position - others are set relative to this.
    buttonName->setText(sketchName);
    buttonName->secondaryText = "<< CLICK TO CHANGE THE NAME";
    buttons.push_back(buttonName);
    
    //  Path Button
    //
    textButton  *buttonPath = new textButton();
    buttonPath->font = &font;
    buttonPath->secondFont = &secondFont;
    buttonPath->topLeftAnchor.set(buttons[ buttons.size() -1 ]->topLeftAnchor.x, buttons[ buttons.size() -1 ]->topLeftAnchor.y + buttons[ buttons.size() -1 ]->height + 20);
    buttonPath->deliminater = "/";
    buttonPath->prefix = "Path: ";
    buttonPath->setText(sketchPath);
    buttonPath->secondaryText = "<< CLICK TO CHANGE THE DIRECTORY";
    buttons.push_back(buttonPath);
    
    //  Platform Button
    //
    textButton  *buttonPlat = new textButton();
    buttonPlat->font = &font;
    buttonPlat->secondFont = &secondFont;
    buttonPlat->topLeftAnchor.set(buttons[ buttons.size() -1 ]->topLeftAnchor.x, buttons[ buttons.size() -1 ]->topLeftAnchor.y + buttons[ buttons.size() -1 ]->height + 20);
    buttonPlat->deliminater = ", ";
    buttonPlat->prefix = "Platforms: ";
    buttonPlat->secondaryText = "<< CLICK TO CHANGE THE PLATFORM";
    buttonPlat->setText("");
    buttons.push_back(buttonPlat);
    
    //  Addons Button
    //
    textButton  *buttonAddon = new textButton();
    buttonAddon->font = &font;
    buttonAddon->secondFont = &secondFont;
    buttonAddon->topLeftAnchor.set(buttons[ buttons.size() -1 ]->topLeftAnchor.x, buttons[ buttons.size() -1 ]->topLeftAnchor.y + buttons[ buttons.size() -1 ]->height + 20);
    buttonAddon->deliminater = ", ";
    buttonAddon->prefix = "Addons: ";
    buttonAddon->secondaryText = "<< CLICK TO SELECT ADDONS";
    buttonAddon->setText("");
    buttons.push_back(buttonAddon);
    
    for (int i = 0; i < buttons.size(); i++){
        buttons[i]->calculateRect();
    }
    
    //  Generate Button
    //
    generateButton.font = &font;
    generateButton.secondFont = &secondFont;
    generateButton.deliminater = ",";
    generateButton.prefix = "GENERATE PROJECT";
    generateButton.setText("");
    generateButton.bDrawLong = false;
    generateButton.topLeftAnchor.set(ofGetWidth() - buttons[0]->x - generateButton.width + 10 , ofGetHeight() - generateButton.height - 40);
    generateButton.calculateRect();
    
    //  Addon Button
    //
    backButton = generateButton;
    backButton.prefix = "BACK >>";
    backButton.setText("");
    backButton.bDrawLong = false;
    backButton.calculateRect();
    
    //  LOAD ADDONS
    //
    loadAddons();
    
    //  LOAD PLATFORMS
    //
    platformsList.set(64,12,350,500);
    platformsList.font = &font;
    platformsList.title = "Platforms";
    platformsList.addElement("windows (codeblocks)",ofGetTargetPlatform()==OF_TARGET_WINGCC);
	platformsList.addElement("windows (visualStudio)", ofGetTargetPlatform()==OF_TARGET_WINVS);
	platformsList.addElement("linux (codeblocks)",ofGetTargetPlatform()==OF_TARGET_LINUX);
	platformsList.addElement("linux64 (codeblocks)",ofGetTargetPlatform()==OF_TARGET_LINUX64);

    //#define MAKE_IOS
#ifdef MAKE_IOS
	platformsList.addElement("osx (xcode)",false);
	platformsList.addElement("ios (xcode)",true);
#else
    platformsList.addElement("osx (xcode)",ofGetTargetPlatform()==OF_TARGET_OSX);
	platformsList.addElement("ios (xcode)",ofGetTargetPlatform()==OF_TARGET_IPHONE);
#endif
    
    // update the platforms text in the platform button
    //
    buttons[2]->setText( platformsList.getSelectedAsString() );
}
示例#4
0
//--------------------------------------------------------------
void testApp::setup(){
    ofEnableAlphaBlending();
    ofSetLogLevel(OF_LOG_VERBOSE);
    ofSetVerticalSync(true);

    
    statusEnergy = 0;
    
    mode = 0;
    bInited = false;
    project = NULL;
    sketchName = "mySketch";
	

    //-------------------------------------
    // get settings
    //-------------------------------------

    XML.loadFile("settings/projectGeneratorSettings.xml");
    appToRoot = XML.getValue("appToRoot", "../../../../");
    defaultLoc = XML.getValue("defaultNewProjectLocation", "apps/myApps");
       //-------------------------------------
    // calculate the bin path (../../../ on osx) and the sketch path (bin -> root - > defaultLoc)
    //-------------------------------------

    // if appToRoot is wrong, we have alot of issues.  all these paths are used in this project:

#ifdef TARGET_OSX
    string binPath = ofFilePath::getAbsolutePath(ofFilePath::join(ofFilePath::getCurrentWorkingDirectory(), "../../../"));
#else
    string binPath = ofFilePath::getCurrentExeDir();
#endif

    string ofRoot = ofFilePath::getAbsolutePath(ofFilePath::join(binPath, appToRoot));

    addonsPath = ofFilePath::getAbsolutePath(ofFilePath::join(ofRoot,"addons"));
    sketchPath = ofFilePath::getAbsolutePath(ofFilePath::join(ofRoot, defaultLoc));


    convertWindowsToUnixPath(ofRoot);
    convertWindowsToUnixPath(addonsPath);
    convertWindowsToUnixPath(sketchPath);

    // there's some issues internally in OF with non unix paths for OF root
    setOFRoot(ofRoot);



    //-------------------------------------
    // get settings
    //-------------------------------------


    //-------------------------------------
    // load font and setup the buttons
    font.loadFont("fonts/Inconsolata.otf", 14, true,false,false,0.3,90);
    titleFont.loadFont("fonts/Inconsolata.otf", 28, true,false,false,0.3,90);
    secondFont.loadFont("fonts/Inconsolata.otf", 11, true,false,false,0.3,90);
    
    //  Sketch button
    //
    button.font = &font;
    button.secondFont = &secondFont;
    button.prefix = "Name: ";
	button.topLeftAnchor.set(76, 160+40); //set top button position - others are set relative to this.
    button.setText(sketchName);
    
    button.secondaryText = "<< CLICK TO CHANGE THE NAME";
    buttons.push_back(button);

    //  Path button
    //
    button.deliminater = "/";
    button.prefix = "Path: ";
    button.setText(sketchPath);
    button.secondaryText = "<< CLICK TO CHANGE THE DIRECTORY";
	button.topLeftAnchor.set(button.topLeftAnchor.x, button.topLeftAnchor.y + button.rect.height + 20);
    buttons.push_back(button);

    //  Platform text
    //
    button.deliminater = ", ";
    button.prefix = "Platforms: ";
    button.secondaryText = "";
    button.bDrawLong = false;
    button.secondaryText = "";
    button.bSelectable = false;
    button.setText(platform);

    button.topLeftAnchor.set(button.topLeftAnchor.x, button.topLeftAnchor.y + button.rect.height + 20);
    buttons.push_back(button);

    //  Addons button
    //
    button.deliminater = ", ";
    button.bDrawLong = true;
    button.prefix = "Addons: ";
    button.secondaryText = "<< CLICK TO SELECT ADDONS";
    button.bSelectable = true;
    button.setText(addons);

    button.topLeftAnchor.set(button.topLeftAnchor.x, button.topLeftAnchor.y + button.rect.height + 20);
    buttons.push_back(button);

    //  Generate
    //
    generateButton = button;
    generateButton.topLeftAnchor.set(906, 535);
	//generateButton.setColor(ofColor(50, 150, 255));
    generateButton.deliminater = ",";
    generateButton.prefix = "GENERATE PROJECT";
    generateButton.bSelectable = true;
    generateButton.setText("");
    generateButton.bDrawLong = false;
    
    addonButton = button;
    addonButton.topLeftAnchor.set(906, 535);
    addonButton.prefix = "<< BACK";
    addonButton.setText("");
    addonButton.bDrawLong = false;
    

    for (int i = 0; i < buttons.size(); i++){
        buttons[i].calculateRect();
    }
    addonButton.calculateRect();
    generateButton.calculateRect();

    //-------------------------------------
    // addons panels:
    //-------------------------------------

    panelCoreAddons.setup();
    panelOtherAddons.setup();

    ofDirectory addons(addonsPath);

    addons.listDir();
    for(int i=0;i<(int)addons.size();i++){
    	string addon = addons.getName(i);

    	if(addon.find("ofx")==0){

            if (isAddonCore(addon)){
                ofxToggle * toggle = new ofxToggle();
                panelCoreAddons.add(toggle->setup(addon,false,300));
            } else {
                bHaveNonCoreAddons = true;
                ofxToggle * toggle = new ofxToggle();
                panelOtherAddons.add(toggle->setup(addon,false,300));
            }


    	}
    }

    //-------------------------------------
    // platform panel (not used, really, but here just in case)
    //-------------------------------------
    panelPlatforms.setup();
    panelPlatforms.add(wincbToggle.setup("windows (codeblocks)",ofGetTargetPlatform()==OF_TARGET_WINGCC));
	panelPlatforms.add(winvsToggle.setup("windows (visual studio)", ofGetTargetPlatform()==OF_TARGET_WINVS));
	panelPlatforms.add(linuxcbToggle.setup("linux (codeblocks)",ofGetTargetPlatform()==OF_TARGET_LINUX));
	panelPlatforms.add(linux64cbToggle.setup("linux64 (codeblocks)",ofGetTargetPlatform()==OF_TARGET_LINUX64));

//for ios, we need to fake that the target is ios (since we're compiling w/ osx OF)

//#define MAKE_IOS
    
#ifdef MAKE_IOS
	panelPlatforms.add(osxToggle.setup("osx (xcode)",false));
	panelPlatforms.add(iosToggle.setup("ios (xcode)",true));
#else
    panelPlatforms.add(osxToggle.setup("osx (xcode)",ofGetTargetPlatform()==OF_TARGET_OSX));
	panelPlatforms.add(iosToggle.setup("ios (xcode)",ofGetTargetPlatform()==OF_TARGET_IPHONE));
#endif
    
    
    // update the platforms text in the platform button
    string platforms = "";
    for (int i = 0; i < panelPlatforms.getNumControls(); i++){
        if (*((ofxToggle *)panelPlatforms.getControl(i))){
            if (platforms.length() > 0) platforms+=", ";
            platforms += ((ofxToggle *)panelPlatforms.getControl(i))->getName();

        };
    }
    buttons[2].setText(platforms);


    panelPlatforms.setPosition(10,40);
    panelCoreAddons.setPosition(10,40);
    panelOtherAddons.setPosition(330,40);
   

    logo.loadImage("images/ofw-logo.png");

    ofBackground(230,230,230);
    
    
    generateButton.topLeftAnchor.set(ofGetWidth() - buttons[0].rect.x - generateButton.rect.width + 10 ,
                                     ofGetHeight() - generateButton.rect.height - 40);// 535);
    generateButton.calculateRect();
    
    addonButton.topLeftAnchor.set(ofGetWidth() - buttons[0].rect.x - addonButton.rect.width + 10 ,
                                  ofGetHeight() - addonButton.rect.height - 40);// 535);
    addonButton.calculateRect();

}