mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-18 10:30:14 +01:00
update to servicepoint 0.4.2
This commit is contained in:
parent
c01264afd7
commit
5fff78506a
10
src/font.rs
10
src/font.rs
|
@ -5,7 +5,7 @@ use font_kit::font::Font;
|
|||
use font_kit::hinting::HintingOptions;
|
||||
use pathfinder_geometry::transform2d::Transform2F;
|
||||
use pathfinder_geometry::vector::{vec2f, vec2i};
|
||||
use servicepoint2::{PixelGrid, TILE_SIZE};
|
||||
use servicepoint2::{Grid, PixelGrid, TILE_SIZE};
|
||||
|
||||
const DEFAULT_FONT_FILE: &[u8] = include_bytes!("../Web437_IBM_BIOS.woff");
|
||||
|
||||
|
@ -16,7 +16,7 @@ pub struct BitmapFont {
|
|||
impl BitmapFont {
|
||||
pub fn load(font: Font) -> BitmapFont {
|
||||
let mut bitmaps = core::array::from_fn(|_| {
|
||||
PixelGrid::new(TILE_SIZE as usize, TILE_SIZE as usize)
|
||||
PixelGrid::new(TILE_SIZE, TILE_SIZE)
|
||||
});
|
||||
|
||||
for char_code in u8::MIN..u8::MAX {
|
||||
|
@ -43,9 +43,9 @@ impl BitmapFont {
|
|||
assert_eq!(canvas.pixels.len(), 64);
|
||||
assert_eq!(canvas.stride, 8);
|
||||
|
||||
for y in 0..TILE_SIZE as usize {
|
||||
for x in 0..TILE_SIZE as usize {
|
||||
let index = x + y * TILE_SIZE as usize;
|
||||
for y in 0..TILE_SIZE {
|
||||
for x in 0..TILE_SIZE {
|
||||
let index = x + y * TILE_SIZE;
|
||||
let canvas_val = canvas.pixels[index] != 0;
|
||||
bitmaps[char_code as usize].set(x, y, canvas_val);
|
||||
}
|
||||
|
|
18
src/gui.rs
18
src/gui.rs
|
@ -4,9 +4,7 @@ use std::sync::RwLock;
|
|||
use log::{info, warn};
|
||||
use pixels::wgpu::TextureFormat;
|
||||
use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
|
||||
use servicepoint2::{
|
||||
ByteGrid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE,
|
||||
};
|
||||
use servicepoint2::{ByteGrid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE, Grid};
|
||||
use winit::application::ApplicationHandler;
|
||||
use winit::dpi::LogicalSize;
|
||||
use winit::event::WindowEvent;
|
||||
|
@ -25,7 +23,7 @@ pub struct App<'t> {
|
|||
cli: &'t Cli,
|
||||
}
|
||||
|
||||
const SPACER_HEIGHT: u16 = 4;
|
||||
const SPACER_HEIGHT: usize = 4;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AppEvents {
|
||||
|
@ -56,18 +54,18 @@ impl<'t> App<'t> {
|
|||
let mut frame = pixels.frame_mut().chunks_exact_mut(4);
|
||||
let display = self.display.read().unwrap();
|
||||
let luma = self.luma.read().unwrap();
|
||||
for y in 0..PIXEL_HEIGHT as usize {
|
||||
if self.cli.spacers && y != 0 && y % TILE_SIZE as usize == 0 {
|
||||
for y in 0..PIXEL_HEIGHT {
|
||||
if self.cli.spacers && y != 0 && y % TILE_SIZE == 0 {
|
||||
// cannot just frame.skip(PIXEL_WIDTH as usize * SPACER_HEIGHT as usize) because of typing
|
||||
for _ in 0..PIXEL_WIDTH as usize * SPACER_HEIGHT as usize {
|
||||
for _ in 0..PIXEL_WIDTH * SPACER_HEIGHT {
|
||||
frame.next().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
for x in 0..PIXEL_WIDTH as usize {
|
||||
for x in 0..PIXEL_WIDTH {
|
||||
let is_set = display.get(x, y);
|
||||
let brightness =
|
||||
luma.get(x / TILE_SIZE as usize, y / TILE_SIZE as usize);
|
||||
luma.get(x / TILE_SIZE, y / TILE_SIZE);
|
||||
|
||||
let color = if is_set {
|
||||
[
|
||||
|
@ -98,7 +96,7 @@ impl ApplicationHandler<AppEvents> for App<'_> {
|
|||
PIXEL_HEIGHT
|
||||
};
|
||||
|
||||
let size = LogicalSize::new(PIXEL_WIDTH, height);
|
||||
let size = LogicalSize::new(PIXEL_WIDTH as u16, height as u16);
|
||||
let attributes = Window::default_attributes()
|
||||
.with_title("servicepoint-simulator")
|
||||
.with_inner_size(size)
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -7,10 +7,7 @@ use std::time::Duration;
|
|||
|
||||
use clap::Parser;
|
||||
use log::{info, warn, LevelFilter};
|
||||
use servicepoint2::{
|
||||
ByteGrid, Command, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_HEIGHT,
|
||||
TILE_WIDTH,
|
||||
};
|
||||
use servicepoint2::{ByteGrid, Command, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_HEIGHT, TILE_WIDTH, Grid};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
|
||||
use crate::execute_command::execute_command;
|
||||
|
@ -53,11 +50,11 @@ fn main() {
|
|||
.expect("could not enter non blocking mode");
|
||||
|
||||
let display = RwLock::new(PixelGrid::new(
|
||||
PIXEL_WIDTH as usize,
|
||||
PIXEL_HEIGHT as usize,
|
||||
PIXEL_WIDTH,
|
||||
PIXEL_HEIGHT,
|
||||
));
|
||||
|
||||
let mut luma = ByteGrid::new(TILE_WIDTH as usize, TILE_HEIGHT as usize);
|
||||
let mut luma = ByteGrid::new(TILE_WIDTH, TILE_HEIGHT);
|
||||
luma.fill(u8::MAX);
|
||||
let luma = RwLock::new(luma);
|
||||
|
||||
|
|
Loading…
Reference in a new issue