
11.02.2021, 03:12
|
|
Флудер
Регистрация: 06.11.2017
Сообщений: 2,759
С нами:
4483143
Репутация:
183
|
|
Накидал небольшой класс:
C++:
Код:
class
Button
{
public
:
float
x
,
y
,
w
,
h
;
bool
state
;
Button
(
float
_x
,
float
_y
,
float
_w
,
float
_h
)
:
x
(
_x
)
,
y
(
_y
)
,
w
(
_w
)
,
h
(
_h
)
,
state
(
false
)
{
}
void
Draw
(
)
{
if
(
this
->
state
)
{
state
=
false
;
return
SF
->
getRender
(
)
->
DrawBox
(
posX
,
posY
,
Width
,
Height
,
PressedButton
)
;
}
return
SF
->
getRender
(
)
->
DrawBox
(
posX
,
posY
,
Width
,
Height
,
StandartColor
)
;
}
bool
HandleClick
(
float
x
,
float
y
)
noexcept
{
if
(
(
this
->
x
x
)
&&
(
this
->
y
y
)
)
{
return
state
=
true
;
}
return
state
=
false
;
}
}
Можно еще сделать типа пула, только он урежет твою мобильность:
C++:
Код:
class
ButtonPool
{
std
::
vector
Buttons
;
unsigned
int
CreateButton
(
float
x
,
float
y
,
float
w
,
float
h
)
{
this
->
Buttons
.
push_back
(
new
Button
(
x
,
y
,
w
,
h
)
)
;
return
this
->
Buttons
.
size
(
)
-
1
;
}
void
HandleClick
(
LPARAM lParam
)
noexcept
{
float
x
=
GET_X_LPARAM
(
lParam
)
;
float
y
=
GET_Y_LPARAM
(
lParam
)
;
for
(
auto
&
i
:
this
->
Buttons
)
{
i
->
HandleClick
(
x
,
y
)
;
}
}
void
Draw
(
)
{
for
(
auto
&
i
:
this
->
Buttons
)
{
i
->
Draw
(
)
;
}
}
void
DeleteButton
(
unsigned
int
id
)
{
this
->
Buttons
.
erase
(
this
->
Buttons
.
begin
(
)
+
id
)
;
}
}
Также при удалении кнопки, придется все иды смещать самому.
Касательно класса кнопки, чтобы обрабатывать нажатия, запихнуть в WndProc под такими условиями:
C++:
Код:
switch
(
uMsg
)
{
case
WM_LBUTTONDOWN
:
{
float
x
=
GET_X_LPARAM
(
lParam
)
;
float
y
=
GET_Y_LPARAM
(
lParam
)
;
Button
::
HandleClick
(
x
,
y
)
;
}
}
Ща налетят всякие мемиры и человечики, и скажут что говно
|
|
|