Commit 7f7f28d9 authored by Florian Blasius's avatar Florian Blasius 🤘
Browse files

[refactoring] insert renderobject with index

parent baa1b0e9
Pipeline #2405 passed with stage
in 2 minutes and 20 seconds
......@@ -31,14 +31,16 @@ fn main() {
rect_pressed: false,
};
example_state.rect_index = window.push_rectangle(
example_state.rect_index = window.insert_rectangle(
0,
Rectangle::default()
.with_size(Size::new(example_state.rect.2, example_state.rect.3))
.with_position(Point::new(example_state.rect.0, example_state.rect.1))
.with_background(Color::rgb(100, 123, 145)),
);
window.push_text(
window.insert_text(
1,
Text::default()
.with_text("Drag the rectangle")
.with_position(Point::new(10.0, 20.0))
......
......@@ -21,14 +21,16 @@ fn main() {
.with_size(Size::new(800.0, 600.0))
.build();
window.push_rectangle(
window.insert_rectangle(
0,
Rectangle::default()
.with_size(Size::new(40.0, 40.0))
.with_position(Point::new(10.0, 10.0))
.with_background(Color::rgb(100, 123, 145)),
);
window.push_rectangle(
window.insert_rectangle(
1,
Rectangle::default()
.with_size(Size::new(40.0, 40.0))
.with_position(Point::new(60.0, 10.0))
......@@ -43,7 +45,8 @@ fn main() {
);
// z index example
window.push_rectangle_with_z(
window.insert_rectangle_with_z(
2,
Rectangle::default()
.with_size(Size::new(20.0, 20.0))
.with_position(Point::new(120.0, 20.0))
......@@ -51,14 +54,16 @@ fn main() {
10,
);
window.push_rectangle(
window.insert_rectangle(
3,
Rectangle::default()
.with_size(Size::new(40.0, 40.0))
.with_position(Point::new(110.0, 10.0))
.with_background(Color::rgb(100, 123, 145)),
);
window.push_text(
window.insert_text(
4,
Text::default()
.with_text("OrbRender")
.with_position(Point::new(10.0, 80.0))
......@@ -66,7 +71,8 @@ fn main() {
.with_font(FontConfig::default().with_family("Roboto").with_size(22.0)),
);
window.push_image(
window.insert_image(
5,
Image::default()
.with_position(Point::new(10.0, 100.0))
.with_source(format!("{}orbtk-space.png", res_path)),
......
......@@ -235,16 +235,16 @@ impl Window for CairoWindow {
self.background = background;
}
fn push_rectangle_with_z(&mut self, rectangle: Rectangle, z: usize) -> usize {
self.render_storage.push_with_z(rectangle, z)
fn insert_rectangle_with_z(&mut self, index: usize, rectangle: Rectangle, z: usize) -> usize {
self.render_storage.insert_with_z(index, rectangle, z)
}
fn push_text_with_z(&mut self, text: Text, z: usize) -> usize {
self.render_storage.push_with_z(text, z)
fn insert_text_with_z(&mut self, index: usize, text: Text, z: usize) -> usize {
self.render_storage.insert_with_z(index, text, z)
}
fn push_image_with_z(&mut self, image: Image, z: usize) -> usize {
self.render_storage.push_with_z(image, z)
fn insert_image_with_z(&mut self, index: usize, image: Image, z: usize) -> usize {
self.render_storage.insert_with_z(index, image, z)
}
fn get_rectangle(&mut self, index: usize) -> Option<&Rectangle> {
......
......@@ -121,16 +121,16 @@ impl Window for OrbClientWindow {
self.background = background;
}
fn push_rectangle_with_z(&mut self, rectangle: Rectangle, z: usize) -> usize {
self.render_storage.push_with_z(rectangle, z)
fn insert_rectangle_with_z(&mut self, rectangle: Rectangle, z: usize) -> usize {
self.render_storage.insert_with_z(rectangle, z)
}
fn push_text_with_z(&mut self, text: Text, z: usize) -> usize {
self.render_storage.push_with_z(text, z)
fn insert_text_with_z(&mut self, text: Text, z: usize) -> usize {
self.render_storage.insert_with_z(text, z)
}
fn push_image_with_z(&mut self, image: Image, z: usize) -> usize {
self.render_storage.push_with_z(image, z)
fn insert_image_with_z(&mut self, image: Image, z: usize) -> usize {
self.render_storage.insert_with_z(image, z)
}
fn remove_render_object(&mut self, index: usize) {
......
......@@ -172,16 +172,16 @@ impl Window for StdWebWindow {
self.background = background;
}
fn push_rectangle_with_z(&mut self, rectangle: Rectangle, z: usize) -> usize {
self.render_storage.push_with_z(rectangle, z)
fn insert_rectangle_with_z(&mut self, index: usize, rectangle: Rectangle, z: usize) -> usize {
self.render_storage.insert_with_z(index, rectangle, z)
}
fn push_text_with_z(&mut self, text: Text, z: usize) -> usize {
self.render_storage.push_with_z(text, z)
fn insert_text_with_z(&mut self, index: usize, text: Text, z: usize) -> usize {
self.render_storage.insert_with_z(index, text, z)
}
fn push_image_with_z(&mut self, image: Image, z: usize) -> usize {
self.render_storage.push_with_z(image, z)
fn insert_image_with_z(&mut self, index: usize, image: Image, z: usize) -> usize {
self.render_storage.insert_with_z(index, image, z)
}
fn get_rectangle(&mut self, index: usize) -> Option<&Rectangle> {
......
......@@ -31,7 +31,7 @@ fn clip_rounded(rect: LayoutRect, radius: f64) -> ComplexClipRegion {
ComplexClipRegion::new(rect, BorderRadius::uniform(radius), ClipMode::Clip)
}
fn push_rect(
fn insert_rect(
renderer: &mut RenderBuilder,
rect: LayoutRect,
color: ColorF,
......@@ -42,11 +42,11 @@ fn push_rect(
let id = renderer
.builder
.define_clip(rect, vec![clip_rounded(clip_rect, radius)], None);
renderer.builder.push_clip_id(id);
renderer.builder.insert_clip_id(id);
}
let info = PrimitiveInfo::new(rect);
renderer.builder.push_rect(&info, color.into());
renderer.builder.insert_rect(&info, color.into());
renderer.builder.pop_clip_id();
}
......@@ -121,7 +121,7 @@ impl Window for WebRenderWindow {
|| border_thickness.bottom > 0.0
{
if rectangle.border_color.unwrap().data > 0 {
push_rect(
insert_rect(
render_builder,
bounds,
ColorF::new(
......@@ -136,7 +136,7 @@ impl Window for WebRenderWindow {
}
if rectangle.background.unwrap().data > 0 {
push_rect(
insert_rect(
render_builder,
bounds,
ColorF::new(
......@@ -164,7 +164,7 @@ impl Window for WebRenderWindow {
}
} else {
if rectangle.background.unwrap().data > 0 {
push_rect(
insert_rect(
render_builder,
bounds,
ColorF::new(
......@@ -249,16 +249,16 @@ impl Window for WebRenderWindow {
);
}
fn push_rectangle_with_z(&mut self, rectangle: Rectangle, z: usize) -> usize {
self.render_storage.push_with_z(rectangle, z)
fn insert_rectangle_with_z(&mut self, rectangle: Rectangle, z: usize) -> usize {
self.render_storage.insert_with_z(rectangle, z)
}
fn push_text_with_z(&mut self, text: Text, z: usize) -> usize {
self.render_storage.push_with_z(text, z)
fn insert_text_with_z(&mut self, text: Text, z: usize) -> usize {
self.render_storage.insert_with_z(text, z)
}
fn push_image_with_z(&mut self, image: Image, z: usize) -> usize {
self.render_storage.push_with_z(image, z)
fn insert_image_with_z(&mut self, image: Image, z: usize) -> usize {
self.render_storage.insert_with_z(image, z)
}
fn remove_render_object(&mut self, index: usize) {
......
......@@ -17,14 +17,13 @@ pub trait RenderObject: Any {}
pub struct RenderStorage {
render_objects: BTreeMap<usize, Box<Any>>,
z_map: BTreeMap<usize, BTreeSet<usize>>,
render_object_counter: usize,
}
impl RenderStorage {
/// Appends an render object with z index to the storage. Returns the id of the render object.
pub fn push_with_z<R: RenderObject>(&mut self, render_object: R, z: usize) -> usize {
pub fn insert_with_z<R: RenderObject>(&mut self, index: usize, render_object: R, z: usize) -> usize {
self.render_objects
.insert(self.render_object_counter, Box::new(render_object));
.insert(index, Box::new(render_object));
if !self.z_map.contains_key(&z) {
self.z_map.insert(z, BTreeSet::new());
......@@ -34,10 +33,9 @@ impl RenderStorage {
self.z_map
.get_mut(&z)
.unwrap()
.insert(self.render_object_counter);
.insert(index);
self.render_object_counter += 1;
self.render_object_counter - 1
index
}
/// Returns a reference to a render object depending on the type of index.
......@@ -77,7 +75,6 @@ impl RenderStorage {
pub fn clear(&mut self) {
self.render_objects.clear();
self.z_map.clear();
self.render_object_counter = 0;
}
}
......
......@@ -14,28 +14,28 @@ pub trait Window {
/// Sets the `background` color of the window.
fn background(&mut self, color: Color);
/// Pushes a rectangle render object with z index to the render list. Returns the index of the rectangle.
fn push_rectangle_with_z(&mut self, rectangle: Rectangle, z: usize) -> usize;
/// Inserts a rectangle render object with z index into the render map. Returns the index of the rectangle.
fn insert_rectangle_with_z(&mut self, index: usize, rectangle: Rectangle, z: usize) -> usize;
/// Pushes a rectangle render object to the render list. Returns the index of the rectangle.
fn push_rectangle(&mut self, rectangle: Rectangle) -> usize {
self.push_rectangle_with_z(rectangle, 0)
/// Inserts a rectangle render object into the render map. Returns the index of the rectangle.
fn insert_rectangle(&mut self, index: usize, rectangle: Rectangle) -> usize {
self.insert_rectangle_with_z(index, rectangle, 0)
}
/// Pushes a text render object with z index to the render list. Returns the index of the text.
fn push_text_with_z(&mut self, text: Text, z: usize) -> usize;
/// Inserts a text render object with z index into the render map. Returns the index of the text.
fn insert_text_with_z(&mut self, index: usize, text: Text, z: usize) -> usize;
/// Pushes a text render object to the render list. Returns the index of the text.
fn push_text(&mut self, text: Text) -> usize {
self.push_text_with_z(text, 0)
/// Inserts a text render object into the render map. Returns the index of the text.
fn insert_text(&mut self, index: usize, text: Text) -> usize {
self.insert_text_with_z(index, text, 0)
}
/// Pushes a image render object with z index to the render list. Returns the index of the image.
fn push_image_with_z(&mut self, image: Image, z: usize) -> usize;
/// Inserts a image render object with z index into the render map. Returns the index of the image.
fn insert_image_with_z(&mut self, index: usize, image: Image, z: usize) -> usize;
/// Pushes a image render object to the render list. Returns the index of the image.
fn push_image(&mut self, image: Image) -> usize {
self.push_image_with_z(image, 0)
/// Inserts a image render object into the render map. Returns the index of the image.
fn insert_image(&mut self, index: usize, image: Image) -> usize {
self.insert_image_with_z(index, image, 0)
}
/// Returns a reference to a rectangle depending on the type of index.
......
Supports Markdown
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