mirror of
https://gitlab.freedesktop.org/dabrain34/GstPipelineStudio.git
synced 2024-11-22 00:50:59 +00:00
mainwindow: can now draw a vector of rectangles.
This commit is contained in:
parent
52718e0388
commit
12e7958886
3 changed files with 28 additions and 13 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -292,6 +292,7 @@ dependencies = [
|
||||||
name = "gst_pipeline_studio"
|
name = "gst_pipeline_studio"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"gtk",
|
"gtk",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -7,3 +7,4 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gtk = "0.14.3"
|
gtk = "0.14.3"
|
||||||
|
anyhow = "1"
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use gtk::ffi::GtkDrawingArea;
|
use gtk::cairo::Context;
|
||||||
use gtk::gdk::Display;
|
|
||||||
use gtk::glib;
|
use gtk::glib;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
|
@ -9,6 +8,20 @@ use gtk::{
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
struct Element {
|
||||||
|
name: String,
|
||||||
|
position: (f64, f64),
|
||||||
|
size: (f64, f64),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_elements(elements: &Vec<Element>, c: &Context) {
|
||||||
|
for element in elements {
|
||||||
|
c.rectangle(element.position.0, element.position.1, 80.0, 45.0);
|
||||||
|
c.fill().expect("Can not draw into context");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build_ui(application: >k::Application) {
|
pub fn build_ui(application: >k::Application) {
|
||||||
let glade_src = include_str!("gps.ui");
|
let glade_src = include_str!("gps.ui");
|
||||||
let builder = Builder::from_string(glade_src);
|
let builder = Builder::from_string(glade_src);
|
||||||
|
@ -25,20 +38,20 @@ pub fn build_ui(application: >k::Application) {
|
||||||
let event_box = EventBox::new();
|
let event_box = EventBox::new();
|
||||||
event_box.add(&drawing_area);
|
event_box.add(&drawing_area);
|
||||||
view_port.add(&event_box);
|
view_port.add(&event_box);
|
||||||
let mut position = (0.0, 0.0);
|
let elements: Rc<RefCell<Vec<Element>>> = Rc::new(RefCell::new(vec![]));
|
||||||
let position = Rc::new(RefCell::new((0.0, 0.0)));
|
let e_clone = elements.clone();
|
||||||
let p_clone = position.clone();
|
|
||||||
drawing_area.connect_draw(move |w, c| {
|
drawing_area.connect_draw(move |w, c| {
|
||||||
println!("w: {} c:{} p: {:?}", w, c, p_clone);
|
println!("w: {} c:{} e: {:?}", w, c, e_clone);
|
||||||
c.rectangle(p_clone.borrow().0, p_clone.borrow().1, 10.0, 20.0);
|
draw_elements(&e_clone.borrow().to_vec(), c);
|
||||||
c.fill();
|
|
||||||
gtk::Inhibit(false)
|
gtk::Inhibit(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
event_box.connect_button_release_event(move |w, evt| {
|
event_box.connect_button_release_event(move |_w, evt| {
|
||||||
let mut p = position.borrow_mut();
|
let mut elements = elements.borrow_mut();
|
||||||
p.0 = evt.position().0; // = evt.position().clone();
|
let mut element: Element = Default::default();
|
||||||
p.1 = evt.position().1;
|
element.position.0 = evt.position().0;
|
||||||
|
element.position.1 = evt.position().1;
|
||||||
|
elements.push(element);
|
||||||
drawing_area.queue_draw();
|
drawing_area.queue_draw();
|
||||||
gtk::Inhibit(false)
|
gtk::Inhibit(false)
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue