Skip to content

Commit cb2ba14

Browse files
authored
Merge pull request #3 from firefly-zero/16-colors
16 colors
2 parents c2a53a6 + 02bb0c7 commit cb2ba14

File tree

7 files changed

+58
-94
lines changed

7 files changed

+58
-94
lines changed

examples/image/image.png

16 Bytes
Loading

examples/image/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ extern fn boot() {
2222

2323
#[no_mangle]
2424
extern fn update() {
25-
ff::clear_screen(ff::Color::Light);
25+
ff::clear_screen(ff::Color::White);
2626
let image = unsafe { IMAGE.get().unwrap() };
2727
let image: ff::Image = (image).into();
28-
let colors = ff::ImageColors::default();
29-
ff::draw_image(&image, ff::Point { x: 60, y: 60 }, &colors);
28+
ff::draw_image(&image, ff::Point { x: 60, y: 60 });
3029
}

examples/triangle/firefly.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ author_id = "demo"
22
app_id = "rust-triangle"
33
author_name = "Demo"
44
app_name = "Triangle Demo (Rust)"
5+
compile_args = ["--no-default-features"]

examples/triangle/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use firefly_rust as ff;
44

55
#[no_mangle]
66
extern fn boot() {
7+
ff::clear_screen(ff::Color::White);
78
ff::draw_triangle(
89
ff::Point { x: 60, y: 10 },
910
ff::Point { x: 40, y: 40 },
1011
ff::Point { x: 80, y: 40 },
1112
ff::Style {
12-
fill_color: ff::Color::Accent,
13-
stroke_color: ff::Color::Secondary,
13+
fill_color: ff::Color::LightGray,
14+
stroke_color: ff::Color::DarkBlue,
1415
stroke_width: 1,
1516
},
1617
);

src/graphics/bindings.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,6 @@ extern {
111111
sub_y: i32,
112112
sub_width: i32,
113113
sub_height: i32,
114-
c1: i32,
115-
c2: i32,
116-
c3: i32,
117-
c4: i32,
118-
);
119-
pub(crate) fn draw_image(
120-
ptr: u32,
121-
len: u32,
122-
x: i32,
123-
y: i32,
124-
c1: i32,
125-
c2: i32,
126-
c3: i32,
127-
c4: i32,
128114
);
115+
pub(crate) fn draw_image(ptr: u32, len: u32, x: i32, y: i32);
129116
}

src/graphics/funcs.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,27 +184,18 @@ pub fn draw_text(t: &str, f: &Font, p: Point, c: Color) {
184184
}
185185

186186
/// Render an image using the given colors.
187-
pub fn draw_image(i: &Image, p: Point, c: &ImageColors) {
187+
pub fn draw_image(i: &Image, p: Point) {
188188
let ptr = i.raw.as_ptr();
189189
let len = i.raw.len();
190190
unsafe {
191-
b::draw_image(
192-
ptr as u32,
193-
len as u32,
194-
p.x,
195-
p.y,
196-
c.a.into(),
197-
c.b.into(),
198-
c.c.into(),
199-
c.d.into(),
200-
);
191+
b::draw_image(ptr as u32, len as u32, p.x, p.y);
201192
}
202193
}
203194

204195
/// Draw a subregion of an image.
205196
///
206197
/// Most often used to draw a sprite from a sprite atlas.
207-
pub fn draw_sub_image(i: &SubImage, p: Point, c: &ImageColors) {
198+
pub fn draw_sub_image(i: &SubImage, p: Point) {
208199
let ptr = i.raw.as_ptr();
209200
let len = i.raw.len();
210201
unsafe {
@@ -217,10 +208,6 @@ pub fn draw_sub_image(i: &SubImage, p: Point, c: &ImageColors) {
217208
i.point.y,
218209
i.size.width,
219210
i.size.height,
220-
c.a.into(),
221-
c.b.into(),
222-
c.c.into(),
223-
c.d.into(),
224211
);
225212
}
226213
}

src/graphics/types.rs

Lines changed: 48 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,23 @@ impl From<Style> for LineStyle {
6363
/// A pointer to a color in the color palette.
6464
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
6565
pub enum Color {
66-
/// No color (100% transparency).
6766
None,
68-
/// The first color in the palette. Typically, the darkest color.
69-
Dark,
70-
/// The second color in the palette.
71-
Accent,
72-
/// The third color in the palette.
73-
Secondary,
74-
/// The last color in the palette. Typically, the brightest, almost white, color.
75-
Light,
67+
Black,
68+
Purple,
69+
Red,
70+
Orange,
71+
Yellow,
72+
LightGreen,
73+
Green,
74+
DarkGreen,
75+
DarkBlue,
76+
Blue,
77+
LightBlue,
78+
Cyan,
79+
White,
80+
LightGray,
81+
Gray,
82+
DarkGray,
7683
}
7784

7885
impl Default for Color {
@@ -87,10 +94,22 @@ impl TryFrom<usize> for Color {
8794
fn try_from(value: usize) -> Result<Self, Self::Error> {
8895
match value {
8996
0 => Ok(Color::None),
90-
1 => Ok(Color::Dark),
91-
2 => Ok(Color::Accent),
92-
3 => Ok(Color::Secondary),
93-
4 => Ok(Color::Light),
97+
1 => Ok(Color::Black),
98+
2 => Ok(Color::Purple),
99+
3 => Ok(Color::Red),
100+
4 => Ok(Color::Orange),
101+
5 => Ok(Color::Yellow),
102+
6 => Ok(Color::LightGreen),
103+
7 => Ok(Color::Green),
104+
8 => Ok(Color::DarkGreen),
105+
9 => Ok(Color::DarkBlue),
106+
10 => Ok(Color::Blue),
107+
11 => Ok(Color::LightBlue),
108+
12 => Ok(Color::Cyan),
109+
13 => Ok(Color::White),
110+
14 => Ok(Color::LightGray),
111+
15 => Ok(Color::Gray),
112+
16 => Ok(Color::DarkGray),
94113
_ => Err(()),
95114
}
96115
}
@@ -100,52 +119,22 @@ impl From<Color> for i32 {
100119
fn from(value: Color) -> Self {
101120
match value {
102121
Color::None => 0,
103-
Color::Dark => 1,
104-
Color::Accent => 2,
105-
Color::Secondary => 3,
106-
Color::Light => 4,
107-
}
108-
}
109-
}
110-
111-
/// A mapping of colors in the image to the color palette.
112-
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
113-
pub struct ImageColors {
114-
pub a: Color,
115-
pub b: Color,
116-
pub c: Color,
117-
pub d: Color,
118-
}
119-
120-
impl Default for ImageColors {
121-
fn default() -> Self {
122-
Self {
123-
a: Color::Dark,
124-
b: Color::Accent,
125-
c: Color::Secondary,
126-
d: Color::Light,
127-
}
128-
}
129-
}
130-
131-
impl From<[Color; 4]> for ImageColors {
132-
fn from(value: [Color; 4]) -> Self {
133-
Self {
134-
a: value[0],
135-
b: value[1],
136-
c: value[2],
137-
d: value[3],
138-
}
139-
}
140-
}
141-
142-
impl From<&[Color; 4]> for ImageColors {
143-
fn from(value: &[Color; 4]) -> Self {
144-
Self {
145-
a: value[0],
146-
b: value[1],
147-
c: value[2],
148-
d: value[3],
122+
Color::Black => 1,
123+
Color::Purple => 2,
124+
Color::Red => 3,
125+
Color::Orange => 4,
126+
Color::Yellow => 5,
127+
Color::LightGreen => 6,
128+
Color::Green => 7,
129+
Color::DarkGreen => 8,
130+
Color::DarkBlue => 9,
131+
Color::Blue => 10,
132+
Color::LightBlue => 11,
133+
Color::Cyan => 12,
134+
Color::White => 13,
135+
Color::LightGray => 14,
136+
Color::Gray => 15,
137+
Color::DarkGray => 16,
149138
}
150139
}
151140
}

0 commit comments

Comments
 (0)