Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Astro
rust-card10
Commits
0988fe2e
Commit
0988fe2e
authored
Oct 05, 2019
by
Astro
⚙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
l0dable, rkanoid: update display coordinate types everywhere else
parent
d2bca3b8
Pipeline
#4120
passed with stage
in 9 minutes and 27 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
19 deletions
+19
-19
card10-l0dable/src/display.rs
card10-l0dable/src/display.rs
+4
-4
card10-l0dable/src/framebuffer/mod.rs
card10-l0dable/src/framebuffer/mod.rs
+5
-5
card10-l0dable/src/framebuffer/text.rs
card10-l0dable/src/framebuffer/text.rs
+2
-2
rkanoid/src/main.rs
rkanoid/src/main.rs
+8
-8
No files found.
card10-l0dable/src/display.rs
View file @
0988fe2e
...
...
@@ -86,10 +86,10 @@ pub enum Font {
/// Immediate mode routines
impl
Display
{
pub
const
W
:
u
16
=
160
;
pub
const
H
:
u
16
=
80
;
pub
const
FONT_W
:
u
16
=
14
;
pub
const
FONT_H
:
u
16
=
20
;
pub
const
W
:
i
16
=
160
;
pub
const
H
:
i
16
=
80
;
pub
const
FONT_W
:
i
16
=
14
;
pub
const
FONT_H
:
i
16
=
20
;
/// Open the display, return an instance
pub
fn
open
()
->
Self
{
...
...
card10-l0dable/src/framebuffer/mod.rs
View file @
0988fe2e
...
...
@@ -61,16 +61,16 @@ impl<'d> FrameBuffer<'d> {
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
);
let
x
=
usize
::
from
(
Display
::
W
as
u16
-
1
-
x
);
let
y
=
usize
::
from
(
Display
::
H
as
u16
-
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
);
let
x
=
usize
::
from
(
Display
::
W
as
u16
-
1
-
x
);
let
y
=
usize
::
from
(
Display
::
H
as
u16
-
1
-
y
);
unsafe
{
transmute
(
&
mut
self
.buffer.fb
[
y
][
x
])
}
}
}
...
...
@@ -85,7 +85,7 @@ impl<'d, C: PixelColor + Into<RawColor>> Drawing<C> for FrameBuffer<'d> {
let
x
=
coord
[
0
]
as
u16
;
let
y
=
coord
[
1
]
as
u16
;
if
x
>=
Display
::
W
||
y
>=
Display
::
H
{
if
x
>=
Display
::
W
as
u16
||
y
>=
Display
::
H
as
u16
{
continue
;
}
// Swap bytes
...
...
card10-l0dable/src/framebuffer/text.rs
View file @
0988fe2e
...
...
@@ -24,10 +24,10 @@ impl<'a, 'd, 'f> Write for TextRenderer<'a, 'd, 'f> {
Some
(
glyph
)
=>
{
for
y
in
0
..
self
.font.h
{
let
y1
=
(
self
.y
+
y
as
isize
)
as
u16
;
if
y1
<
Display
::
H
{
if
y1
<
Display
::
H
as
u16
{
for
x
in
0
..
self
.font.w
{
let
x1
=
(
self
.x
+
x
as
isize
)
as
u16
;
if
x1
<
Display
::
W
{
if
x1
<
Display
::
W
as
u16
{
if
glyph
.get_pixel
(
x
as
usize
,
y
as
usize
)
{
self
.framebuffer
[(
x1
,
y1
)]
=
self
.color
;
}
...
...
rkanoid/src/main.rs
View file @
0988fe2e
...
...
@@ -184,7 +184,7 @@ fn game(level: u16, mut score: u32) -> GameResult {
let
mut
blocks
=
Blocks
::
generate
((
0x3F
+
0x10
*
level
)
.min
(
0xff
)
as
u8
);
// Clear screen
draw_rect
(
&
mut
fb
,
0
,
0
,
Display
::
W
-
1
,
Display
::
H
-
1
,
RawColor
::
black
());
draw_rect
(
&
mut
fb
,
0
,
0
,
Display
::
W
as
u16
-
1
,
Display
::
H
as
u16
-
1
,
RawColor
::
black
());
// Draw Blocks
for
(
lineno
,
line
)
in
blocks
.blocks
.iter_mut
()
.enumerate
()
{
let
lineno
=
lineno
as
u32
;
...
...
@@ -299,11 +299,11 @@ fn game(level: u16, mut score: u32) -> GameResult {
}
// Space below blocks
draw_rect
(
&
mut
fb
,
0
,
(
BLOCK_H
*
BLOCKS_Y
)
as
u16
,
Display
::
W
,
Display
::
H
,
RawColor
::
black
());
Display
::
W
as
u16
,
Display
::
H
as
u16
,
RawColor
::
black
());
// Paddle
draw_rect
(
&
mut
fb
,
(
paddle
-
paddle_size
)
as
u16
,
Display
::
H
-
PADDLE_HEIGHT
as
u16
,
(
paddle
+
paddle_size
)
as
u16
,
Display
::
H
-
1
,
(
paddle
-
paddle_size
)
as
u16
,
Display
::
H
as
u16
-
PADDLE_HEIGHT
as
u16
,
(
paddle
+
paddle_size
)
as
u16
,
Display
::
H
as
u16
-
1
,
RawColor
::
rgb8
(
0x7f
,
0xff
,
0x7f
));
// Ball
fb
.draw
(
...
...
@@ -412,10 +412,10 @@ fn main() {
}
fn
draw_rect
(
fb
:
&
mut
FrameBuffer
,
x1
:
u16
,
y1
:
u16
,
x2
:
u16
,
y2
:
u16
,
color
:
RawColor
)
{
let
x1
=
x1
.max
(
0
)
.min
(
Display
::
W
-
1
);
let
x2
=
x2
.max
(
0
)
.min
(
Display
::
W
-
1
);
let
y1
=
y1
.max
(
0
)
.min
(
Display
::
H
-
1
);
let
y2
=
y2
.max
(
0
)
.min
(
Display
::
H
-
1
);
let
x1
=
x1
.max
(
0
)
.min
(
Display
::
W
as
u16
-
1
);
let
x2
=
x2
.max
(
0
)
.min
(
Display
::
W
as
u16
-
1
);
let
y1
=
y1
.max
(
0
)
.min
(
Display
::
H
as
u16
-
1
);
let
y2
=
y2
.max
(
0
)
.min
(
Display
::
H
as
u16
-
1
);
for
y
in
y1
..=
y2
{
for
x
in
x1
..=
x2
{
fb
[(
x
,
y
)]
=
color
;
...
...
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