Debian Codegraph @

common/ui/userbox.cpp

raw
1 /*
2 * Portions of this file are copyright Rebirth contributors and licensed as
3 * described in COPYING.txt.
4 * Portions of this file are copyright Parallax Software and licensed
5 * according to the Parallax license below.
6 * See COPYING.txt for license details.
7
8 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
10 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
16 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
18 */
19
20
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include "maths.h"
25 #include "pstypes.h"
26 #include "event.h"
27 #include "gr.h"
28 #include "ui.h"
29 #include "mouse.h"
30 #include "key.h"
31
32 namespace dcx {
33
34 namespace {
35
36 void ui_draw_userbox(UI_DIALOG &dlg, UI_GADGET_USERBOX &userbox)
37 {
38 #if 0 //ndef OGL
39 if ( userbox->status==1 )
40 #endif
41 {
42 gr_set_current_canvas(userbox.canvas);
43
44 const uint8_t color = (dlg.keyboard_focus_gadget == &userbox)
45 ? CRED
46 : CBRIGHT;
47 gr_ubox(*grd_curcanv, -1, -1, userbox.width, userbox.height, color);
48 }
49 }
50
51 }
52
53 std::unique_ptr<UI_GADGET_USERBOX> ui_add_gadget_userbox(UI_DIALOG &dlg, short x, short y, short w, short h)
54 {
55 auto userbox = ui_gadget_add<UI_GADGET_USERBOX>(dlg, x, y, x + w - 1, y + h - 1);
56 userbox->width = w;
57 userbox->height = h;
58 userbox->b1_held_down=0;
59 userbox->b1_clicked=0;
60 userbox->b1_double_clicked=0;
61 userbox->b1_dragging=0;
62 userbox->b1_drag_x1=0;
63 userbox->b1_drag_y1=0;
64 userbox->b1_drag_x2=0;
65 userbox->b1_drag_y2=0;
66 userbox->b1_done_dragging = 0;
67 userbox->keypress = 0;
68 userbox->mouse_onme = 0;
69 userbox->mouse_x = 0;
70 userbox->mouse_y = 0;
71 userbox->bitmap = &(userbox->canvas->cv_bitmap);
72 return userbox;
73 }
74
75 window_event_result UI_GADGET_USERBOX::event_handler(UI_DIALOG &dlg, const d_event &event)
76 {
77 window_event_result rval = window_event_result::ignored;
78 if (event.type == event_type::window_draw)
79 ui_draw_userbox(dlg, *this);
80
81 const auto keypress = (event.type == event_type::key_command)
82 ? event_key_get(event)
83 : 0u;
84 const auto [x, y, z] = mouse_get_pos();
85 const auto OnMe = ui_mouse_on_gadget(*this);
86
87 const auto olddrag = b1_held_down;
88
89 mouse_onme = OnMe;
90 mouse_x = x - x1;
91 mouse_y = y - y1;
92
93 b1_dragging = 0;
94 b1_clicked = 0;
95
96 if (OnMe)
97 {
98 if ( B1_JUST_PRESSED )
99 {
100 b1_held_down = 1;
101 b1_drag_x1 = x - x1;
102 b1_drag_y1 = y - y1;
103 rval = window_event_result::handled;
104 }
105 else if (B1_JUST_RELEASED)
106 {
107 if (b1_held_down)
108 b1_clicked = 1;
109 b1_held_down = 0;
110 rval = window_event_result::handled;
111 }
112
113 if (event.type == event_type::mouse_moved && b1_held_down)
114 {
115 b1_dragging = 1;
116 b1_drag_x2 = x - x1;
117 b1_drag_y2 = y - y1;
118 }
119
120 if ( B1_DOUBLE_CLICKED )
121 {
122 b1_double_clicked = 1;
123 rval = window_event_result::handled;
124 }
125 else
126 b1_double_clicked = 0;
127
128 }
129
130 if (B1_JUST_RELEASED)
131 b1_held_down = 0;
132
133 b1_done_dragging = 0;
134
135 if (olddrag==1 && b1_held_down==0 )
136 {
137 if ((b1_drag_x1 != b1_drag_x2) || (b1_drag_y1 != b1_drag_y2) )
138 b1_done_dragging = 1;
139 }
140
141 if (dlg.keyboard_focus_gadget == this)
142 {
143 this->keypress = keypress;
144 rval = window_event_result::handled;
145 }
146 if (b1_clicked || b1_dragging)
147 {
148 rval = ui_gadget_send_event(dlg, b1_clicked ? event_type::ui_gadget_pressed : event_type::ui_userbox_dragged, *this);
149 if (rval == window_event_result::ignored)
150 rval = window_event_result::handled;
151 }
152
153 return rval;
154 }
155
156
157
158
159
160 }