Browse Source

started work on the canvas widget and adjusted aspect

master
Weird Constructor 4 years ago
parent
commit
83e4868bd9
  1. 1
      CHANGELOG.md
  2. 1
      godot_bind/src/lib.rs
  3. 9
      godot_project/gamelib/main.wl
  4. BIN
      godot_project/gdnative/libsscg_gd.so
  5. 6
      godot_project/project.godot
  6. 69
      sscg_game/src/gui.rs
  7. 17
      sscg_game/src/wlambda_api.rs

1
CHANGELOG.md

@ -2,6 +2,7 @@
========================
* Feature: Added an FPS counter in the top right.
* Change: Aspect ratio is now expanded and default window size is at 1280x720 now.
0.3.0 alpha (2019-11-26)
========================

1
godot_bind/src/lib.rs

@ -78,6 +78,7 @@ fn draw_cmds(xxo: i32, yyo: i32,
},
DrawCmd::Circle { x, y, r, color } => {
unsafe {
println!("CIRCLE: {},{},{} : {:?}", x, y, r, color);
n.draw_circle(
vec2((xxo + *x) as f32,
(yyo + *y) as f32),

9
godot_project/gamelib/main.wl

@ -116,10 +116,17 @@ STATE.code.recalc_ship_cargo = {
${ t = :l_text, ref = :kg, text = STATE.ship.cargo.kg, w = 333, fg = c:SE1_L, bg = "000" },
${ t = :l_text, text = STATE.ship_types.(STATE.ship.t).cargo_max_kg, w = 333, fg = c:SE2, bg = "000" },
]},
${ t = :hbox, spacing = 5, w = 1000, h = 700, childs = $[
${ t = :hbox, spacing = 5, w = 1000, h = 300, childs = $[
gui:action_button 500 1000 :start_mining "Start mining",
gui:button 500 1000 :depart "Depart",
]},
${ t = :canvas,
w = 1000,
h = 400,
cmds = $[
$[:circle, 500, 500, 100, "F00"],
],
},
]
} {||
match _1

BIN
godot_project/gdnative/libsscg_gd.so

Binary file not shown.

6
godot_project/project.godot

@ -19,6 +19,12 @@ config/name="Space Ship Cargo Game"
run/main_scene="res://scenes/system_map/system_map.tscn"
config/icon="res://icon.png"
[display]
window/size/width=1280
window/size/height=720
window/stretch/aspect="expand"
[input]
fly_stop={

69
sscg_game/src/gui.rs

@ -6,6 +6,7 @@ use crate::logic::FontSize;
pub enum Widget {
Layout(usize, Size, Layout),
Label(usize, Size, Label),
Canvas(usize, Size, Canvas),
}
fn calc_m_wo_spacing(child_count: usize, spacing: u32, border: i32, mw: u32) -> u32 {
@ -25,6 +26,7 @@ impl Widget {
match self {
Widget::Layout(id, _, _) => *id,
Widget::Label(id, _, _) => *id,
Widget::Canvas(id, _, _) => *id,
}
}
pub fn calc_feedback<P>(&self, max_w: u32, max_h: u32, p: &mut P)
@ -40,6 +42,10 @@ impl Widget {
p.push_add_offs(l.margin as i32, l.margin as i32);
(*id, l.size(max_w, max_h))
},
Widget::Canvas(id, l, _) => {
p.push_add_offs(l.margin as i32, l.margin as i32);
(*id, l.size(max_w, max_h))
},
};
WidgetFeedback {
@ -299,6 +305,38 @@ impl Widget {
self.draw_label(lbl, bg_color, tw, th, &mut mw, &mut mh, lbl.font_size, p);
}
},
Widget::Canvas(id, _size, cv) => {
let min = if mw < mh { mw } else { mh };
println!("CANVAAAAAAAAAAAAAS {:?}\n", cv);
for cmd in cv.cmds.iter() {
match cmd {
CanvasCmd::Circle( x, y, r, clr ) => {
let x = p2r(min, *x);
let y = p2r(min, *y);
let r = p2r(min, *r as i32);
p.draw_circle(x as i32, y as i32, r, *clr);
},
CanvasCmd::CircleFilled( x, y, r, clr ) => {
let x = p2r(min, *x);
let y = p2r(min, *y);
let r = p2r(min, *r as i32);
p.draw_circle(x as i32, y as i32, r, *clr);
},
CanvasCmd::Line( x1, y1, x2, y2, t, clr ) => {
p.draw_line(
p2r(min, *x1) as i32,
p2r(min, *y1) as i32,
p2r(min, *x2) as i32,
p2r(min, *y2) as i32,
*t,
*clr);
},
CanvasCmd::Rect( x1, y1, rw, rh, clr ) => { },
CanvasCmd::RectFilled( x1, y1, rw, rh, clr ) => { },
CanvasCmd::Hitbox( x1, y1, rw, rh, tag ) => { },
}
}
},
}
p.pop_offs();
w_fb.w = mw;
@ -543,6 +581,13 @@ impl Window {
id
}
pub fn add_canvas(&mut self, s: Size, cv: Canvas) -> usize {
let id = self.widgets.len();
self.widgets.push(Widget::Canvas(id, s, cv));
self.does_need_redraw();
id
}
pub fn add_label(&mut self, s: Size, l: Label) -> usize {
let id = self.widgets.len();
self.widgets.push(Widget::Label(id, s, l));
@ -737,9 +782,29 @@ impl Size {
}
}
#[derive(Debug, Clone)]
pub enum CanvasCmd {
Circle(i32, i32, u32, (u8, u8, u8, u8)),
CircleFilled(i32, i32, u32, (u8, u8, u8, u8)),
Line(i32, i32, i32, i32, u32, (u8, u8, u8, u8)),
Rect(i32, i32, u32, u32, (u8, u8, u8, u8)),
RectFilled(i32, i32, u32, u32, (u8, u8, u8, u8)),
Hitbox(i32, i32, u32, u32, String),
}
#[derive(Debug, Copy, Clone)]
pub enum LabelStyle {
#[derive(Debug, Clone)]
pub struct Canvas {
cmds: std::vec::Vec<CanvasCmd>,
}
impl Canvas {
pub fn new() -> Self {
Self { cmds: vec![], }
}
pub fn push(&mut self, cmd: CanvasCmd) {
self.cmds.push(cmd);
}
}
#[derive(Debug, Clone)]

17
sscg_game/src/wlambda_api.rs

@ -586,6 +586,23 @@ fn vval2widget(v: VVal, win: &mut gui::Window) -> usize {
color_hex24tpl(&v.v_s_rawk("border_color")),
&childs);
},
"canvas" => {
let mut cv = gui::Canvas::new();
println!("CCCCCCCCCCCCCCCCC {}", v.s());
for elem in v.clone().v_k("cmds").iter() {
match &elem.v_s_raw(0)[..] {
"circle" => {
cv.push(gui::CanvasCmd::Circle(
elem.v_i(1) as i32,
elem.v_i(2) as i32,
elem.v_i(3) as u32,
color_hex24tpl(&v.v_s_raw(4))));
},
_ => {},
}
}
return win.add_canvas(vval2size(v.clone()), cv);
},
_ => ()
}

Loading…
Cancel
Save