2006-03-20 17:12:09 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2012-07-01 02:54:33 +00:00
|
|
|
#include "maths.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "pstypes.h"
|
|
|
|
#include "gr.h"
|
2011-01-14 09:51:13 +00:00
|
|
|
#include "event.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "ui.h"
|
2012-01-03 09:24:31 +00:00
|
|
|
#include "mouse.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "key.h"
|
2012-01-03 09:24:31 +00:00
|
|
|
#include "u_mem.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-04 03:07:40 +00:00
|
|
|
#include "dxxsconf.h"
|
2013-12-21 05:12:38 +00:00
|
|
|
#include "compiler-array.h"
|
2013-12-04 03:07:40 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
// ts = total span
|
|
|
|
// w = width of each item
|
|
|
|
// n = number of items
|
|
|
|
// i = item number (0 based)
|
|
|
|
#define EVEN_DIVIDE(ts,w,n,i) ((((ts)-((w)*(n)))*((i)+1))/((n)+1))+((w)*(i))
|
|
|
|
|
|
|
|
#define BUTTON_HORZ_SPACING 20
|
|
|
|
#define TEXT_EXTRA_HEIGHT 5
|
|
|
|
|
2013-12-22 22:03:07 +00:00
|
|
|
struct messagebox
|
2012-01-03 09:24:31 +00:00
|
|
|
{
|
2013-12-04 23:31:29 +00:00
|
|
|
const ui_messagebox_tie *button;
|
2012-01-03 09:24:31 +00:00
|
|
|
UI_GADGET_BUTTON *button_g[10];
|
2013-06-08 22:24:17 +00:00
|
|
|
const char *text;
|
2012-01-03 09:24:31 +00:00
|
|
|
int *choice;
|
2012-04-11 02:52:57 +00:00
|
|
|
int width;
|
|
|
|
int text_y;
|
|
|
|
int line_y;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2012-01-03 09:24:31 +00:00
|
|
|
|
|
|
|
static int messagebox_handler(UI_DIALOG *dlg, d_event *event, messagebox *m)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-04-11 02:52:57 +00:00
|
|
|
if (event->type == EVENT_UI_DIALOG_DRAW)
|
|
|
|
{
|
2014-07-20 03:48:27 +00:00
|
|
|
const grs_font * temp_font;
|
2012-04-11 02:52:57 +00:00
|
|
|
|
|
|
|
gr_set_current_canvas( &grd_curscreen->sc_canvas );
|
|
|
|
temp_font = grd_curscreen->sc_canvas.cv_font;
|
|
|
|
|
|
|
|
if ( grd_curscreen->sc_w < 640 ) {
|
2014-07-20 03:48:27 +00:00
|
|
|
grd_curscreen->sc_canvas.cv_font = ui_small_font.get();
|
2012-04-11 02:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui_dialog_set_current_canvas(dlg);
|
|
|
|
ui_string_centered( m->width/2, m->text_y, m->text );
|
|
|
|
|
|
|
|
gr_setcolor( CGREY );
|
|
|
|
Hline(1, m->width-2, m->line_y+1 );
|
|
|
|
|
|
|
|
gr_setcolor( CBRIGHT );
|
|
|
|
Hline(2, m->width-2, m->line_y+2 );
|
|
|
|
|
|
|
|
grd_curscreen->sc_canvas.cv_font = temp_font;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-12-04 23:31:29 +00:00
|
|
|
for (i=0; i < m->button->count(); i++ )
|
2012-01-03 09:24:31 +00:00
|
|
|
{
|
2012-03-05 11:08:41 +00:00
|
|
|
if (GADGET_PRESSED(m->button_g[i]))
|
2012-01-03 09:24:31 +00:00
|
|
|
{
|
|
|
|
*(m->choice) = i+1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-04 23:31:29 +00:00
|
|
|
int (ui_messagebox)( short xc, short yc, const char * text, const ui_messagebox_tie &Button )
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2011-01-17 14:42:18 +00:00
|
|
|
UI_DIALOG * dlg;
|
2012-01-03 09:24:31 +00:00
|
|
|
messagebox *m;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
int i, width, height, avg, x, y;
|
|
|
|
int button_width, button_height, text_height, text_width;
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
|
2012-01-03 09:24:31 +00:00
|
|
|
MALLOC(m, messagebox, 1);
|
2013-12-04 03:07:40 +00:00
|
|
|
m->button = &Button;
|
2012-01-03 09:24:31 +00:00
|
|
|
m->text = text;
|
|
|
|
m->choice = &choice;
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
button_width = button_height = 0;
|
|
|
|
|
|
|
|
gr_set_current_canvas( &grd_curscreen->sc_canvas );
|
|
|
|
w = grd_curscreen->sc_w;
|
|
|
|
h = grd_curscreen->sc_h;
|
|
|
|
|
2013-12-04 23:31:29 +00:00
|
|
|
for (i=0; i < Button.count(); i++ )
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2013-12-04 23:31:29 +00:00
|
|
|
ui_get_button_size( Button.string(i), &width, &height );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
if ( width > button_width ) button_width = width;
|
|
|
|
if ( height > button_height ) button_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
gr_get_string_size(text, &text_width, &text_height, &avg );
|
|
|
|
|
2013-12-04 23:31:29 +00:00
|
|
|
width = button_width*Button.count();
|
|
|
|
width += BUTTON_HORZ_SPACING*(Button.count()+1);
|
2006-03-20 17:12:09 +00:00
|
|
|
width ++;
|
|
|
|
|
|
|
|
text_width += avg*6;
|
|
|
|
text_width += 10;
|
|
|
|
|
|
|
|
if (text_width > width )
|
|
|
|
width = text_width;
|
|
|
|
|
|
|
|
height = text_height;
|
|
|
|
height += button_height;
|
|
|
|
height += 4*TEXT_EXTRA_HEIGHT;
|
|
|
|
height += 2; // For line in middle
|
|
|
|
|
2012-01-03 09:24:31 +00:00
|
|
|
{
|
|
|
|
int mx, my, mz;
|
|
|
|
|
|
|
|
mouse_get_pos(&mx, &my, &mz);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2012-01-03 09:24:31 +00:00
|
|
|
if ( xc == -1 )
|
|
|
|
xc = mx;
|
|
|
|
|
|
|
|
if ( yc == -1 )
|
|
|
|
yc = my - button_height/2;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
if ( xc == -2 )
|
|
|
|
xc = w/2;
|
|
|
|
|
|
|
|
if ( yc == -2 )
|
|
|
|
yc = h/2;
|
|
|
|
|
|
|
|
x = xc - width/2;
|
|
|
|
y = yc - height/2;
|
|
|
|
|
|
|
|
if (x < 0 ) {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (x+width-1) >= w ) {
|
|
|
|
x = w - width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y < 0 ) {
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (y+height-1) >= h ) {
|
|
|
|
y = h - height;
|
|
|
|
}
|
|
|
|
|
2013-12-04 22:37:23 +00:00
|
|
|
dlg = ui_create_dialog( x, y, width, height, static_cast<dialog_flags>(DF_DIALOG | DF_MODAL), messagebox_handler, m );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//ui_draw_line_in( MESSAGEBOX_BORDER, MESSAGEBOX_BORDER, width-MESSAGEBOX_BORDER, height-MESSAGEBOX_BORDER );
|
|
|
|
|
|
|
|
y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
|
|
|
|
|
2012-04-11 02:52:57 +00:00
|
|
|
m->width = width;
|
|
|
|
m->text_y = y;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
y = 2*TEXT_EXTRA_HEIGHT + text_height;
|
2012-04-11 02:52:57 +00:00
|
|
|
|
|
|
|
m->line_y = y;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
y = height - TEXT_EXTRA_HEIGHT - button_height;
|
|
|
|
|
2013-12-04 23:31:29 +00:00
|
|
|
for (i=0; i < Button.count(); i++ )
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
|
2013-12-04 23:31:29 +00:00
|
|
|
x = EVEN_DIVIDE(width,button_width,Button.count(),i);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-04 23:31:29 +00:00
|
|
|
m->button_g[i] = ui_add_gadget_button( dlg, x, y, button_width, button_height, Button.string(i), NULL );
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 14:42:18 +00:00
|
|
|
ui_gadget_calc_keys(dlg);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//key_flush();
|
|
|
|
|
2012-01-03 09:24:31 +00:00
|
|
|
dlg->keyboard_focus_gadget = (UI_GADGET *)m->button_g[0];
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
choice = 0;
|
|
|
|
|
|
|
|
while(choice==0)
|
2011-01-14 09:51:13 +00:00
|
|
|
event_process();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-01-17 14:42:18 +00:00
|
|
|
ui_close_dialog(dlg);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
return choice;
|
|
|
|
}
|