|
@@ -1,24 +1,19 @@
|
|
|
use xcb;
|
|
|
-use ui::ext;
|
|
|
-use ui::ext::ConnectionExt;
|
|
|
use ui::font;
|
|
|
|
|
|
-use std::cmp;
|
|
|
use std::rc::Rc;
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
pub struct DrawContext {
|
|
|
conn: Arc<xcb::Connection>,
|
|
|
- window: xcb::Window,
|
|
|
picture: xcb::render::Picture,
|
|
|
pen: xcb::render::Picture,
|
|
|
fonts: Rc<font::FontLoader>,
|
|
|
- pen_color: xcb::render::Color,
|
|
|
bg_color: xcb::render::Color
|
|
|
}
|
|
|
|
|
|
impl DrawContext {
|
|
|
- pub fn new(conn: Arc<xcb::Connection>, window: xcb::Window, picture: xcb::render::Picture, fonts: Rc<font::FontLoader>) -> DrawContext {
|
|
|
+ pub fn new(conn: Arc<xcb::Connection>, picture: xcb::render::Picture, fonts: Rc<font::FontLoader>) -> DrawContext {
|
|
|
let pen = conn.generate_id();
|
|
|
let color = xcb::render::Color::new(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
|
|
|
xcb::render::create_solid_fill(
|
|
@@ -29,11 +24,9 @@ impl DrawContext {
|
|
|
|
|
|
DrawContext {
|
|
|
conn: conn,
|
|
|
- window: window,
|
|
|
picture: picture,
|
|
|
pen: pen,
|
|
|
fonts: fonts,
|
|
|
- pen_color: color,
|
|
|
bg_color: xcb::render::Color::new(0, 0, 0, 0xFFFF)
|
|
|
}
|
|
|
}
|
|
@@ -66,35 +59,21 @@ impl DrawContext {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub fn draw_text_until(&self, name: &str, x: u16, width: u16) {
|
|
|
- if !name.is_empty() {
|
|
|
- let text = self.fonts.create_renderable_text(name);
|
|
|
- let baseline = 20 - self.fonts.default_offset(20);
|
|
|
+ pub fn draw_text_with_clipping(&self, name: &str, x: u16, width: u16) {
|
|
|
+ xcb::render::set_picture_clip_rectangles(
|
|
|
+ &self.conn,
|
|
|
+ self.picture,
|
|
|
+ 0, 0,
|
|
|
+ &[xcb::Rectangle::new(x as i16, 0, width, 20)]
|
|
|
+ );
|
|
|
|
|
|
- // weird things happen if you draw too little
|
|
|
- let width = cmp::min(width, text.width);
|
|
|
+ self.draw_text(name, x);
|
|
|
|
|
|
- let pixmap = self.conn.generate_id();
|
|
|
- xcb::create_pixmap(&self.conn, 32, pixmap, self.window, x + width, 1);
|
|
|
- let pen = self.conn.generate_id();
|
|
|
- xcb::render::create_picture(
|
|
|
- &self.conn,
|
|
|
- pen,
|
|
|
- pixmap,
|
|
|
- self.conn.get_pict_format(ext::PictFormat::ARGB32),
|
|
|
- &[]
|
|
|
- );
|
|
|
- xcb::render::fill_rectangles(
|
|
|
- &self.conn,
|
|
|
- xcb::render::PICT_OP_SRC as u8,
|
|
|
- pen,
|
|
|
- self.pen_color,
|
|
|
- &[xcb::Rectangle::new(x as i16, 0, width, 1)]
|
|
|
- );
|
|
|
- text.render(&self.conn, pen, self.picture, x, baseline as u16);
|
|
|
- xcb::render::free_picture(&self.conn, pen);
|
|
|
- xcb::free_pixmap(&self.conn, pixmap);
|
|
|
- }
|
|
|
+ xcb::render::change_picture(
|
|
|
+ &self.conn,
|
|
|
+ self.picture,
|
|
|
+ &[(xcb::render::CP_CLIP_MASK, xcb::render::PICTURE_NONE)]
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
pub fn flush(&self) {
|