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.
|
|
|
|
*/
|
|
|
|
|
2010-12-24 04:34:30 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Radio box gadget stuff.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-07-01 02:54:33 +00:00
|
|
|
#include "maths.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "pstypes.h"
|
2011-10-25 01:39:35 +00:00
|
|
|
#include "event.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "gr.h"
|
|
|
|
#include "ui.h"
|
2011-11-06 12:06:41 +00:00
|
|
|
#include "mouse.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "key.h"
|
|
|
|
#include "u_mem.h"
|
2012-07-24 09:28:44 +00:00
|
|
|
#include "strutil.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:24 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
#define Middle(x) ((2*(x)+1)/4)
|
|
|
|
|
2012-03-03 12:19:15 +00:00
|
|
|
void ui_draw_radio( UI_DIALOG *dlg, UI_GADGET_RADIO * radio )
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2012-03-31 12:25:09 +00:00
|
|
|
#if 0 //ndef OGL
|
2006-03-20 17:12:09 +00:00
|
|
|
if ((radio->status==1) || (radio->position != radio->oldposition))
|
2012-03-31 10:36:07 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
radio->status = 0;
|
|
|
|
|
|
|
|
gr_set_current_canvas( radio->canvas );
|
|
|
|
|
2014-10-04 22:13:47 +00:00
|
|
|
if (dlg->keyboard_focus_gadget == radio)
|
2006-03-20 17:12:09 +00:00
|
|
|
gr_set_fontcolor(CRED, -1);
|
|
|
|
else
|
|
|
|
gr_set_fontcolor(CBLACK, -1);
|
|
|
|
|
|
|
|
if (radio->position == 0 )
|
|
|
|
{
|
|
|
|
ui_draw_box_out( 0, 0, radio->width-1, radio->height-1 );
|
|
|
|
if (radio->flag)
|
|
|
|
ui_string_centered(Middle(radio->width), Middle(radio->height), "O");
|
|
|
|
else
|
|
|
|
ui_string_centered(Middle(radio->width), Middle(radio->height), " ");
|
|
|
|
} else {
|
|
|
|
ui_draw_box_in( 0, 0, radio->width-1, radio->height-1 );
|
|
|
|
if (radio->flag)
|
|
|
|
ui_string_centered(Middle(radio->width) + 1, Middle(radio->height) + 1, "O");
|
|
|
|
else
|
|
|
|
ui_string_centered(Middle(radio->width) + 1, Middle(radio->height) + 1, " ");
|
|
|
|
}
|
|
|
|
|
2015-02-17 03:52:59 +00:00
|
|
|
gr_ustring(radio->width+4, 2, radio->text.get());
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-20 04:36:10 +00:00
|
|
|
std::unique_ptr<UI_GADGET_RADIO> ui_add_gadget_radio(UI_DIALOG * dlg, short x, short y, short w, short h, short group, const char * text)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2014-12-20 04:36:10 +00:00
|
|
|
std::unique_ptr<UI_GADGET_RADIO> radio{ui_gadget_add<UI_GADGET_RADIO>(dlg, x, y, x+w-1, y+h-1)};
|
2015-01-28 03:42:53 +00:00
|
|
|
radio->text = RAIIdmem<char[]>(d_strdup(text));
|
2006-03-20 17:12:09 +00:00
|
|
|
radio->width = w;
|
|
|
|
radio->height = h;
|
|
|
|
radio->position = 0;
|
|
|
|
radio->oldposition = 0;
|
|
|
|
radio->pressed = 0;
|
|
|
|
radio->flag = 0;
|
|
|
|
radio->group = group;
|
|
|
|
return radio;
|
|
|
|
}
|
|
|
|
|
2014-10-04 21:47:13 +00:00
|
|
|
window_event_result ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio,const d_event &event )
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
UI_GADGET * tmp;
|
|
|
|
radio->oldposition = radio->position;
|
2011-11-06 12:06:41 +00:00
|
|
|
radio->pressed = 0;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-08-06 02:10:49 +00:00
|
|
|
window_event_result rval = window_event_result::ignored;
|
2014-10-04 21:47:13 +00:00
|
|
|
if (event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2011-11-06 12:06:41 +00:00
|
|
|
int OnMe;
|
|
|
|
|
2014-10-04 22:13:47 +00:00
|
|
|
OnMe = ui_mouse_on_gadget( radio );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-11-06 12:06:41 +00:00
|
|
|
if ( B1_JUST_PRESSED && OnMe)
|
|
|
|
{
|
|
|
|
radio->position = 1;
|
2014-08-06 02:10:49 +00:00
|
|
|
rval = window_event_result::handled;
|
2011-11-06 12:06:41 +00:00
|
|
|
}
|
|
|
|
else if (B1_JUST_RELEASED)
|
|
|
|
{
|
|
|
|
if ((radio->position==1) && OnMe)
|
|
|
|
radio->pressed = 1;
|
|
|
|
|
|
|
|
radio->position = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-11-06 12:06:41 +00:00
|
|
|
|
2014-10-04 21:47:13 +00:00
|
|
|
if (event.type == EVENT_KEY_COMMAND)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2011-11-06 12:06:41 +00:00
|
|
|
int key;
|
|
|
|
|
|
|
|
key = event_key_get(event);
|
|
|
|
|
2014-10-04 22:13:47 +00:00
|
|
|
if ((dlg->keyboard_focus_gadget==radio) && ((key==KEY_SPACEBAR) || (key==KEY_ENTER)) )
|
2011-11-06 12:06:41 +00:00
|
|
|
{
|
|
|
|
radio->position = 2;
|
2014-08-06 02:10:49 +00:00
|
|
|
rval = window_event_result::handled;
|
2011-11-06 12:06:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-04 21:47:13 +00:00
|
|
|
else if (event.type == EVENT_KEY_RELEASE)
|
2011-11-06 12:06:41 +00:00
|
|
|
{
|
|
|
|
int key;
|
|
|
|
|
|
|
|
key = event_key_get(event);
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
radio->position = 0;
|
2011-11-06 12:06:41 +00:00
|
|
|
|
2014-10-04 22:13:47 +00:00
|
|
|
if ((dlg->keyboard_focus_gadget==radio) && ((key==KEY_SPACEBAR) || (key==KEY_ENTER)) )
|
2011-11-06 12:06:41 +00:00
|
|
|
radio->pressed = 1;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2011-11-06 12:06:41 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
if ((radio->pressed == 1) && (radio->flag==0))
|
|
|
|
{
|
2014-10-04 22:13:47 +00:00
|
|
|
tmp = radio->next;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-10-04 22:13:47 +00:00
|
|
|
while (tmp != radio )
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2014-09-06 23:27:57 +00:00
|
|
|
if (tmp->kind==UI_GADGET_RADIO::s_kind)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2014-10-04 22:13:47 +00:00
|
|
|
auto tmpr = static_cast<UI_GADGET_RADIO *>(tmp);
|
2006-03-20 17:12:09 +00:00
|
|
|
if ((tmpr->group == radio->group ) && (tmpr->flag) )
|
|
|
|
{
|
|
|
|
tmpr->flag = 0;
|
|
|
|
tmpr->status = 1;
|
|
|
|
tmpr->pressed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
radio->flag = 1;
|
2016-10-27 11:42:48 +00:00
|
|
|
rval = ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, radio);
|
|
|
|
if (rval == window_event_result::ignored)
|
|
|
|
rval = window_event_result::handled;
|
2012-03-03 12:19:15 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-10-04 21:47:13 +00:00
|
|
|
if (event.type == EVENT_WINDOW_DRAW)
|
2012-03-31 10:36:07 +00:00
|
|
|
ui_draw_radio( dlg, radio );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-10-25 01:39:35 +00:00
|
|
|
return rval;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2010-12-24 04:34:30 +00:00
|
|
|
void ui_radio_set_value(UI_GADGET_RADIO *radio, int value)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2010-12-24 04:34:30 +00:00
|
|
|
value = value != 0;
|
2006-03-20 17:12:09 +00:00
|
|
|
if (radio->flag == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
radio->flag = value;
|
|
|
|
radio->status = 1; // redraw
|
|
|
|
|
2016-07-06 01:54:25 +00:00
|
|
|
for (auto tmp = radio; (tmp = static_cast<UI_GADGET_RADIO *>(tmp->next)) != radio;)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2014-09-06 23:27:57 +00:00
|
|
|
if ((tmp->kind == UI_GADGET_RADIO::s_kind) && (tmp->group == radio->group) && tmp->flag)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
tmp->flag = 0;
|
|
|
|
tmp->status = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-05 22:57:24 +00:00
|
|
|
|
|
|
|
}
|