Commit 437d5d79 authored by Florian Blasius's avatar Florian Blasius 🤘
Browse files

[feature] cairo png rendering.

parent 639389e8
Pipeline #2353 passed with stage
in 3 minutes and 27 seconds
......@@ -86,10 +86,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "orbclient"
version = "0.3.19"
source = "git+https://gitlab.redox-os.org/redox-os/orbclient.git#dc175376ad4ec897686a2e3a39a7c41df2032168"
version = "0.3.20"
source = "git+https://gitlab.redox-os.org/redox-os/orbclient.git#9df7d2c8b82b231dae7fe5f5e8a5e041d837e214"
dependencies = [
"redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.49 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -97,7 +97,7 @@ dependencies = [
name = "orbrender"
version = "0.1.0"
dependencies = [
"orbclient 0.3.19 (git+https://gitlab.redox-os.org/redox-os/orbclient.git)",
"orbclient 0.3.20 (git+https://gitlab.redox-os.org/redox-os/orbclient.git)",
"rust-cairo 0.1.0 (git+https://gitlab.redox-os.org/redox-os/rust-cairo.git)",
"stdweb 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -140,13 +140,13 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.1.44"
version = "0.1.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rust-cairo"
version = "0.1.0"
source = "git+https://gitlab.redox-os.org/redox-os/rust-cairo.git#bbb78123c77104b1a70f31a06562e6f043f9401d"
source = "git+https://gitlab.redox-os.org/redox-os/rust-cairo.git#1482cdb320e19618fc8624163ca3e1606d4ae00a"
[[package]]
name = "rustc_version"
......@@ -197,12 +197,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.80"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.80"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -217,7 +217,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -232,7 +232,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"stdweb-internal-macros 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -246,8 +246,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -259,8 +259,8 @@ dependencies = [
"base-x 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -320,12 +320,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum orbclient 0.3.19 (git+https://gitlab.redox-os.org/redox-os/orbclient.git)" = "<none>"
"checksum orbclient 0.3.20 (git+https://gitlab.redox-os.org/redox-os/orbclient.git)" = "<none>"
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1"
"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd"
"checksum redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "a84bcd297b87a545980a2d25a0beb72a1f490c31f0a9fde52fca35bfbb1ceb70"
"checksum redox_syscall 0.1.49 (registry+https://github.com/rust-lang/crates.io-index)" = "f22c50afdcf3f0a31ebb6b47697f6a7c5e5a24967e842858118bce0615f0afad"
"checksum rust-cairo 0.1.0 (git+https://gitlab.redox-os.org/redox-os/rust-cairo.git)" = "<none>"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
......@@ -333,8 +333,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum sdl2-sys 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c543ce8a6e33a30cb909612eeeb22e693848211a84558d5a00bb11e791b7ab7"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "15c141fc7027dd265a47c090bf864cf62b42c4d228bbcf4e51a0c9e2b0d3f7ef"
"checksum serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "225de307c6302bec3898c51ca302fc94a7a1697ef0845fcee6448f33c032249c"
"checksum serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)" = "157e12af46859e968da75dea9845530e13d03bcab2009a41b9b7bb3cf4eb3ec2"
"checksum serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)" = "9469829702497daf2daf3c190e130c3fa72f719920f73c86160d43e8f8d76951"
"checksum serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "c37ccd6be3ed1fdf419ee848f7c758eb31b054d7cd3ae3600e3bae0adf569811"
"checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
"checksum stdweb 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "b84f9c829ef7d2e6abf1965393b231c0fd495f0293d612f32dbadd637e91fd0d"
......
......@@ -102,10 +102,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "orbclient"
version = "0.3.19"
source = "git+https://gitlab.redox-os.org/redox-os/orbclient.git#dc175376ad4ec897686a2e3a39a7c41df2032168"
version = "0.3.20"
source = "git+https://gitlab.redox-os.org/redox-os/orbclient.git#9df7d2c8b82b231dae7fe5f5e8a5e041d837e214"
dependencies = [
"redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.49 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -113,7 +113,7 @@ dependencies = [
name = "orbrender"
version = "0.1.0"
dependencies = [
"orbclient 0.3.19 (git+https://gitlab.redox-os.org/redox-os/orbclient.git)",
"orbclient 0.3.20 (git+https://gitlab.redox-os.org/redox-os/orbclient.git)",
"rust-cairo 0.1.0 (git+https://gitlab.redox-os.org/redox-os/rust-cairo.git)",
"stdweb 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -156,13 +156,13 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.1.44"
version = "0.1.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rust-cairo"
version = "0.1.0"
source = "git+https://gitlab.redox-os.org/redox-os/rust-cairo.git#bbb78123c77104b1a70f31a06562e6f043f9401d"
source = "git+https://gitlab.redox-os.org/redox-os/rust-cairo.git#1482cdb320e19618fc8624163ca3e1606d4ae00a"
[[package]]
name = "rustc_version"
......@@ -213,12 +213,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.80"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.80"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -233,7 +233,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -248,7 +248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"stdweb-internal-macros 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -262,8 +262,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -275,8 +275,8 @@ dependencies = [
"base-x 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -303,7 +303,7 @@ version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.49 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -346,12 +346,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum orbclient 0.3.19 (git+https://gitlab.redox-os.org/redox-os/orbclient.git)" = "<none>"
"checksum orbclient 0.3.20 (git+https://gitlab.redox-os.org/redox-os/orbclient.git)" = "<none>"
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1"
"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd"
"checksum redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "a84bcd297b87a545980a2d25a0beb72a1f490c31f0a9fde52fca35bfbb1ceb70"
"checksum redox_syscall 0.1.49 (registry+https://github.com/rust-lang/crates.io-index)" = "f22c50afdcf3f0a31ebb6b47697f6a7c5e5a24967e842858118bce0615f0afad"
"checksum rust-cairo 0.1.0 (git+https://gitlab.redox-os.org/redox-os/rust-cairo.git)" = "<none>"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
......@@ -359,8 +359,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum sdl2-sys 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c543ce8a6e33a30cb909612eeeb22e693848211a84558d5a00bb11e791b7ab7"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "15c141fc7027dd265a47c090bf864cf62b42c4d228bbcf4e51a0c9e2b0d3f7ef"
"checksum serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "225de307c6302bec3898c51ca302fc94a7a1697ef0845fcee6448f33c032249c"
"checksum serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)" = "157e12af46859e968da75dea9845530e13d03bcab2009a41b9b7bb3cf4eb3ec2"
"checksum serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)" = "9469829702497daf2daf3c190e130c3fa72f719920f73c86160d43e8f8d76951"
"checksum serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "c37ccd6be3ed1fdf419ee848f7c758eb31b054d7cd3ae3600e3bae0adf569811"
"checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
"checksum stdweb 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "b84f9c829ef7d2e6abf1965393b231c0fd495f0293d612f32dbadd637e91fd0d"
......
......@@ -66,7 +66,7 @@ fn main() {
let update = Arc::new(AtomicBool::new(true));
let mut runner = Runner::new(Box::new(move || {
let runner = Runner::new(Box::new(move || {
if update.load(atomic::Ordering::Acquire) {
window.render();
update.store(false, atomic::Ordering::Release);
......@@ -76,43 +76,14 @@ fn main() {
match event {
Event::System(system_event) => match system_event {
SystemEvent::Quit => {
// running = false;
return false;
}
_ => {}
},
_ => {}
}
}
}));
runner.run();
// let mut draw = false;
// let mut running = true;
// let mut update = true;
//
// loop {
// if !running {
// break;
// }
// // let start = PreciseTime::now();
// if update {
// window.render();
// update = false;
// }
//
// for event in window.events() {
// match event {
// Event::System(system_event) => match system_event {
// SystemEvent::Quit => {
// running = false;
// }
// _ => {}
// },
// _ => {}
// }
// }
// // let end = PreciseTime::now();
// // println!("{} seconds for whatever you did.", start.to(end));
// }
true
})).run();
}
......@@ -2,7 +2,6 @@ use orbclient;
use orbclient::Renderer;
use rust_cairo::*;
use std::ffi::CString;
use std::os::raw::c_char;
use crate::{
events::{Event, SystemEvent},
......@@ -12,25 +11,6 @@ use crate::{
window::WindowBuilder,
};
pub struct Runner {
run: Box<FnMut()>,
}
impl Runner {
pub fn new(run: Box<FnMut()>) -> Self {
Runner {
run
}
}
pub fn run(mut self) {
loop {
(self.run)();
}
}
}
unsafe fn rounded_rect(
x: f64,
y: f64,
......@@ -140,12 +120,14 @@ impl Window for CairoWindow {
self.cairo_context,
&border_color,
);
} else {
cairo_rectangle(self.cairo_context, position.x as f64,
position.y as f64,
size.width as f64,
size.height as f64);
cairo_rectangle(
self.cairo_context,
position.x as f64,
position.y as f64,
size.width as f64,
size.height as f64,
);
cairo_set_source_rgba(
self.cairo_context,
......@@ -156,26 +138,32 @@ impl Window for CairoWindow {
);
cairo_fill(self.cairo_context);
}
}
}
if let Some(background) = rectangle.background {
if rectangle.radius > 0.0 {
rounded_rect(
(position.x + border_thickness.left) as f64,
(position.y + border_thickness.top) as f64,
(size.width - border_thickness.left - border_thickness.right) as f64,
(size.height - border_thickness.top - border_thickness.bottom) as f64,
rectangle.radius as f64,
self.cairo_context,
&background,
);
rounded_rect(
(position.x + border_thickness.left) as f64,
(position.y + border_thickness.top) as f64,
(size.width - border_thickness.left - border_thickness.right)
as f64,
(size.height - border_thickness.top - border_thickness.bottom)
as f64,
rectangle.radius as f64,
self.cairo_context,
&background,
);
} else {
cairo_rectangle(self.cairo_context, (position.x + border_thickness.left) as f64,
(position.y + border_thickness.top) as f64,
(size.width - border_thickness.left - border_thickness.right) as f64,
(size.height - border_thickness.top - border_thickness.bottom) as f64);
cairo_rectangle(
self.cairo_context,
(position.x + border_thickness.left) as f64,
(position.y + border_thickness.top) as f64,
(size.width - border_thickness.left - border_thickness.right)
as f64,
(size.height - border_thickness.top - border_thickness.bottom)
as f64,
);
cairo_set_source_rgba(
self.cairo_context,
......@@ -191,18 +179,26 @@ impl Window for CairoWindow {
if let Some(tx) = render_object.downcast_ref::<Text>() {
let position = tx.position;
cairo_set_source_rgba(self.cairo_context, tx.foreground.r_f() as f64,
tx.foreground.g_f() as f64,
tx.foreground.b_f() as f64,
tx.foreground.a_f() as f64);
cairo_set_source_rgba(
self.cairo_context,
tx.foreground.r_f() as f64,
tx.foreground.g_f() as f64,
tx.foreground.b_f() as f64,
tx.foreground.a_f() as f64,
);
let font = CString::new(tx.font.family.clone()).expect("CString::new failed");
let text = CString::new(tx.text.clone()).expect("CString::new failed");
cairo_select_font_face(self.cairo_context, font.as_ptr(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
// if self.text_bold {
// cairo_select_font_face(cr, font.as_ptr(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
// }
cairo_select_font_face(
self.cairo_context,
font.as_ptr(),
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL,
);
// if self.text_bold {
// cairo_select_font_face(cr, font.as_ptr(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
// }
cairo_set_font_size(self.cairo_context, tx.font.size as f64);
......@@ -214,24 +210,35 @@ impl Window for CairoWindow {
x_advance: 0.0,
y_advance: 0.0,
};
cairo_text_extents(self.cairo_context, text.as_ptr(), &mut text_extens as *mut cairo_text_extents_t);
cairo_text_extents(
self.cairo_context,
text.as_ptr(),
&mut text_extens as *mut cairo_text_extents_t,
);
cairo_move_to(self.cairo_context, position.x as f64, position.y as f64);
cairo_show_text(self.cairo_context, text.as_ptr());
}
if let Some(img) = render_object.downcast_ref::<Image>() {
// cairo_new_sub_path(self.cairo_context);
// let image = Image::from_path(img.source);
// let c_image = cairo_image_surface_create_for_data()
// cairo_set_source_surface(self.cairo_context, )
let filename = CString::new(img.source.clone()).expect("CString::new failed");
let png = cairo_image_surface_create_from_png(filename.as_ptr());
}
}
//save cairo state
cairo_save(self.cairo_context);
//set the coordinates zero point to the desired point for the graphic
cairo_translate(self.cairo_context,img.position.x as f64+5.0, img.position.y as f64 +5.0);
//draw image on position zero for x and y
cairo_set_source_surface (self.cairo_context, png, 0.0,0.0);
cairo_paint (self.cairo_context);
//restore the old cairo state
cairo_restore(self.cairo_context);
}
}
}
self.inner_window.sync();
......@@ -312,7 +319,7 @@ impl From<WindowBuilder> for CairoWindow {
//WHY I DO THIS?????
//The Answer -> https://mobtowers.com/2013/04/15/html5-canvas-crisp-lines-every-time/
// cairo_translate(cr, 0.5, 0.5);
// cairo_translate(cr, 0.5, 0.5);
}
CairoWindow {
......
pub use self::runner::Runner;
#[cfg(target_arch = "wasm32")]
pub use self::stdweb::{build_window, initialize, Runner};
pub use self::stdweb::{build_window, initialize};
#[cfg(target_arch = "wasm32")]
mod stdweb;
#[cfg(target_arch = "wasm32")]
#[path = "runner/stdweb.rs"]
mod runner;
#[cfg(not(target_arch = "wasm32"))]
pub use self::cairo::{build_window, initialize, Runner};
pub use self::cairo::{build_window, initialize};
#[cfg(not(target_arch = "wasm32"))]
mod cairo;
#[cfg(not(target_arch = "wasm32"))]
#[path = "runner/default.rs"]
mod runner;
////
//#[cfg(not(target_arch = "wasm32"))]
//pub use self::orbclient::{build_window, initialize};
......
pub struct Runner {
run: Box<FnMut() -> bool>,
}
impl Runner {
pub fn new(run: Box<FnMut() -> bool>) -> Self {
Runner {
run
}
}
pub fn run(mut self) {
loop {
if !(self.run)() {
break;
}
}
}
}
\ No newline at end of file
use stdweb::web::window;
pub struct Runner {
run: Box<FnMut() -> bool>,
}
impl Runner {
pub fn new(run: Box<FnMut() -> bool>) -> Self {
Runner {
run
}
}
pub fn run(mut self) {
(self.run)();
window().request_animation_frame(|_| self.run());
}
}
\ No newline at end of file
......@@ -5,23 +5,6 @@ use stdweb::{
web::{document, html_element::{CanvasElement, ImageElement}, window, CanvasRenderingContext2d, FillRule},
};
pub struct Runner {
run: Box<FnMut()>,
}
impl Runner {
pub fn new(run: Box<FnMut()>) -> Self {
Runner {
run
}
}
pub fn run(mut self) {
(self.run)();
window().request_animation_frame(|_| self.run());
}
}
// Shamelessly stolen from webplatform's TodoMVC example.
macro_rules! enclose {
( ($( $x:ident ),*) $y:expr ) => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment