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 <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "u_mem.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-05 11:45:27 +00:00
|
|
|
#include "mouse.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "key.h"
|
|
|
|
|
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)
|
|
|
|
|
2017-02-11 21:42:44 +00:00
|
|
|
static void ui_draw_box_in1(grs_canvas &canvas, const unsigned x1, const unsigned y1, const unsigned x2, const unsigned y2)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2020-07-16 02:31:04 +00:00
|
|
|
const auto color = CWHITE;
|
2017-02-11 21:42:44 +00:00
|
|
|
gr_urect(canvas, x1 + 1, y1 + 1, x2 - 1, y2 - 1, color);
|
|
|
|
ui_draw_shad(canvas, x1, y1, x2, y2, CGREY, CBRIGHT);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_draw_icon( UI_GADGET_ICON * icon )
|
|
|
|
{
|
2015-09-29 02:41:22 +00:00
|
|
|
int height, width;
|
2006-03-20 17:12:09 +00:00
|
|
|
int x, y;
|
|
|
|
|
2012-03-31 12:25:09 +00:00
|
|
|
#if 0 //ndef OGL
|
2006-03-20 17:12:09 +00:00
|
|
|
if ((icon->status==1) || (icon->position != icon->oldposition))
|
2012-03-31 10:36:07 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
icon->status = 0;
|
|
|
|
|
|
|
|
gr_set_current_canvas( icon->canvas );
|
2017-03-10 01:22:24 +00:00
|
|
|
auto &canvas = *grd_curcanv;
|
|
|
|
gr_get_string_size(*canvas.cv_font, icon->text.get(), &width, &height, nullptr);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
x = ((icon->width-1)/2)-((width-1)/2);
|
|
|
|
y = ((icon->height-1)/2)-((height-1)/2);
|
|
|
|
|
|
|
|
if (icon->position==1 )
|
|
|
|
{
|
|
|
|
// Draw pressed
|
2017-03-10 01:22:24 +00:00
|
|
|
ui_draw_box_in(canvas, 0, 0, icon->width, icon->height);
|
2006-03-20 17:12:09 +00:00
|
|
|
x += 2; y += 2;
|
|
|
|
}
|
|
|
|
else if (icon->flag)
|
|
|
|
{
|
|
|
|
// Draw part out
|
2017-03-10 01:22:24 +00:00
|
|
|
ui_draw_box_in1(canvas, 0, 0, icon->width, icon->height);
|
2006-03-20 17:12:09 +00:00
|
|
|
x += 1; y += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Draw released!
|
2017-03-10 01:22:24 +00:00
|
|
|
ui_draw_box_out(canvas, 0, 0, icon->width, icon->height);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 01:22:24 +00:00
|
|
|
gr_set_fontcolor(canvas, CBLACK, -1);
|
2018-05-19 23:21:42 +00:00
|
|
|
gr_ustring(canvas, *canvas.cv_font, x, y, icon->text.get());
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-20 04:36:09 +00:00
|
|
|
std::unique_ptr<UI_GADGET_ICON> ui_add_gadget_icon(UI_DIALOG * dlg, const char * text, short x, short y, short w, short h, int k,int (*f)())
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2020-10-12 03:28:25 +00:00
|
|
|
auto icon = ui_gadget_add<UI_GADGET_ICON>(*dlg, x, y, x + w - 1, y + h - 1);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
icon->width = w;
|
|
|
|
icon->height = h;
|
2015-02-17 03:52:59 +00:00
|
|
|
auto ltext = strlen(text) + 1;
|
|
|
|
MALLOC( icon->text, char[], ltext + 1);//Hack by KRB
|
|
|
|
memcpy(icon->text.get(), text, ltext);
|
2006-03-20 17:12:09 +00:00
|
|
|
icon->trap_key = k;
|
|
|
|
icon->user_function = f;
|
|
|
|
icon->oldposition = 0;
|
|
|
|
icon->position = 0;
|
|
|
|
icon->pressed = 0;
|
2014-07-20 03:48:27 +00:00
|
|
|
icon->canvas->cv_font = ui_small_font.get();
|
2006-03-20 17:12:09 +00:00
|
|
|
// Call twice to get original;
|
|
|
|
if (f)
|
|
|
|
{
|
2016-06-16 03:56:44 +00:00
|
|
|
icon->flag = static_cast<int8_t>(f());
|
|
|
|
icon->flag = static_cast<int8_t>(f());
|
2006-03-20 17:12:09 +00:00
|
|
|
} else {
|
|
|
|
icon->flag = 0;
|
|
|
|
}
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2020-10-12 03:28:26 +00:00
|
|
|
window_event_result UI_GADGET_ICON::event_handler(UI_DIALOG &dlg, const d_event &event)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2020-10-12 03:28:26 +00:00
|
|
|
oldposition = position;
|
|
|
|
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
|
|
|
{
|
2020-10-12 03:28:26 +00:00
|
|
|
const auto OnMe = ui_mouse_on_gadget(*this);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-11-05 11:45:27 +00:00
|
|
|
if (B1_JUST_PRESSED && OnMe)
|
|
|
|
{
|
2020-10-12 03:28:26 +00:00
|
|
|
position = 1;
|
2014-08-06 02:10:49 +00:00
|
|
|
rval = window_event_result::handled;
|
2011-11-05 11:45:27 +00:00
|
|
|
}
|
|
|
|
else if (B1_JUST_RELEASED)
|
|
|
|
{
|
2020-10-12 03:28:26 +00:00
|
|
|
if ((position == 1) && OnMe)
|
|
|
|
pressed = 1;
|
2011-11-05 11:45:27 +00:00
|
|
|
|
2020-10-12 03:28:26 +00:00
|
|
|
position = 0;
|
2011-11-05 11:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
|
2014-10-04 21:47:13 +00:00
|
|
|
if (event.type == EVENT_KEY_COMMAND)
|
2011-11-05 11:45:27 +00:00
|
|
|
{
|
2020-10-12 03:28:26 +00:00
|
|
|
const auto key = event_key_get(event);
|
|
|
|
if (key == trap_key)
|
2011-11-05 11:45:27 +00:00
|
|
|
{
|
2020-10-12 03:28:26 +00:00
|
|
|
position = 1;
|
2014-08-06 02:10:49 +00:00
|
|
|
rval = window_event_result::handled;
|
2011-11-05 11:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-04 21:47:13 +00:00
|
|
|
else if (event.type == EVENT_KEY_RELEASE)
|
2011-11-05 11:45:27 +00:00
|
|
|
{
|
2020-10-12 03:28:26 +00:00
|
|
|
const auto key = event_key_get(event);
|
|
|
|
position = 0;
|
|
|
|
if (key == trap_key)
|
|
|
|
pressed = 1;
|
2011-11-05 11:45:27 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 03:28:26 +00:00
|
|
|
if (pressed == 1)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2020-10-12 03:28:26 +00:00
|
|
|
status = 1;
|
|
|
|
flag = static_cast<int8_t>(user_function());
|
|
|
|
rval = ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, *this);
|
2016-10-27 11:42:48 +00:00
|
|
|
if (rval == window_event_result::ignored)
|
|
|
|
rval = window_event_result::handled;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2014-10-04 21:47:13 +00:00
|
|
|
if (event.type == EVENT_WINDOW_DRAW)
|
2020-10-12 03:28:26 +00:00
|
|
|
ui_draw_icon(this);
|
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
|
|
|
}
|
2015-12-05 22:57:24 +00:00
|
|
|
|
|
|
|
}
|