Beginning of sudoku chapter 7 with SDM loading
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
//! Gameboard view.
|
||||
|
||||
use graphics::character::CharacterCache;
|
||||
use graphics::types::Color;
|
||||
use graphics::{Context, Graphics};
|
||||
|
||||
@@ -17,6 +18,7 @@ pub struct GameboardViewSettings {
|
||||
pub section_edge_radius: f64,
|
||||
pub cell_edge_radius: f64,
|
||||
pub selected_cell_background_color: Color,
|
||||
pub text_color: Color,
|
||||
}
|
||||
|
||||
impl GameboardViewSettings {
|
||||
@@ -33,6 +35,7 @@ impl GameboardViewSettings {
|
||||
section_edge_radius: 2.0,
|
||||
cell_edge_radius: 1.0,
|
||||
selected_cell_background_color: [0.9, 0.9, 1.0, 1.0],
|
||||
text_color: [0.0, 0.0, 0.1, 1.0],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,8 +49,16 @@ impl GameboardView {
|
||||
GameboardView { settings: settings }
|
||||
}
|
||||
|
||||
pub fn draw<G: Graphics>(&self, controller: &GameboardController, c: &Context, g: &mut G) {
|
||||
use graphics::{Line, Rectangle};
|
||||
pub fn draw<G: Graphics, C>(
|
||||
&self,
|
||||
controller: &GameboardController,
|
||||
glyphs: &mut C,
|
||||
c: &Context,
|
||||
g: &mut G,
|
||||
) where
|
||||
C: CharacterCache<Texture = G::Texture>,
|
||||
{
|
||||
use graphics::{Image, Line, Rectangle, Transformed};
|
||||
|
||||
let ref settings = self.settings;
|
||||
let board_rect = [
|
||||
@@ -76,6 +87,37 @@ impl GameboardView {
|
||||
);
|
||||
}
|
||||
|
||||
let text_image = Image::new_color(settings.text_color);
|
||||
let cell_size = settings.size / 9.0;
|
||||
|
||||
for j in 0..9 {
|
||||
for i in 0..9 {
|
||||
if let Some(ch) = controller.gameboard.char([i, j]) {
|
||||
let pos = [
|
||||
settings.position[0] + i as f64 * cell_size + 15.0,
|
||||
settings.position[1] + j as f64 * cell_size + 34.0,
|
||||
];
|
||||
|
||||
if let Ok(character) = glyphs.character(34, ch) {
|
||||
let ch_x = pos[0] + character.left();
|
||||
let ch_y = pos[1] - character.top();
|
||||
let text_image = text_image.src_rect([
|
||||
character.atlas_offset[0],
|
||||
character.atlas_offset[1],
|
||||
character.atlas_size[0],
|
||||
character.atlas_size[1],
|
||||
]);
|
||||
text_image.draw(
|
||||
character.texture,
|
||||
&c.draw_state,
|
||||
c.transform.trans(ch_x, ch_y),
|
||||
g,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let cell_edge = Line::new(settings.cell_edge_color, settings.cell_edge_radius);
|
||||
let section_edge = Line::new(settings.section_edge_color, settings.section_edge_radius);
|
||||
|
||||
|
Reference in New Issue
Block a user