Engine/lib/sdl/src/video/x11/SDL_x11messagebox.c
/* Calculate and initialize text and button locations. */
Calculate and initialize text and button locations.
Calculate and initialize text and button locations .
static int
X11_MessageBoxInitPositions( SDL_MessageBoxDataX11 *data )
{
    int i;
    int ybuttons;
    int text_width_max = 0;
    int button_text_height = 0;
    int button_width = MIN_BUTTON_WIDTH;
    const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
    if ( messageboxdata->message && messageboxdata->message[ 0 ] ) {
        const char *text = messageboxdata->message;
        TextLineData *plinedata = data->linedata;
        for ( i = 0; i < MAX_TEXT_LINES; i++, plinedata++ ) {
            int height;
            char *lf = SDL_strchr( ( char * )text, '\n' );
            data->numlines++;
            plinedata->length = ( lf && ( i < MAX_TEXT_LINES - 1 ) ) ? ( lf - text ) : SDL_strlen( text );
            plinedata->text = text;
            GetTextWidthHeight( data, text, plinedata->length, &plinedata->width, &height );
            data->text_height = IntMax( data->text_height, height );
            text_width_max = IntMax( text_width_max, plinedata->width );
            if (lf && (lf > text) && (lf[-1] == '\r')) {
                plinedata->length--;
            }
            text += plinedata->length + 1;
            if ( !lf )
                break;
        }
        data->text_height += 2;
    }
    for ( i = 0; i < data->numbuttons; i++ ) {
        int height;
        data->buttonpos[ i ].buttondata = &data->buttondata[ i ];
        data->buttonpos[ i ].length = SDL_strlen( data->buttondata[ i ].text );
        GetTextWidthHeight( data, data->buttondata[ i ].text, SDL_strlen( data->buttondata[ i ].text ),
                            &data->buttonpos[ i ].text_width, &height );
        button_width = IntMax( button_width, data->buttonpos[ i ].text_width );
        button_text_height = IntMax( button_text_height, height );
    }
    if ( data->numlines ) {
        data->xtext = data->text_height;
        data->ytext = data->text_height + data->text_height;
        ybuttons = 3 * data->ytext / 2 + ( data->numlines - 1 ) * data->text_height;
        data->dialog_width = IntMax( data->dialog_width, 2 * data->xtext + text_width_max );
        data->dialog_height = IntMax( data->dialog_height, ybuttons );
    } else {
        ybuttons = button_text_height;
    }
    if ( data->numbuttons ) {
        int x, y;
        int width_of_buttons;
        int button_spacing = button_text_height;
        int button_height = 2 * button_text_height;
        button_width += button_text_height;
        width_of_buttons = data->numbuttons * button_width + ( data->numbuttons - 1 ) * button_spacing;
        data->dialog_width = IntMax( data->dialog_width, width_of_buttons + 2 * button_spacing );
        data->dialog_height = IntMax( data->dialog_height, ybuttons + 2 * button_height );
        x = ( data->dialog_width - width_of_buttons ) / 2;
        y = ybuttons + ( data->dialog_height - ybuttons - button_height ) / 2;
        for ( i = 0; i < data->numbuttons; i++ ) {
            data->buttonpos[ i ].rect.x = x;
            data->buttonpos[ i ].rect.y = y;
            data->buttonpos[ i ].rect.w = button_width;
            data->buttonpos[ i ].rect.h = button_height;
            data->buttonpos[ i ].x = x + ( button_width - data->buttonpos[ i ].text_width ) / 2;
            data->buttonpos[ i ].y = y + ( button_height - button_text_height - 1 ) / 2 + button_text_height;
            x += button_width + button_spacing;
        }
    }
    return 0;
}
static int X11_MessageBoxInitPositions ( SDL_MessageBoxDataX11 * data ) { int i ; int ybuttons ; int text_width_max = 0 ; int button_text_height = 0 ; int button_width = MIN_BUTTON_WIDTH ; const SDL_MessageBoxData * messageboxdata = data -> messageboxdata ; if ( messageboxdata -> message && messageboxdata -> message [ 0 ] ) { const char * text = messageboxdata -> message ; TextLineData * plinedata = data -> linedata ; for ( i = 0 ; i < MAX_TEXT_LINES ; i ++ , plinedata ++ ) { int height ; char * lf = SDL_strchr ( ( char * ) text , ' \n ' ) ; data -> numlines ++ ; plinedata -> length = ( lf && ( i < MAX_TEXT_LINES - 1 ) ) ? ( lf - text ) : SDL_strlen ( text ) ; plinedata -> text = text ; GetTextWidthHeight ( data , text , plinedata -> length , & plinedata -> width , & height ) ; data -> text_height = IntMax ( data -> text_height , height ) ; text_width_max = IntMax ( text_width_max , plinedata -> width ) ; if ( lf && ( lf > text ) && ( lf [ -1 ] == ' \r ' ) ) { plinedata -> length -- ; } text += plinedata -> length + 1 ; if ( ! lf ) break ; } data -> text_height += 2 ; } for ( i = 0 ; i < data -> numbuttons ; i ++ ) { int height ; data -> buttonpos [ i ] . buttondata = & data -> buttondata [ i ] ; data -> buttonpos [ i ] . length = SDL_strlen ( data -> buttondata [ i ] . text ) ; GetTextWidthHeight ( data , data -> buttondata [ i ] . text , SDL_strlen ( data -> buttondata [ i ] . text ) , & data -> buttonpos [ i ] . text_width , & height ) ; button_width = IntMax ( button_width , data -> buttonpos [ i ] . text_width ) ; button_text_height = IntMax ( button_text_height , height ) ; } if ( data -> numlines ) { data -> xtext = data -> text_height ; data -> ytext = data -> text_height + data -> text_height ; ybuttons = 3 * data -> ytext / 2 + ( data -> numlines - 1 ) * data -> text_height ; data -> dialog_width = IntMax ( data -> dialog_width , 2 * data -> xtext + text_width_max ) ; data -> dialog_height = IntMax ( data -> dialog_height , ybuttons ) ; } else { ybuttons = button_text_height ; } if ( data -> numbuttons ) { int x , y ; int width_of_buttons ; int button_spacing = button_text_height ; int button_height = 2 * button_text_height ; button_width += button_text_height ; width_of_buttons = data -> numbuttons * button_width + ( data -> numbuttons - 1 ) * button_spacing ; data -> dialog_width = IntMax ( data -> dialog_width , width_of_buttons + 2 * button_spacing ) ; data -> dialog_height = IntMax ( data -> dialog_height , ybuttons + 2 * button_height ) ; x = ( data -> dialog_width - width_of_buttons ) / 2 ; y = ybuttons + ( data -> dialog_height - ybuttons - button_height ) / 2 ; for ( i = 0 ; i < data -> numbuttons ; i ++ ) { data -> buttonpos [ i ] . rect . x = x ; data -> buttonpos [ i ] . rect . y = y ; data -> buttonpos [ i ] . rect . w = button_width ; data -> buttonpos [ i ] . rect . h = button_height ; data -> buttonpos [ i ] . x = x + ( button_width - data -> buttonpos [ i ] . text_width ) / 2 ; data -> buttonpos [ i ] . y = y + ( button_height - button_text_height - 1 ) / 2 + button_text_height ; x += button_width + button_spacing ; } } return 0 ; }
Calculate and initialize text and button locations.
Calculate and initialize text and button locations .
/* Go over text and break linefeeds into separate lines. */ /* Only grab length up to lf if it exists and isn't the last line. */ /* Text and widths are the largest we've ever seen. */ /* Break if there are no more linefeeds. */ /* Bump up the text height slightly. */ /* Loop through all buttons and calculate the button widths and height. */ /* x,y for this line of text. */ /* Bump button y down to bottom of text. */ /* Bump the dialog box width and height up if needed. */ /* Button y starts at height of button text. */ /* Bump button width up a bit. */ /* Get width of all buttons lined up. */ /* Bump up dialog width and height if buttons are wider than text. */ /* Location for first button. */ /* Button coordinates. */ /* Button text coordinates. */ /* Scoot over for next button. */