dxx-rebirth/common/ui/userbox.cpp

165 lines
3.8 KiB
C++
Raw Normal View History

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>
2012-07-01 02:54:33 +00:00
#include "maths.h"
2006-03-20 17:12:09 +00:00
#include "pstypes.h"
#include "event.h"
2006-03-20 17:12:09 +00:00
#include "gr.h"
#include "ui.h"
#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
2020-10-12 03:28:26 +00:00
namespace {
void ui_draw_userbox(UI_DIALOG &dlg, UI_GADGET_USERBOX &userbox)
2006-03-20 17:12:09 +00:00
{
#if 0 //ndef OGL
2006-03-20 17:12:09 +00:00
if ( userbox->status==1 )
#endif
2006-03-20 17:12:09 +00:00
{
2020-10-12 03:28:26 +00:00
gr_set_current_canvas(userbox.canvas);
2006-03-20 17:12:09 +00:00
2020-10-12 03:28:26 +00:00
const uint8_t color = (dlg.keyboard_focus_gadget == &userbox)
2016-02-12 04:02:28 +00:00
? CRED
: CBRIGHT;
2020-10-12 03:28:26 +00:00
gr_ubox(*grd_curcanv, -1, -1, userbox.width, userbox.height, color);
2006-03-20 17:12:09 +00:00
}
}
2020-10-12 03:28:26 +00:00
}
2006-03-20 17:12:09 +00:00
std::unique_ptr<UI_GADGET_USERBOX> ui_add_gadget_userbox(UI_DIALOG &dlg, short x, short y, short w, short h)
2006-03-20 17:12:09 +00:00
{
auto userbox = ui_gadget_add<UI_GADGET_USERBOX>(dlg, x, y, x + w - 1, y + h - 1);
2006-03-20 17:12:09 +00:00
userbox->width = w;
userbox->height = h;
userbox->b1_held_down=0;
userbox->b1_clicked=0;
userbox->b1_double_clicked=0;
userbox->b1_dragging=0;
userbox->b1_drag_x1=0;
userbox->b1_drag_y1=0;
userbox->b1_drag_x2=0;
userbox->b1_drag_y2=0;
userbox->b1_done_dragging = 0;
userbox->keypress = 0;
userbox->mouse_onme = 0;
userbox->mouse_x = 0;
userbox->mouse_y = 0;
userbox->bitmap = &(userbox->canvas->cv_bitmap);
return userbox;
}
window_event_result UI_GADGET_USERBOX::event_handler(UI_DIALOG &dlg, const d_event &event)
2006-03-20 17:12:09 +00:00
{
int x, y, z;
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_WINDOW_DRAW)
2020-10-12 03:28:26 +00:00
ui_draw_userbox(dlg, *this);
const auto keypress = (event.type == EVENT_KEY_COMMAND)
? event_key_get(event)
: 0u;
mouse_get_pos(&x, &y, &z);
const auto OnMe = ui_mouse_on_gadget(*this);
2006-03-20 17:12:09 +00:00
const auto olddrag = b1_held_down;
2006-03-20 17:12:09 +00:00
mouse_onme = OnMe;
mouse_x = x - x1;
mouse_y = y - y1;
2006-03-20 17:12:09 +00:00
b1_dragging = 0;
b1_clicked = 0;
2006-03-20 17:12:09 +00:00
if (OnMe)
{
if ( B1_JUST_PRESSED )
{
b1_held_down = 1;
b1_drag_x1 = x - x1;
b1_drag_y1 = y - y1;
2014-08-06 02:10:49 +00:00
rval = window_event_result::handled;
2006-03-20 17:12:09 +00:00
}
else if (B1_JUST_RELEASED)
2006-03-20 17:12:09 +00:00
{
if (b1_held_down)
b1_clicked = 1;
b1_held_down = 0;
2014-08-06 02:10:49 +00:00
rval = window_event_result::handled;
}
if ( (event.type == EVENT_MOUSE_MOVED) && b1_held_down )
{
b1_dragging = 1;
b1_drag_x2 = x - x1;
b1_drag_y2 = y - y1;
2006-03-20 17:12:09 +00:00
}
if ( B1_DOUBLE_CLICKED )
{
b1_double_clicked = 1;
2014-08-06 02:10:49 +00:00
rval = window_event_result::handled;
}
2006-03-20 17:12:09 +00:00
else
b1_double_clicked = 0;
2006-03-20 17:12:09 +00:00
}
if (B1_JUST_RELEASED)
b1_held_down = 0;
2006-03-20 17:12:09 +00:00
b1_done_dragging = 0;
2006-03-20 17:12:09 +00:00
if (olddrag==1 && b1_held_down==0 )
2006-03-20 17:12:09 +00:00
{
if ((b1_drag_x1 != b1_drag_x2) || (b1_drag_y1 != b1_drag_y2) )
b1_done_dragging = 1;
2006-03-20 17:12:09 +00:00
}
if (dlg.keyboard_focus_gadget == this)
{
this->keypress = keypress;
2014-08-06 02:10:49 +00:00
rval = window_event_result::handled;
}
2012-03-03 12:19:15 +00:00
if (b1_clicked || b1_dragging)
2012-03-03 12:19:15 +00:00
{
rval = ui_gadget_send_event(dlg, b1_clicked ? EVENT_UI_GADGET_PRESSED : EVENT_UI_USERBOX_DRAGGED, *this);
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
return rval;
2006-03-20 17:12:09 +00:00
}
2015-12-05 22:57:24 +00:00
}