Skip to content

Commit 8eb26da

Browse files
committed
use ToColor trait
1 parent 1328100 commit 8eb26da

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/sdl2_ttf/lib.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::c_str::CString;
1818
use std::num::FromPrimitive;
1919
use sdl2::surface::Surface;
2020
use sdl2::get_error;
21-
use sdl2::pixels::Color;
21+
use sdl2::pixels::ToColor;
2222
use sdl2::rwops::RWops;
2323
use sdl2::version::Version;
2424

@@ -336,11 +336,11 @@ impl Font {
336336
}
337337
}
338338

339-
pub fn render_bytes_solid(&self, text: &[u8], fg: Color) -> Result<~Surface, ~str> {
339+
pub fn render_bytes_solid<C: ToColor>(&self, text: &[u8], fg: C) -> Result<~Surface, ~str> {
340340
//! Draw LATIN1 text in solid mode.
341341
unsafe {
342342
let raw = text.with_c_str(|ctext| {
343-
ffi::TTF_RenderText_Solid(self.raw, ctext, fg)
343+
ffi::TTF_RenderText_Solid(self.raw, ctext, fg.to_color())
344344
});
345345
if raw.is_null() {
346346
Err(get_error())
@@ -350,11 +350,11 @@ impl Font {
350350
}
351351
}
352352

353-
pub fn render_str_solid(&self, text: &str, fg: Color) -> Result<~Surface, ~str> {
353+
pub fn render_str_solid<C: ToColor>(&self, text: &str, fg: C) -> Result<~Surface, ~str> {
354354
//! Draw UTF8 text in solid mode.
355355
unsafe {
356356
let raw = text.with_c_str(|ctext| {
357-
ffi::TTF_RenderUTF8_Solid(self.raw, ctext, fg)
357+
ffi::TTF_RenderUTF8_Solid(self.raw, ctext, fg.to_color())
358358
});
359359
if raw.is_null() {
360360
Err(get_error())
@@ -364,10 +364,10 @@ impl Font {
364364
}
365365
}
366366

367-
pub fn render_char_solid(&self, ch: char, fg: Color) -> Result<~Surface, ~str> {
367+
pub fn render_char_solid<C: ToColor>(&self, ch: char, fg: C) -> Result<~Surface, ~str> {
368368
//! Draw a UNICODE glyph in solid mode.
369369
unsafe {
370-
let raw = ffi::TTF_RenderGlyph_Solid(self.raw, ch as u16, fg);
370+
let raw = ffi::TTF_RenderGlyph_Solid(self.raw, ch as u16, fg.to_color());
371371
if raw.is_null() {
372372
Err(get_error())
373373
} else {
@@ -376,11 +376,11 @@ impl Font {
376376
}
377377
}
378378

379-
pub fn render_bytes_shaded(&self, text: &[u8], fg: Color, bg: Color) -> Result<~Surface, ~str> {
379+
pub fn render_bytes_shaded<C: ToColor>(&self, text: &[u8], fg: C, bg: C) -> Result<~Surface, ~str> {
380380
//! Draw LATIN1 text in shaded mode.
381381
unsafe {
382382
let raw = text.with_c_str(|ctext| {
383-
ffi::TTF_RenderText_Shaded(self.raw, ctext, fg, bg)
383+
ffi::TTF_RenderText_Shaded(self.raw, ctext, fg.to_color(), bg.to_color())
384384
});
385385
if raw.is_null() {
386386
Err(get_error())
@@ -390,11 +390,11 @@ impl Font {
390390
}
391391
}
392392

393-
pub fn render_str_shaded(&self, text: &str, fg: Color, bg: Color) -> Result<~Surface, ~str> {
393+
pub fn render_str_shaded<C: ToColor>(&self, text: &str, fg: C, bg: C) -> Result<~Surface, ~str> {
394394
//! Draw UTF8 text in shaded mode.
395395
unsafe {
396396
let raw = text.with_c_str(|ctext| {
397-
ffi::TTF_RenderUTF8_Shaded(self.raw, ctext, fg, bg)
397+
ffi::TTF_RenderUTF8_Shaded(self.raw, ctext, fg.to_color(), bg.to_color())
398398
});
399399
if raw.is_null() {
400400
Err(get_error())
@@ -404,10 +404,10 @@ impl Font {
404404
}
405405
}
406406

407-
pub fn render_char_shaded(&self, ch: char, fg: Color, bg: Color) -> Result<~Surface, ~str> {
407+
pub fn render_char_shaded<C: ToColor>(&self, ch: char, fg: C, bg: C) -> Result<~Surface, ~str> {
408408
//! Draw a UNICODE glyph in shaded mode.
409409
unsafe {
410-
let raw = ffi::TTF_RenderGlyph_Shaded(self.raw, ch as u16, fg, bg);
410+
let raw = ffi::TTF_RenderGlyph_Shaded(self.raw, ch as u16, fg.to_color(), bg.to_color());
411411
if raw.is_null() {
412412
Err(get_error())
413413
} else {
@@ -416,11 +416,11 @@ impl Font {
416416
}
417417
}
418418

419-
pub fn render_bytes_blended(&self, text: &[u8], fg: Color) -> Result<~Surface, ~str> {
419+
pub fn render_bytes_blended<C: ToColor>(&self, text: &[u8], fg: C) -> Result<~Surface, ~str> {
420420
//! Draw LATIN1 text in blended mode.
421421
unsafe {
422422
let raw = text.with_c_str(|ctext| {
423-
ffi::TTF_RenderText_Blended(self.raw, ctext, fg)
423+
ffi::TTF_RenderText_Blended(self.raw, ctext, fg.to_color())
424424
});
425425
if raw.is_null() {
426426
Err(get_error())
@@ -430,11 +430,11 @@ impl Font {
430430
}
431431
}
432432

433-
pub fn render_str_blended(&self, text: &str, fg: Color) -> Result<~Surface, ~str> {
433+
pub fn render_str_blended<C: ToColor>(&self, text: &str, fg: C) -> Result<~Surface, ~str> {
434434
//! Draw UTF8 text in blended mode.
435435
unsafe {
436436
let raw = text.with_c_str(|ctext| {
437-
ffi::TTF_RenderUTF8_Blended(self.raw, ctext, fg)
437+
ffi::TTF_RenderUTF8_Blended(self.raw, ctext, fg.to_color())
438438
});
439439
if raw.is_null() {
440440
Err(get_error())
@@ -444,10 +444,10 @@ impl Font {
444444
}
445445
}
446446

447-
pub fn render_char_blended(&self, ch: char, fg: Color) -> Result<~Surface, ~str> {
447+
pub fn render_char_blended<C: ToColor>(&self, ch: char, fg: C) -> Result<~Surface, ~str> {
448448
//! Draw a UNICODE glyph in blended mode.
449449
unsafe {
450-
let raw = ffi::TTF_RenderGlyph_Blended(self.raw, ch as u16, fg);
450+
let raw = ffi::TTF_RenderGlyph_Blended(self.raw, ch as u16, fg.to_color());
451451
if raw.is_null() {
452452
Err(get_error())
453453
} else {

0 commit comments

Comments
 (0)