Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F626052
lineedit.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
lineedit.cpp
View Options
#include
"util/graphics/bitmap.h"
#include
"util/font.h"
#include
"lineedit.h"
#include
"util/debug.h"
#include
<iostream>
using
namespace
Gui
;
static
Global
::
stream_type
&
debug
(
int
level
){
Global
::
debug
(
level
)
<<
"[line edit] "
;
return
Global
::
debug
(
level
);
}
LineEdit
::
LineEdit
()
:
blinkRate
(
30
),
cursorTime
(
0
),
changed
(
false
){
colors
.
body
=
Graphics
::
makeColor
(
0
,
0
,
60
);
colors
.
border
=
Graphics
::
makeColor
(
0
,
0
,
20
);
colors
.
bodyAlpha
=
colors
.
borderAlpha
=
150
;
textColor
=
Graphics
::
makeColor
(
255
,
255
,
255
);
cursorColor
=
Graphics
::
makeColor
(
128
,
128
,
128
);
transforms
.
setRadius
(
10
);
input
.
enable
();
}
LineEdit
::~
LineEdit
(){
}
void
LineEdit
::
setTextColor
(
const
Graphics
::
Color
color
){
textColor
=
color
;
}
void
LineEdit
::
setCursorColor
(
const
Graphics
::
Color
color
){
cursorColor
=
color
;
}
void
LineEdit
::
act
(
const
Font
&
){
if
(
input
.
doInput
()){
changed
=
true
;
}
else
{
changed
=
false
;
}
cursorTime
++
;
if
(
cursorTime
>
blinkRate
*
2
){
cursorTime
=
0
;
}
}
void
LineEdit
::
draw
(
const
Font
&
font
,
const
Graphics
::
Bitmap
&
work
){
Graphics
::
Bitmap
temp
=
Graphics
::
Bitmap
(
work
,
location
.
getX
(),
location
.
getY
(),
location
.
getWidth
(),
location
.
getHeight
());
drawBox
(
transforms
.
getRadius
(),
0
,
0
,
location
.
getWidth
(),
location
.
getHeight
(),
colors
,
temp
);
const
int
modifier
=
(
temp
.
getWidth
()
*
(
transforms
.
getRadius
()
*
.001
))
==
0
?
2
:
(
temp
.
getWidth
()
*
(
transforms
.
getRadius
()
*
.001
));
Graphics
::
Bitmap
textTemp
=
Graphics
::
Bitmap
(
temp
,
modifier
,
0
,
temp
.
getWidth
()
-
(
modifier
*
2
),
temp
.
getHeight
());
const
int
fontLength
=
font
.
textLength
(
input
.
getText
().
c_str
());
if
(
fontLength
>=
textTemp
.
getWidth
()){
font
.
printf
(
textTemp
.
getWidth
()
-
modifier
-
fontLength
,
0
,
textColor
,
textTemp
,
input
.
getText
(),
0
);
renderCursor
(
textTemp
.
getWidth
()
-
modifier
-
1
,
0
,
font
,
textTemp
);
}
else
{
font
.
printf
(
0
,
0
,
textColor
,
textTemp
,
input
.
getText
(),
0
);
renderCursor
(
fontLength
+
1
,
0
,
font
,
textTemp
);
}
}
void
LineEdit
::
render
(
const
Graphics
::
Bitmap
&
){
}
void
LineEdit
::
toggleEnabled
(){
if
(
input
.
isEnabled
()){
input
.
disable
();
}
else
{
input
.
enable
();
}
}
void
LineEdit
::
setFocused
(
bool
enabled
){
if
(
enabled
){
input
.
enable
();
}
else
{
input
.
disable
();
}
}
void
LineEdit
::
addHook
(
int
key
,
void
(
*
callback
)(
void
*
),
void
*
arg
){
input
.
addBlockingHandle
(
key
,
callback
,
arg
);
}
bool
LineEdit
::
didChanged
(
unsigned
long
long
&
){
return
changed
;
}
void
LineEdit
::
renderCursor
(
int
x
,
int
y
,
const
Font
&
font
,
const
Graphics
::
Bitmap
&
work
){
if
(
cursorTime
<=
blinkRate
){
font
.
printf
(
x
,
y
,
cursorColor
,
work
,
"|"
,
0
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Nov 15, 12:15 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
140302
Default Alt Text
lineedit.cpp (2 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline