Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Minesweeper2D
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
Model registry
Operate
Environments
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
barni2000
Minesweeper2D
Commits
025a929f
Commit
025a929f
authored
Nov 8, 2013
by
Czémán Barnabás
Browse files
Options
Downloads
Patches
Plain Diff
Beviteli mező modified
parent
753563a2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
input.c
+32
-87
32 additions, 87 deletions
input.c
input.h
+1
-1
1 addition, 1 deletion
input.h
main.c
+4
-4
4 additions, 4 deletions
main.c
with
37 additions
and
92 deletions
input.c
+
32
−
87
View file @
025a929f
#include
"input.h"
#define NUMBERS 10
#define ABC 27
/*Beviteli típus*/
typedef
struct
Key
{
int
key
;
char
character
;
}
Key
;
/*Számok*/
Key
number
[
NUMBERS
]
=
{
{
SDLK_0
,
'0'
},
{
SDLK_1
,
'1'
},
{
SDLK_2
,
'2'
},
{
SDLK_3
,
'3'
},
{
SDLK_4
,
'4'
},
{
SDLK_5
,
'5'
},
{
SDLK_6
,
'6'
},
{
SDLK_7
,
'7'
},
{
SDLK_8
,
'8'
},
{
SDLK_9
,
'9'
}
};
/*Betük*/
Key
abc
[
ABC
]
=
{
{
SDLK_a
,
'a'
},
{
SDLK_b
,
'b'
},
{
SDLK_c
,
'c'
},
{
SDLK_d
,
'd'
},
{
SDLK_e
,
'e'
},
{
SDLK_f
,
'f'
},
{
SDLK_g
,
'g'
},
{
SDLK_h
,
'h'
},
{
SDLK_i
,
'i'
},
{
SDLK_j
,
'j'
},
{
SDLK_k
,
'k'
},
{
SDLK_l
,
'l'
},
{
SDLK_m
,
'm'
},
{
SDLK_n
,
'n'
},
{
SDLK_o
,
'o'
},
{
SDLK_p
,
'p'
},
{
SDLK_q
,
'q'
},
{
SDLK_r
,
'r'
},
{
SDLK_s
,
's'
},
{
SDLK_t
,
't'
},
{
SDLK_u
,
'u'
},
{
SDLK_v
,
'v'
},
{
SDLK_x
,
'x'
},
{
SDLK_y
,
'y'
},
{
SDLK_z
,
'z'
}
};
void
drawInput
(
SDL_Surface
*
screen
,
Input
*
input
){
/*Kirajzol egy inputot*/
SDL_Rect
siz
=
{
0
},
pos
=
{
0
};
...
...
@@ -59,7 +12,7 @@ void drawInput(SDL_Surface* screen,Input* input){/*Kirajzol egy inputot*/
SDL_BlitSurface
(
input
->
bg
,
&
siz
,
screen
,
&
pos
);
if
(
input
->
textS
!=
NULL
)
pos
.
y
+=
(
siz
.
h
-
input
->
textS
->
h
)
/
2
;
SDL_BlitSurface
(
input
->
textS
,
&
siz
,
screen
,
&
pos
);
SDL_BlitSurface
(
input
->
textS
,
NULL
,
screen
,
&
pos
);
}
void
setInput
(
Input
*
input
,
SDL_Surface
*
bg
,
SDL_Rect
rect
){
/*Inicializáció*/
...
...
@@ -79,35 +32,28 @@ void setInputActive(Input* input,SDL_Event* evt){/*Aktívba állítja az bevitel
}
int
addNewElement
(
Input
*
input
,
SDL_Event
*
evt
,
Key
*
in
,
int
n
){
/*hozzáad egy új karaktert*/
int
addNewElement
(
Input
*
input
,
Uint16
element
){
/*hozzáad egy új karaktert*/
int
i
,
exit
=
0
,
index
=-
1
;
char
*
cache
;
for
(
i
=
0
;
i
<
n
&&
exit
!=
1
;
i
++
){
if
(
evt
->
key
.
keysym
.
sym
==
in
[
i
].
key
){
exit
=
1
;
index
=
i
;
}
}
if
(
i
<
n
){
Uint16
*
cache
;
i
=
0
;
cache
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
input
->
textSize
+
1
));
cache
=
(
Uint16
*
)
malloc
(
sizeof
(
Uint16
)
*
(
input
->
textSize
+
1
));
//if(input->text!=NULL)
for
(
i
=
0
;
i
<
input
->
textSize
-
1
;
i
++
){
cache
[
i
]
=
input
->
text
[
i
];
}
cache
[
i
]
=
in
[
index
].
character
;
cache
[
i
]
=
element
;
cache
[
i
+
1
]
=
'\0'
;
free
(
input
->
text
);
input
->
text
=
cache
;
input
->
textSize
++
;
}
return
index
;
}
void
deleteAElement
(
Input
*
input
){
/*kitöröl egy karakter*/
int
i
=
0
;
char
*
cache
;
cache
=
(
char
*
)
malloc
(
sizeof
(
char
*
)
*
(
input
->
textSize
-
1
));
Uint16
*
cache
;
cache
=
(
Uint16
*
)
malloc
(
sizeof
(
Uint16
)
*
(
input
->
textSize
-
1
));
for
(
i
=
0
;
i
<
input
->
textSize
-
2
;
i
++
){
cache
[
i
]
=
input
->
text
[
i
];
}
...
...
@@ -121,12 +67,13 @@ void renderNewText(Input* input,TTF_Font* font){/*Létrehozza a modosított kép
SDL_Surface
*
cache
;
SDL_Color
c
=
{
0
,
0
,
0
,
255
};
SDL_FreeSurface
(
input
->
textS
);
input
->
textS
=
TTF_Render
Text
_Solid
(
font
,
input
->
text
,
c
);
input
->
textS
=
TTF_Render
UNICODE
_Solid
(
font
,
input
->
text
,
c
);
}
void
setInputEvents
(
Input
*
input
,
SDL_Event
*
evt
,
TTF_Font
*
font
,
int
flag
){
/*Beállítja az eseményeket*/
int
succes
=
0
;
SDL_EnableUNICODE
(
1
);
switch
(
evt
->
type
){
case
SDL_MOUSEBUTTONDOWN
:
setInputActive
(
input
,
evt
);
...
...
@@ -134,26 +81,24 @@ void setInputEvents(Input* input,SDL_Event* evt,TTF_Font* font,int flag){/*Beál
case
SDL_KEYDOWN
:
/*Ha volt billentyű nyomás és aktiv a bevitelimező akkor keres*/
if
(
input
->
isActive
==
1
){
/*Ha nem backspace nyomunk akkor meg keresi a karakter*/
if
(
evt
->
key
.
keysym
.
sym
!=
SDLK_BACKSPACE
){
/*Ha csak számokat lehet bevinni vagy ha számokat és betűket*/
if
(
flag
==
INPUT_NUM
||
flag
==
INPUT_ALL
){
succes
=
addNewElement
(
input
,
evt
,
number
,
NUMBERS
+
1
);
}
/*Ha számok között talált akkor nem keres a betűk közöt vagy ha csak számokat leheet bevinni*/
if
((
flag
==
INPUT_ABC
||
flag
==
INPUT_ALL
)
&&
succes
==-
1
){
succes
=
addNewElement
(
input
,
evt
,
abc
,
ABC
);
}
/*Ha nem talált akkor nem csinál feleslegesen új képet*/
if
(
succes
!=-
1
)
renderNewText
(
input
,
font
);
}
/*ha backspace-t nyomtunk akkor töröl ha szöveg mérete nem 0*/
else
{
switch
(
evt
->
key
.
keysym
.
unicode
){
case
0x0000
:
/*Nincs megfelelő karaktere*/
break
;
case
'\r'
:
case
'\n'
:
input
->
isActive
=
0
;
break
;
case
'\b'
:
if
(
input
->
textSize
!=
1
){
deleteAElement
(
input
);
renderNewText
(
input
,
font
);
}
break
;
default:
addNewElement
(
input
,
evt
->
key
.
keysym
.
unicode
);
renderNewText
(
input
,
font
);
break
;
}
}
break
;
...
...
This diff is collapsed.
Click to expand it.
input.h
+
1
−
1
View file @
025a929f
...
...
@@ -11,7 +11,7 @@
typedef
struct
{
SDL_Surface
*
bg
;
SDL_Surface
*
textS
;
char
*
text
;
Uint16
*
text
;
int
textSize
;
SDL_Rect
rect
;
int
isActive
;
...
...
This diff is collapsed.
Click to expand it.
main.c
+
4
−
4
View file @
025a929f
...
...
@@ -58,10 +58,10 @@ int main()
setButton
(
&
btn
[
2
],
highScore
,
m_images
[
1
],
font
,
"HighScore"
);
setButton
(
&
btn
[
3
],
exitGame
,
m_images
[
1
],
font
,
"Exit"
);
//
setInput(&inp,m_images[1],inp1);
setInput
(
&
inp
,
m_images
[
1
],
inp1
);
//SDL_SetColorKey(m_images[0],SDL_SRCCOLORKEY,SDL_MapRGB(m_images[0]->format,0,0,255));
//SDL_SetColor
túlélő
Key(m_images[0],SDL_SRCCOLORKEY,SDL_MapRGB(m_images[0]->format,0,0,255));
while
(
btn
[
3
].
leftButtonClicked
!=
1
){
SDL_WaitEvent
(
&
evt
);
/*Eseményre vát*/
SDL_BlitSurface
(
m_images
[
0
],
NULL
,
screen
,
NULL
);
/*Háttér*/
...
...
@@ -72,7 +72,7 @@ int main()
drawButton
(
screen
,
&
evt
,
btn
[
1
]);
drawButton
(
screen
,
&
evt
,
btn
[
2
]);
drawButton
(
screen
,
&
evt
,
btn
[
3
]);
//
drawInput(screen,&inp);
drawInput
(
screen
,
&
inp
);
/*Gomb eseményei*/
...
...
@@ -81,7 +81,7 @@ int main()
setButtonEvents
(
&
btn
[
2
],
&
evt
);
setButtonEvents
(
&
btn
[
3
],
&
evt
);
//
setInputEvents(&inp,&evt,font,INPUT_ALL);
setInputEvents
(
&
inp
,
&
evt
,
font
,
INPUT_ALL
);
sprintf
(
debug
,
"%d"
,
btn
[
0
].
leftButtonClicked
);
SDL_BlitSurface
(
TTF_RenderUTF8_Solid
(
font
,
debug
,
color
),
NULL
,
screen
,
NULL
);
...
...
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