Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Chess
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bolla Péter
Chess
Commits
e23fa524
Commit
e23fa524
authored
2 months ago
by
Bolla Péter
Browse files
Options
Downloads
Patches
Plain Diff
Update button.cpp
parent
4526871a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
button.cpp
+62
-38
62 additions, 38 deletions
button.cpp
with
62 additions
and
38 deletions
button.cpp
+
62
−
38
View file @
e23fa524
...
@@ -6,59 +6,68 @@ struct DrawColor{
...
@@ -6,59 +6,68 @@ struct DrawColor{
int
r
,
g
,
b
;
int
r
,
g
,
b
;
};
};
const
DrawColor
BG_BLACK
{
205
,
133
,
63
},
BG_WHITE
{
255
,
248
,
220
};
const
DrawColor
BG_BLACK
{
205
,
133
,
63
},
BG_WHITE
{
255
,
248
,
220
}
,
BG_ACTIVE
{
255
,
255
,
51
},
BG_CHECK
{
255
,
99
,
71
},
BG_MATE
{
220
,
20
,
60
}
;
Button
::
Button
(
App
*
parent
,
int
x
,
int
y
,
int
sx
,
int
sy
,
std
::
function
<
void
()
>
f
,
Square
s
)
:
Button
::
Button
(
App
*
parent
,
int
x
,
int
y
,
int
sx
,
int
sy
,
std
::
function
<
void
()
>
f
,
Chess
*
chb
,
int
i
)
:
Widget
(
parent
,
x
,
y
,
sx
,
sy
),
_f
(
f
),
_
s
(
s
)
Widget
(
parent
,
x
,
y
,
sx
,
sy
),
_f
(
f
),
_
ind
(
i
),
_cb
(
chb
)
{
{
pressed
=
0
;
pressed
=
0
;
active
=
0
;
}
}
void
Button
::
Draw
()
const
void
Button
::
Draw
()
const
{
{
//DRAW BACKGROUND
//DRAW BACKGROUND
if
(
_s
.
color
==
White
)
gout
<<
color
(
BG_WHITE
.
r
,
BG_WHITE
.
g
,
BG_WHITE
.
b
);
if
(
pressed
||
active
)
{
gout
<<
color
(
BG_ACTIVE
.
r
,
BG_ACTIVE
.
g
,
BG_ACTIVE
.
b
);
}
else
if
(
_cb
->
GetColor
(
_ind
)
==
White
)
gout
<<
color
(
BG_WHITE
.
r
,
BG_WHITE
.
g
,
BG_WHITE
.
b
);
else
gout
<<
color
(
BG_BLACK
.
r
,
BG_BLACK
.
g
,
BG_BLACK
.
b
);
else
gout
<<
color
(
BG_BLACK
.
r
,
BG_BLACK
.
g
,
BG_BLACK
.
b
);
gout
<<
move_to
(
_x
,
_y
)
<<
box
(
_sx
,
_sy
);
gout
<<
move_to
(
_x
,
_y
)
<<
box
(
_sx
,
_sy
);
//If occupied -> draw the piece
//If occupied -> draw the piece
if
(
_s
.
occupied
)
if
(
_cb
->
Occupied
(
_ind
))
//gout.load_font("LUCEFONT.TTF", 40);
{
gout
<<
move_to
(
_x
+
2
,
_y
+
2
*
_sy
);
gout
.
load_font
(
"CASEFONT.TTF"
,
60
);
gout
<<
color
(
0
,
0
,
0
);
}
gout
<<
move_to
(
_x
+
_sx
/
8
,
_y
+
_sy
/
8
);
{
{
if
(
_
s
.
piece
.
team
==
Light
)
if
(
_
cb
->
GetSquare
(
_ind
)
.
piece
.
team
==
Light
)
{
{
switch
(
_
s
.
piece
.
type
)
switch
(
_
cb
->
GetSquare
(
_ind
)
.
piece
.
type
)
{
{
case
Pawn
:
case
Pawn
:
{
{
gout
<<
text
(
'
P
'
);
gout
<<
text
(
'
p
'
);
break
;
break
;
}
}
case
Rook
:
case
Rook
:
{
{
gout
<<
text
(
'
R
'
);
gout
<<
text
(
'
r
'
);
break
;
break
;
}
}
case
Knight
:
case
Knight
:
{
{
gout
<<
text
(
'
N
'
);
gout
<<
text
(
'
n
'
);
break
;
break
;
}
}
case
Bishop
:
case
Bishop
:
{
{
gout
<<
text
(
'
B
'
);
gout
<<
text
(
'
b
'
);
break
;
break
;
}
}
case
King
:
case
King
:
{
{
gout
<<
text
(
'
K
'
);
gout
<<
text
(
'
k
'
);
break
;
break
;
}
}
case
Queen
:
case
Queen
:
{
{
gout
<<
text
(
'
Q
'
);
gout
<<
text
(
'
q
'
);
break
;
break
;
}
}
case
Empty
:
case
Empty
:
...
@@ -66,37 +75,37 @@ void Button::Draw() const
...
@@ -66,37 +75,37 @@ void Button::Draw() const
}
}
}
}
else
{
else
{
switch
(
_
s
.
piece
.
type
)
switch
(
_
cb
->
GetSquare
(
_ind
)
.
piece
.
type
)
{
{
case
Pawn
:
case
Pawn
:
{
{
gout
<<
text
(
'
p
'
);
gout
<<
text
(
'
o
'
);
break
;
break
;
}
}
case
Rook
:
case
Rook
:
{
{
gout
<<
text
(
'
r
'
);
gout
<<
text
(
'
t
'
);
break
;
break
;
}
}
case
Knight
:
case
Knight
:
{
{
gout
<<
text
(
'
n
'
);
gout
<<
text
(
'
m
'
);
break
;
break
;
}
}
case
Bishop
:
case
Bishop
:
{
{
gout
<<
text
(
'
b
'
);
gout
<<
text
(
'
v
'
);
break
;
break
;
}
}
case
King
:
case
King
:
{
{
gout
<<
text
(
'
k
'
);
gout
<<
text
(
'
l
'
);
break
;
break
;
}
}
case
Queen
:
case
Queen
:
{
{
gout
<<
text
(
'
q
'
);
gout
<<
text
(
'
w
'
);
break
;
break
;
}
}
case
Empty
:
case
Empty
:
...
@@ -106,26 +115,30 @@ void Button::Draw() const
...
@@ -106,26 +115,30 @@ void Button::Draw() const
}
}
}
}
void
Button
::
Handle
(
genv
::
event
ev
)
void
Button
::
Handle
(
genv
::
event
ev
,
Operation
op
)
{
{
if
(
ev
.
type
==
ev_mouse
)
if
(
op
==
PRESS
)
{
if
(
ev
.
button
==
btn_left
)
{
{
Press
();
Press
();
action
();
action
();
}
}
else
if
(
ev
.
button
==
-
btn_left
)
else
if
(
op
==
RELEASE
)
{
{
Release
();
Release
();
}
}
else
if
(
op
==
ACTIVATE
)
{
Activate
();
}
else
if
(
op
==
DEACTIVATE
)
{
Deactivate
();
}
}
}
}
void
Button
::
Press
()
void
Button
::
Press
()
{
{
if
(
_cb
->
Occupied
(
_ind
))
pressed
=
1
;
pressed
=
1
;
}
}
...
@@ -139,11 +152,22 @@ bool Button::Pressed()
...
@@ -139,11 +152,22 @@ bool Button::Pressed()
return
pressed
;
return
pressed
;
}
}
std
::
string
Button
::
GetValue
()
const
void
Button
::
Activate
()
{
{
return
0
;
active
=
1
;
}
}
void
Button
::
Deactivate
()
{
active
=
0
;
}
bool
Button
::
Active
()
{
return
active
;
}
void
Button
::
action
()
void
Button
::
action
()
{
{
_f
();
_f
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment