Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Astro
rust-card10
Commits
059ae059
Commit
059ae059
authored
Aug 24, 2019
by
Astro
⚙
Browse files
l0dable: spin framebuffer, add RawColor
parent
29a6b351
Changes
2
Show whitespace changes
Inline
Side-by-side
l0dable/src/framebuffer/mod.rs
View file @
059ae059
use
core
::
mem
::{
transmute
,
uninitialized
};
use
core
::
ops
::{
Deref
,
Deref
Mut
};
use
core
::
ops
::{
Index
,
Index
Mut
};
use
crate
::
bindings
::
*
;
use
crate
::
{
Color
,
Display
}
;
use
crate
::
Display
;
mod
font
;
pub
use
font
::
*
;
...
...
@@ -30,7 +30,7 @@ impl<'d> FrameBuffer<'d> {
}
}
pub
fn
text
<
'a
,
'f
>
(
&
'a
mut
self
,
x
:
isize
,
y
:
isize
,
font
:
&
'f
Font
,
color
:
Color
)
->
TextRenderer
<
'a
,
'd
,
'f
>
{
pub
fn
text
<
'a
,
'f
>
(
&
'a
mut
self
,
x
:
isize
,
y
:
isize
,
font
:
&
'f
Font
,
color
:
Raw
Color
)
->
TextRenderer
<
'a
,
'd
,
'f
>
{
TextRenderer
{
framebuffer
:
self
,
x
,
y
,
font
,
color
,
...
...
@@ -38,15 +38,59 @@ impl<'d> FrameBuffer<'d> {
}
}
impl
<
'd
>
Deref
for
FrameBuffer
<
'd
>
{
type
Target
=
[[
Color
;
Display
::
W
as
usize
];
Display
::
H
as
usize
];
fn
deref
(
&
self
)
->
&
Self
::
Target
{
unsafe
{
transmute
(
&
self
.buffer.raw
)
}
impl
<
'd
>
Index
<
(
u16
,
u16
)
>
for
FrameBuffer
<
'd
>
{
type
Output
=
RawColor
;
fn
index
(
&
self
,
(
x
,
y
):
(
u16
,
u16
))
->
&
Self
::
Output
{
let
x
=
usize
::
from
(
Display
::
W
-
1
-
x
);
let
y
=
usize
::
from
(
Display
::
H
-
1
-
y
);
unsafe
{
transmute
(
&
self
.buffer.fb
[
y
][
x
])
}
}
}
impl
<
'd
>
IndexMut
<
(
u16
,
u16
)
>
for
FrameBuffer
<
'd
>
{
fn
index_mut
(
&
mut
self
,
(
x
,
y
):
(
u16
,
u16
))
->
&
mut
Self
::
Output
{
let
x
=
usize
::
from
(
Display
::
W
-
1
-
x
);
let
y
=
usize
::
from
(
Display
::
H
-
1
-
y
);
unsafe
{
transmute
(
&
mut
self
.buffer.fb
[
y
][
x
])
}
}
}
impl
<
'd
>
DerefMut
for
FrameBuffer
<
'd
>
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
Self
::
Target
{
unsafe
{
transmute
(
&
mut
self
.buffer.raw
)
}
#[derive(Debug,
Clone,
Copy)]
#[repr(C)]
pub
struct
RawColor
([
u8
;
2
]);
impl
RawColor
{
pub
fn
red
()
->
Self
{
Self
::
rgb8
(
0xff
,
0
,
0
)
}
pub
fn
blue
()
->
Self
{
Self
::
rgb8
(
0
,
0
,
0xff
)
}
pub
fn
green
()
->
Self
{
Self
::
rgb8
(
0
,
0xff
,
0
)
}
pub
fn
black
()
->
Self
{
Self
::
rgb8
(
0
,
0
,
0
)
}
pub
fn
white
()
->
Self
{
Self
::
rgb8
(
0xff
,
0xff
,
0xff
)
}
pub
fn
yellow
()
->
Self
{
Self
::
rgb8
(
0xff
,
0xff
,
0
)
}
pub
fn
rgb8
(
r8
:
u8
,
g8
:
u8
,
b8
:
u8
)
->
Self
{
let
b1
=
(
r8
&
0xF8
)
|
(
g8
>>
5
);
let
b2
=
((
g8
&
0xFA
)
<<
3
)
|
(
b8
>>
3
);
RawColor
([
b1
,
b2
])
}
}
l0dable/src/framebuffer/text.rs
View file @
059ae059
use
core
::
fmt
::
Write
;
use
super
::{
FrameBuffer
,
Font
};
use
crate
::{
Color
,
Display
};
use
super
::{
FrameBuffer
,
Font
,
RawColor
};
use
crate
::{
Display
};
pub
struct
TextRenderer
<
'a
,
'd
,
'f
>
{
pub
framebuffer
:
&
'a
mut
FrameBuffer
<
'd
>
,
pub
x
:
isize
,
pub
y
:
isize
,
pub
font
:
&
'f
Font
,
pub
color
:
Color
,
pub
color
:
Raw
Color
,
}
impl
<
'a
,
'd
,
'f
>
Write
for
TextRenderer
<
'a
,
'd
,
'f
>
{
...
...
@@ -23,13 +23,13 @@ impl<'a, 'd, 'f> Write for TextRenderer<'a, 'd, 'f> {
None
=>
Ok
(()),
Some
(
glyph
)
=>
{
for
y
in
0
..
self
.font.h
{
let
y1
=
self
.y
+
y
as
isize
;
if
y1
>=
0
&&
y1
<
Display
::
H
as
isize
{
let
y1
=
(
self
.y
+
y
as
isize
)
as
u16
;
if
y1
<
Display
::
H
{
for
x
in
0
..
self
.font.w
{
let
x1
=
self
.x
+
x
as
isize
;
if
x1
>=
0
&&
x1
<
Display
::
W
as
isize
{
let
x1
=
(
self
.x
+
x
as
isize
)
as
u16
;
if
x1
<
Display
::
W
{
if
glyph
.get_pixel
(
x
as
usize
,
y
as
usize
)
{
self
.framebuffer
[
y1
as
usize
][
x1
as
usize
]
=
self
.color
;
self
.framebuffer
[
(
x1
,
y1
)
]
=
self
.color
;
}
}
}
...
...
Write
Preview
Supports
Markdown
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