Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMrPhoenix

Posted 19 January 2013 - 11:13 AM

Brother Bob thanks for the help on that but im still having the freezing issue ?
that what im trying to figure out
 
#include "controls.h"

    SDL_Event control_event;


    static void DeleteChar(char text[], unsigned int pos){
        strcpy(text+pos, text+pos+1);
        printf("Remove Char : %s \n", text);
    }
    static void InsertChar(char text[], unsigned int pos, char c) {
        int length = strlen(text);
        char *buff = malloc(length-pos+2);
        sprintf(buff, "%c%s", c, text+pos);
        strcpy(text+pos, buff);
        free(buff);
        printf("Insert Char : %s \n", text);

    }

    static void keydown_event(SDL_keysym* key) {

        switch(app_state) {

            case 1:
                switch(key->sym) {
                    case SDLK_ESCAPE:
                        app_exit = 0;  // exits application
                    break;
                    case SDLK_UP:
                        if(menu_selections > 1) { menu_selections--; }
                    break;
                    case SDLK_DOWN:
                        if(menu_selections < 3) { menu_selections++; }
                    break;
                    case SDLK_RETURN:

                        // actions for menu selection
                        switch(menu_selections) {
                            case 1:
                                // setup new game variables
                                SDL_Delay(500);
                                SDL_EnableUNICODE(SDL_ENABLE); // enables Unicode for text input
                                app_state = 4;
                            break;
                            case 2:
                                SDL_Delay(500);
                                app_state = 2;
                            break;
                            case 3:
                                SDL_Delay(500);
                                app_state = 3;
                            break;
                        }

                    break;
                    default:
                        break;
                }
            break;

            case 2:
                switch(key->sym) {
                    case SDLK_ESCAPE:
                        app_exit = 0; // exits application
                    break;
                    default:
                        break;
                }
            break;

            case 3:
                switch(key->sym) {
                    case SDLK_ESCAPE:
                        app_exit = 0; // exits application
                    break;
                    default:
                        break;
                }
            break;

            case 4:

                if(strlen(name_input) <= 16) {
                    if((control_event.key.keysym.unicode >= (Uint16) 'A') && (control_event.key.keysym.unicode <= (Uint16) 'Z') ) {
                        InsertChar(name_input, strlen(name_input), (char)control_event.key.keysym.unicode);
                        name_display = TTF_RenderText_Solid(menu_font, name_input, blackColor);
                        printf("uppercase render\n");
                    }else if( (control_event.key.keysym.unicode >= (Uint16) 'a') && (control_event.key.keysym.unicode <= (Uint16) 'z') ) {
                        InsertChar(name_input, strlen(name_input), (char)control_event.key.keysym.unicode);
                        name_display = TTF_RenderText_Solid(menu_font, name_input, blackColor);
                        printf("lowercase render\n");
                    }
                }

                switch(key->sym) {


                    case SDLK_BACKSPACE:
                        if(ngs == 1) { if(strlen(name_input) != 0) {
                            DeleteChar(name_input, strlen((const char*)name_input)-1);
                            name_display = TTF_RenderText_Solid(menu_font, name_input, blackColor);
                            printf("Backspace render\n");
                        } }
                    break;

                    case SDLK_ESCAPE:
                        app_exit = 0; // exits application
                    break;

                    case SDLK_LEFT:
                        if(ngs_race > 1) { ngs_race--; }
                    break;

                    case SDLK_RIGHT:
                        if(ngs_race < 3) { ngs_race++; }
                    break;

                    case SDLK_RETURN:
                        switch(ngs) {
                            case 1:

                            //    SDL_EnableUNICODE(SDL_DISABLE);
                            break;
                            case 2:

                            break;
                            case 3:

                            break;
                        }
                    break;

                    default:
                        break;
                }
            break;

        }

    }

    void handle_controls(){
        while(SDL_PollEvent(&control_event)) {
            switch(control_event.type) {
                case SDL_KEYDOWN:
                    keydown_event(&control_event.key.keysym);
                break;
                case SDL_QUIT:
                    app_exit = 0;  // exits application
                break;
            }
        }
    }



and the stdout
Dark Galaxy V0.1 BETA UN-RELEASED
Author - Randall Perkins 1/18/13 

Starting graphics engine
Remove Char : Defaul 
Backspace render
Remove Char : Defau 
Backspace render
Remove Char : Defa 
Backspace render
Remove Char : Def 
Backspace render
Remove Char : De 
Backspace render
Remove Char : D 
Backspace render
Remove Char :  
Backspace render
Insert Char : r 
lowercase render
Insert Char : ra 
lowercase render
Insert Char : ran 
lowercase render
Insert Char : rand 
lowercase render
Insert Char : randa 
lowercase render
Insert Char : randal 
lowercase render
Insert Char : randall 
lowercase render
Insert Char : randallp (THE POINT THE PROGRAM STOPS WHEN THE 'P' IS PRESSED)  <-----------------
lowercase render
Exiting Graphics engine

#2MrPhoenix

Posted 19 January 2013 - 11:12 AM

Brother Bob thanks for the help on that but im still having the freezing issue ?

that what im trying to figure out

 

#include "controls.h"

    SDL_Event control_event;


    static void DeleteChar(char text[], unsigned int pos){
        strcpy(text+pos, text+pos+1);
        printf("Remove Char : %s \n", text);
    }
    static void InsertChar(char text[], unsigned int pos, char c) {
        int length = strlen(text);
        char *buff = malloc(length-pos+2);
        sprintf(buff, "%c%s", c, text+pos);
        strcpy(text+pos, buff);
        free(buff);
        printf("Insert Char : %s \n", text);

    }

    static void keydown_event(SDL_keysym* key) {

        switch(app_state) {

            case 1:
                switch(key->sym) {
                    case SDLK_ESCAPE:
                        app_exit = 0;  // exits application
                    break;
                    case SDLK_UP:
                        if(menu_selections > 1) { menu_selections--; }
                    break;
                    case SDLK_DOWN:
                        if(menu_selections < 3) { menu_selections++; }
                    break;
                    case SDLK_RETURN:

                        // actions for menu selection
                        switch(menu_selections) {
                            case 1:
                                // setup new game variables
                                SDL_Delay(500);
                                SDL_EnableUNICODE(SDL_ENABLE); // enables Unicode for text input
                                app_state = 4;
                            break;
                            case 2:
                                SDL_Delay(500);
                                app_state = 2;
                            break;
                            case 3:
                                SDL_Delay(500);
                                app_state = 3;
                            break;
                        }

                    break;
                    default:
                        break;
                }
            break;

            case 2:
                switch(key->sym) {
                    case SDLK_ESCAPE:
                        app_exit = 0; // exits application
                    break;
                    default:
                        break;
                }
            break;

            case 3:
                switch(key->sym) {
                    case SDLK_ESCAPE:
                        app_exit = 0; // exits application
                    break;
                    default:
                        break;
                }
            break;

            case 4:

                if(strlen(name_input) <= 16) {
                    if((control_event.key.keysym.unicode >= (Uint16) 'A') && (control_event.key.keysym.unicode <= (Uint16) 'Z') ) {
                        InsertChar(name_input, strlen(name_input), (char)control_event.key.keysym.unicode);
                        name_display = TTF_RenderText_Solid(menu_font, name_input, blackColor);
                        printf("uppercase render\n");
                    }else if( (control_event.key.keysym.unicode >= (Uint16) 'a') && (control_event.key.keysym.unicode <= (Uint16) 'z') ) {
                        InsertChar(name_input, strlen(name_input), (char)control_event.key.keysym.unicode);
                        name_display = TTF_RenderText_Solid(menu_font, name_input, blackColor);
                        printf("lowercase render\n");
                    }
                }

                switch(key->sym) {


                    case SDLK_BACKSPACE:
                        if(ngs == 1) { if(strlen(name_input) != 0) {
                            DeleteChar(name_input, strlen((const char*)name_input)-1);
                            name_display = TTF_RenderText_Solid(menu_font, name_input, blackColor);
                            printf("Backspace render\n");
                        } }
                    break;

                    case SDLK_ESCAPE:
                        app_exit = 0; // exits application
                    break;

                    case SDLK_LEFT:
                        if(ngs_race > 1) { ngs_race--; }
                    break;

                    case SDLK_RIGHT:
                        if(ngs_race < 3) { ngs_race++; }
                    break;

                    case SDLK_RETURN:
                        switch(ngs) {
                            case 1:

                            //    SDL_EnableUNICODE(SDL_DISABLE);
                            break;
                            case 2:

                            break;
                            case 3:

                            break;
                        }
                    break;

                    default:
                        break;
                }
            break;

        }

    }

    void handle_controls(){
        while(SDL_PollEvent(&control_event)) {
            switch(control_event.type) {
                case SDL_KEYDOWN:
                    keydown_event(&control_event.key.keysym);
                break;
                case SDL_QUIT:
                    app_exit = 0;  // exits application
                break;
            }
        }
    }



#1MrPhoenix

Posted 19 January 2013 - 11:06 AM

Brother Bob thanks for the help on that but im still having the freezing issue ?

that what im trying to figure out

 

#include "controls.h"

    SDL_Event control_event;


    static void DeleteChar(char text[], unsigned int pos){
        strcpy(text+pos, text+pos+1);
        printf("Remove Char : %s \n", text);
    }
    static void InsertChar(char text[], unsigned int pos, char c) {
        int length = strlen(text);
        char *buff = malloc(length-pos+2);
        sprintf(buff, "%c%s", c, text+pos);
        strcpy(text+pos, buff);
        free(buff);
        printf("Insert Char : %s \n", text);

    }

    static void keydown_event(SDL_keysym* key) {

        switch(app_state) {

            case 1:
                switch(key->sym) {
                    case SDLK_ESCAPE:
                        app_exit = 0;  // exits application
                    break;
                    case SDLK_UP:
                        if(menu_selections > 1) { menu_selections--; }
                    break;
                    case SDLK_DOWN:
                        if(menu_selections < 3) { menu_selections++; }
                    break;
                    case SDLK_RETURN:

                        // actions for menu selection
                        switch(menu_selections) {
                            case 1:
                                // setup new game variables
                                SDL_Delay(500);
                                SDL_EnableUNICODE(SDL_ENABLE); // enables Unicode for text input
                                app_state = 4;
                            break;
                            case 2:
                                SDL_Delay(500);
                                app_state = 2;
                            break;
                            case 3:
                                SDL_Delay(500);
                                app_state = 3;
                            break;
                        }

                    break;
                    default:
                        break;
                }
            break;

            case 2:
                switch(key->sym) {
                    case SDLK_ESCAPE:
                        app_exit = 0; // exits application
                    break;
                    default:
                        break;
                }
            break;

            case 3:
                switch(key->sym) {
                    case SDLK_ESCAPE:
                        app_exit = 0; // exits application
                    break;
                    default:
                        break;
                }
            break;

            case 4:

                if(strlen(name_input) <= 16) {
                    if((control_event.key.keysym.unicode >= (Uint16) 'A') && (control_event.key.keysym.unicode <= (Uint16) 'Z') ) {
                        InsertChar(name_input, strlen(name_input), (char)control_event.key.keysym.unicode);
                        name_display = TTF_RenderText_Solid(menu_font, name_input, blackColor);
                        printf("uppercase render\n");
                    }else if( (control_event.key.keysym.unicode >= (Uint16) 'a') && (control_event.key.keysym.unicode <= (Uint16) 'z') ) {
                        InsertChar(name_input, strlen(name_input), (char)control_event.key.keysym.unicode);
                        name_display = TTF_RenderText_Solid(menu_font, name_input, blackColor);
                        printf("lowercase render\n");
                    }
                }

                switch(key->sym) {


                    case SDLK_BACKSPACE:
                        if(ngs == 1) { if(strlen(name_input) != 0) {
                            DeleteChar(name_input, strlen((const char*)name_input)-1);
                            name_display = TTF_RenderText_Solid(menu_font, name_input, blackColor);
                            printf("Backspace render\n");
                        } }
                    break;

                    case SDLK_ESCAPE:
                        app_exit = 0; // exits application
                    break;

                    case SDLK_LEFT:
                        if(ngs_race > 1) { ngs_race--; }
                    break;

                    case SDLK_RIGHT:
                        if(ngs_race < 3) { ngs_race++; }
                    break;

                    case SDLK_RETURN:
                        switch(ngs) {
                            case 1:

                            //    SDL_EnableUNICODE(SDL_DISABLE);
                            break;
                            case 2:

                            break;
                            case 3:

                            break;
                        }
                    break;

                    default:
                        break;
                }
            break;

        }

    }

    void handle_controls(){
        while(SDL_PollEvent(&control_event)) {
            switch(control_event.type) {
                case SDL_KEYDOWN:
                    keydown_event(&control_event.key.keysym);
                break;
                case SDL_QUIT:
                    app_exit = 0;  // exits application
                break;
            }
        }
    }

PARTNERS