Place a stone onto the drawing area #38

Merged
savanni merged 7 commits from feature/place-stone into main 2023-04-07 12:14:04 +00:00
6 changed files with 38 additions and 55 deletions
Showing only changes of commit 26db170c79 - Show all commits

View File

@ -1,5 +1,3 @@
use std::time::Duration;
mod api;
pub use api::{CoreApp, Request, Response};

View File

@ -1,4 +1,4 @@
use crate::types::{Color, Size};
use crate::types::Color;
use crate::{types::GameState, ui::types};
#[derive(Clone, Debug)]

View File

@ -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")

View File

@ -27,7 +27,7 @@ pub struct BoardPrivate {
current_player: Rc<RefCell<Color>>,
board: Rc<RefCell<BoardElement>>,
cursor_location: Rc<RefCell<Addr>>,
cursor_location: Rc<RefCell<Option<Addr>>>,
api: Rc<RefCell<Option<CoreApi>>>,
}
@ -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);
}
_ => {}
},
}
});
}

View File

@ -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 {

View File

@ -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<RefCell<Option<Board>>>,
player_card_white: Rc<RefCell<Option<PlayerCard>>>,