diff --git a/kifu/kifu-core/src/lib.rs b/kifu/kifu-core/src/lib.rs index a13d2c8..9c22bc8 100644 --- a/kifu/kifu-core/src/lib.rs +++ b/kifu/kifu-core/src/lib.rs @@ -1,5 +1,3 @@ -use std::time::Duration; - mod api; pub use api::{CoreApp, Request, Response}; diff --git a/kifu/kifu-core/src/ui/playing_field.rs b/kifu/kifu-core/src/ui/playing_field.rs index 7398744..cdc9c12 100644 --- a/kifu/kifu-core/src/ui/playing_field.rs +++ b/kifu/kifu-core/src/ui/playing_field.rs @@ -1,4 +1,4 @@ -use crate::types::{Color, Size}; +use crate::types::Color; use crate::{types::GameState, ui::types}; #[derive(Clone, Debug)] diff --git a/kifu/kifu-gtk/src/main.rs b/kifu/kifu-gtk/src/main.rs index d1ce77d..2ede4f3 100644 --- a/kifu/kifu-gtk/src/main.rs +++ b/kifu/kifu-gtk/src/main.rs @@ -1,15 +1,7 @@ -use gio::resources_lookup_data; use gtk::prelude::*; use kifu_core::{CoreApp, Request, Response}; use kifu_gtk::{ui::PlayingField, CoreApi}; -use std::{ - sync::{Arc, Mutex, RwLock}, - time::Duration, -}; -use tokio::{ - runtime::Runtime, - sync::mpsc::{Receiver, Sender}, -}; +use std::sync::{Arc, RwLock}; fn main() { gio::resources_register_include!("com.luminescent-dreams.kifu-gtk.gresource") diff --git a/kifu/kifu-gtk/src/ui/board.rs b/kifu/kifu-gtk/src/ui/board.rs index de9b561..4ededd6 100644 --- a/kifu/kifu-gtk/src/ui/board.rs +++ b/kifu/kifu-gtk/src/ui/board.rs @@ -27,7 +27,7 @@ pub struct BoardPrivate { current_player: Rc>, board: Rc>, - cursor_location: Rc>, + cursor_location: Rc>>, api: Rc>>, } @@ -135,14 +135,17 @@ impl ObjectImpl for BoardPrivate { }); let cursor = cursor_location.borrow(); - match board.stone(cursor.row, cursor.column) { - IntersectionElement::Empty(_) => pen.ghost_stone( - context, - cursor.row, - cursor.column, - *current_player.borrow(), - ), - _ => {} + match *cursor { + None => {} + Some(ref cursor) => match board.stone(cursor.row, cursor.column) { + IntersectionElement::Empty(_) => pen.ghost_stone( + context, + cursor.row, + cursor.column, + *current_player.borrow(), + ), + _ => {} + }, } let render_end = std::time::Instant::now(); println!("board rendering time: {:?}", render_end - render_start); @@ -159,12 +162,17 @@ impl ObjectImpl for BoardPrivate { let hspace_between = ((WIDTH - 40) as f64) / ((board.size.width - 1) as f64); let vspace_between = ((HEIGHT - 40) as f64) / ((board.size.height - 1) as f64); - let addr = Addr { - column: ((x.round() - 20.) / hspace_between).round() as u8, - row: ((y.round() - 20.) / vspace_between).round() as u8, - }; + let addr = + if x.round() < 20. || x.round() > 780. || y.round() < 20. || y.round() > 780. { + None + } else { + Some(Addr { + column: ((x.round() - 20.) / hspace_between).round() as u8, + row: ((y.round() - 20.) / vspace_between).round() as u8, + }) + }; - if *cursor != addr { + if *cursor != addr.clone() { *cursor = addr; drawing_area.queue_draw(); } @@ -179,15 +187,18 @@ impl ObjectImpl for BoardPrivate { gesture.connect_released(move |_, _, _, _| { let board = board.borrow(); let cursor = cursor.borrow(); - match board.stone(cursor.row, cursor.column) { - IntersectionElement::Empty(request) => { - println!("need to send request: {:?}", request); - api.borrow() - .as_ref() - .expect("API must exist") - .dispatch(request); - } - _ => {} + match *cursor { + None => {} + Some(ref cursor) => match board.stone(cursor.row, cursor.column) { + IntersectionElement::Empty(request) => { + println!("need to send request: {:?}", request); + api.borrow() + .as_ref() + .expect("API must exist") + .dispatch(request); + } + _ => {} + }, } }); } diff --git a/kifu/kifu-gtk/src/ui/player_card.rs b/kifu/kifu-gtk/src/ui/player_card.rs index 04e10e2..c10012c 100644 --- a/kifu/kifu-gtk/src/ui/player_card.rs +++ b/kifu/kifu-gtk/src/ui/player_card.rs @@ -1,6 +1,6 @@ use glib::Object; use gtk::{prelude::*, subclass::prelude::*}; -use kifu_core::{ui::PlayerCardElement, Color}; +use kifu_core::ui::PlayerCardElement; #[derive(Default)] pub struct PlayerCardPrivate { diff --git a/kifu/kifu-gtk/src/ui/playing_field.rs b/kifu/kifu-gtk/src/ui/playing_field.rs index 1738cf3..afcb93d 100644 --- a/kifu/kifu-gtk/src/ui/playing_field.rs +++ b/kifu/kifu-gtk/src/ui/playing_field.rs @@ -2,27 +2,9 @@ use crate::ui::{Board, Chat, PlayerCard}; use crate::CoreApi; use glib::Object; use gtk::{prelude::*, subclass::prelude::*}; -use kifu_core::{ - ui::{ - BoardElement, ChatElement, IntersectionElement, PlayerCardElement, PlayingFieldView, - StoneElement, TextFieldElement, - }, - Color, Size, -}; +use kifu_core::ui::PlayingFieldView; use std::{cell::RefCell, rc::Rc}; -/* -#[derive(Clone, Debug)] -pub struct PlayingFieldView { - pub board: types::GobanElement, - pub player_card_black: types::PlayerCardElement, - pub player_card_white: types::PlayerCardElement, - pub chat: types::ChatElement, - pub message: types::TextFieldElement, - pub current_player: Color, -} -*/ - pub struct PlayingFieldPrivate { board: Rc>>, player_card_white: Rc>>,