Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
cae6f137
Commit
cae6f137
authored
Jul 25, 2010
by
dewyatt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly draw cursor based on position.
Had to add UTF-8 functions utf8_length, utf8_next, utf8_advance.
parent
1d79a9b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
2 deletions
+56
-2
testime.c
test/testime.c
+56
-2
No files found.
test/testime.c
View file @
cae6f137
...
...
@@ -26,6 +26,48 @@ SDL_Rect textRect, markedRect;
Uint32
lineColor
,
backColor
;
SDL_Color
textColor
=
{
0
,
0
,
0
};
char
text
[
MAX_TEXT_LENGTH
],
markedText
[
SDL_TEXTEDITINGEVENT_TEXT_SIZE
];
int
cursor
=
0
;
size_t
utf8_length
(
unsigned
char
c
)
{
c
=
(
unsigned
char
)(
0xff
&
c
);
if
(
c
<
0x80
)
return
1
;
else
if
((
c
>>
5
)
==
0x6
)
return
2
;
else
if
((
c
>>
4
)
==
0xe
)
return
3
;
else
if
((
c
>>
3
)
==
0x1e
)
return
4
;
else
return
0
;
}
char
*
utf8_next
(
char
*
p
)
{
size_t
len
=
utf8_length
(
*
p
);
size_t
i
=
0
;
if
(
!
len
)
return
0
;
for
(;
i
<
len
;
++
i
)
{
++
p
;
if
(
!*
p
)
return
0
;
}
return
p
;
}
char
*
utf8_advance
(
char
*
p
,
size_t
distance
)
{
size_t
i
=
0
;
for
(;
i
<
distance
&&
p
;
++
i
)
{
p
=
utf8_next
(
p
);
}
return
p
;
}
void
usage
()
{
...
...
@@ -181,6 +223,19 @@ void Redraw()
if
(
markedText
[
0
])
{
#ifdef HAVE_SDL_TTF
if
(
cursor
)
{
char
*
p
=
utf8_advance
(
markedText
,
cursor
);
char
c
=
0
;
if
(
!
p
)
p
=
&
markedText
[
strlen
(
markedText
)];
c
=
*
p
;
*
p
=
0
;
TTF_SizeUTF8
(
font
,
markedText
,
&
w
,
0
);
cursorRect
.
x
+=
w
;
*
p
=
c
;
}
RenderText
(
screen
,
font
,
markedText
,
markedRect
.
x
,
markedRect
.
y
,
textColor
);
TTF_SizeUTF8
(
font
,
markedText
,
&
w
,
&
h
);
#endif
...
...
@@ -190,8 +245,6 @@ void Redraw()
underlineRect
.
h
=
2
;
underlineRect
.
w
=
w
;
cursorRect
.
x
+=
w
+
1
;
SDL_FillRect
(
screen
,
&
underlineRect
,
lineColor
);
}
...
...
@@ -308,6 +361,7 @@ int main(int argc, char *argv[])
event
.
edit
.
text
,
event
.
edit
.
start
,
event
.
edit
.
length
);
strcpy
(
markedText
,
event
.
edit
.
text
);
cursor
=
event
.
edit
.
start
;
Redraw
();
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment