Ejemplo n.º 1
0
void g2Dialog::Show()
{
    // Window implementation block
    #ifdef _WIN32
    
        if(Type == g2DialogType_Notification)
        {
            MessageBox(NULL, MessageBuffer, "GLUI2 - Message", MB_ICONINFORMATION);
        }
        else if(Type == g2DialogType_Open)
        {
            // Based on the MSDN article on open/saving dialogs
            // http://msdn.microsoft.com/en-us/library/windows/desktop/ms646829(v=vs.85).aspx
            
			// Allocate the args list for opening file
            OPENFILENAME ofn;
            ZeroMemory(&ofn, sizeof(ofn));
			char szFileName[MAX_PATH] = "";
            
			// Set default flags
            ofn.lStructSize = sizeof(ofn);
            ofn.hwndOwner = NULL;
            ofn.lpstrFile = szFileName;
            ofn.nMaxFile = MAX_PATH;
            ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
            
			// Set a file filter
            char szFileFilter[MAX_PATH];
			if(strlen(FileExtension) > 0)
				sprintf(szFileFilter, "(*.%s)\0*.%s\0", FileExtension, FileExtension);
			else
				strcpy(szFileFilter, "All Files (*.*)\0*.*\0");
            ofn.lpstrFilter = szFileFilter;
			ofn.lpstrDefExt = FileExtension;
			
            // Open file
            if(GetOpenFileName(&ofn))
            {
                strcpy(ResultBuffer, ofn.lpstrFile);
                Selection = g2DialogResult_OK;
            }
            else
            {
                strcpy(ResultBuffer, "");
                Selection = g2DialogResult_Cancel;
            }
        }
        else if(Type == g2DialogType_Save)
        {
            // Based on:
            // http://msdn.microsoft.com/en-us/library/windows/desktop/dd183519(v=VS.85).aspx
            
			// Allocate the args list for opening file
            OPENFILENAME ofn;
            ZeroMemory(&ofn, sizeof(ofn));
			char szFileName[MAX_PATH] = "";
            
			// Set default flags
            ofn.lStructSize = sizeof(ofn);
            ofn.hwndOwner = NULL;
            ofn.lpstrFile = szFileName;
            ofn.nMaxFile = MAX_PATH;
            ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
            
			// Set a file filter
            char szFileFilter[MAX_PATH];
			if(strlen(FileExtension) > 0)
				sprintf(szFileFilter, "(*.%s)\0*.%s\0", FileExtension, FileExtension);
			else
				strcpy(szFileFilter, "All Files (*.*)\0*.*\0");
            ofn.lpstrFilter = szFileFilter;
			ofn.lpstrDefExt = FileExtension;
			
            // Save file
            if(GetSaveFileName(&ofn))
            {
                strcpy(ResultBuffer, ofn.lpstrFile);
                Selection = g2DialogResult_OK;
            }
            else
            {
                strcpy(ResultBuffer, "");
                Selection = g2DialogResult_Cancel;
            }
        }
    
    
    // Linux implementation block
    #elif __linux__
    
        // Ask by the command line
        // Note that linux users shouldn't run the program
        // that instances this application in the background
        // as we need access to standard I/O
        strcpy(ResultBuffer, "");
        
        if(Type == g2DialogType_Notification)
        {
            printf("Message: \"%s\"\n", MessageBuffer);
            Selection = g2DialogResult_OK;
            strcpy(ResultBuffer, "");
            return;
        }
        else if(Type == g2DialogType_Open)
            printf("\"%s\"> ", MessageBuffer);
        else if(Type == g2DialogType_Save)
            printf("\"%s\"> ", MessageBuffer);
        
        char* TempBuffer = NULL;
        if(scanf("%s", TempBuffer) > 0)
        {
            Selection = g2DialogResult_OK;
            
            // Special rule: if we are saving, make sure to
            // add the extension if it exists
            if(Type == g2DialogType_Save && strlen(FileExtension) > 0)
            {
                // If this file does not end in the extension...
                char* ExtLocation = strrchr(TempBuffer, '.');
                if(strcmp(ExtLocation + 1, FileExtension) != 0)
                    sprintf(ResultBuffer, "%s.%s", TempBuffer, FileExtension);
                // Else, it does, just copy it over
                else
                    strcpy(ResultBuffer, TempBuffer);
            }
            // Else, just do a regular copy
            else
                strcpy(ResultBuffer, TempBuffer);
        }
        else
        {
            Selection = g2DialogResult_Cancel;
            strcpy(ResultBuffer, "");
        }
        
    // Apple/OSX includes
    #elif __APPLE__
        
        // Attempt to execute the appropriate notification
        bool result = false;
        if(Type == g2DialogType_Notification)
            result = __g2ShowDialog(MessageBuffer);
        else if(Type == g2DialogType_Open)
            result = __g2ShowOpenDialog(MessageBuffer, FileExtension, ResultBuffer, g2Dialog_MaxBufferLength);
        else if(Type == g2DialogType_Save)
            result = __g2ShowSaveDialog(MessageBuffer, FileExtension, ResultBuffer, g2Dialog_MaxBufferLength);
        
        // Based on the result (i.e. button index) save
        // the correct enumeration type
        if(result == true)
            Selection = g2DialogResult_OK;
        else
            Selection = g2DialogResult_Cancel;
        
    #endif
}
Ejemplo n.º 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 (buttons[4].bMouseOver == true){
            generateProject();
        }

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

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

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

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

             printf("here2? \n");

            string command;


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

            //cout << dir.getAbsolutePath() << endl;

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

#ifdef TARGET_OSX

            printf("here? \n");

            char * MessageBuffer = "please select sketch folder";
            char * FileExtension = "";
            char ResultBuffer[1024];
            memset(ResultBuffer, 0,1024);

            string defaultStr = ofFilePath::join(getOFRoot(),defaultLoc);
            cout << defaultStr << endl;
            if (__g2ShowOpenDialog((char *)defaultStr.c_str(), MessageBuffer, FileExtension, ResultBuffer, 1024)){

                string res = string(ResultBuffer);
                buttons[1].setText(res);
                status = "sketch path set to: " + res;

            }
#else

            ofFileDialogResult results = ofSystemLoadDialog("please select sketch folder",true,buttons[1].myText);
            if(results.bSuccess){
				buttons[1].setText(results.filePath);
				status = "sketch path set to: " + results.filePath;
            }

#endif


        }


        //-------------------------------------
        // 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);

            status = "addons set to: " + addons;

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

    if (mode == MODE_PLATFORM){

    }
}