Skip to content

Commit b4ae060

Browse files
committed
(WIP) Update libui with pixmap rendering on unix
1 parent 2f26606 commit b4ae060

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

ui/examples/image.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! An example control gallery: a port of the same `ui` example.
1+
//! Pixmap example: Initializes and draws and empty 100x100 pixmap
22
33
extern crate ui;
44

@@ -10,7 +10,7 @@ struct ImageAreaHandler {
1010
}
1111

1212
impl AreaHandler for ImageAreaHandler {
13-
fn draw(&mut self, area: &Area, area_draw_params: &AreaDrawParams) {
13+
fn draw(&mut self, _area: &Area, area_draw_params: &AreaDrawParams) {
1414
let img = Image::new(100, 100);
1515
img.load_pixmap(0, 0, 100, 100, &self.data);
1616
area_draw_params.context.draw_image(0.0, 0.0, &img);

ui/src/image.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
use libc::c_void;
2-
use ui_sys::{self, uiPixmapImage, uiImageData, uiNewPixmapImage,
3-
uiFreePixmapImage, uiPixmapImageGetFormat, uiPixmapImageGetData,
4-
uiImageLoadPixmap32Raw, uiDrawPixmapImage};
5-
use ui_sys::uiDrawContext;
2+
use ui_sys::{uiPixmapImage, uiImageData, uiNewPixmapImage,
3+
uiFreePixmapImage, uiPixmapImageGetData,
4+
uiImageLoadPixmap32Raw};
65

76
pub struct Image {
87
ui_image: *mut uiPixmapImage
98
}
109

1110
// #define uiPixmap32FormatOffsets(a,r,g,b) ((a) << 0 | (r) << 2 | (g) << 4 | (b) << 6)
12-
const uiPixmap32FormatOffsetMask: u32 = 0x0ff;
13-
const uiPixmap32FormatHasAlpha: u32 = 0x100;
14-
const uiPixmap32FormatAlphaPremultiplied: u32 = 0x200;
15-
const uiPixmap32FormatZeroRowBottom: u32 = 0x400;
11+
const _UI_PIXMAP32_FORMAT_OFFSET_MASK: u32 = 0x0ff;
12+
const _UI_PIXMAP32_FORMAT_HAS_ALPHA: u32 = 0x100;
13+
const _UI_PIXMAP32_FORMAT_ALPHA_PREMULTIPLIED: u32 = 0x200;
14+
const _UI_PIXMAP32_FORMAT_ZERO_ROW_BOTTOM: u32 = 0x400;
1615

1716
impl Image {
1817
pub fn new(w: i32, h: i32) -> Image {
19-
unsafe {
20-
Image {
21-
ui_image: uiNewPixmapImage(w, h)
22-
}
18+
Image {
19+
ui_image: unsafe { uiNewPixmapImage(w, h) }
2320
}
2421
}
2522

@@ -33,7 +30,16 @@ impl Image {
3330
// uiImageLoadPixmap32Raw(uiImage *img, int x, int y, int width, int height,
3431
// int rowstrideBytes, uiPixmap32Format fmt, void *data);
3532
let img_data = get_image_data(self.ui_image);
36-
uiImageLoadPixmap32Raw(self.ui_image, offset_x, offset_y, w, h, w*4, img_data.fmt, data.as_ptr() as *const c_void);
33+
uiImageLoadPixmap32Raw(
34+
self.ui_image,
35+
offset_x,
36+
offset_y,
37+
w,
38+
h,
39+
w*4,
40+
img_data.fmt,
41+
data.as_ptr() as *const c_void
42+
);
3743
}
3844
}
3945
}
@@ -53,8 +59,6 @@ fn get_image_data(img: *const uiPixmapImage) -> uiImageData {
5359
rowstride: 0,
5460
data: ptr::null_mut(),
5561
};
56-
5762
unsafe { uiPixmapImageGetData(img, &mut d) }
58-
5963
d
6064
}

ui/src/ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! General functions.
22
33
use ffi_utils::{self, Text};
4-
use libc::{c_char, c_int, c_void};
4+
use libc::{c_char, c_void};
55
use std::fmt::{self, Debug, Formatter};
66
use std::ffi::{CStr, CString};
77
use std::mem;

0 commit comments

Comments
 (0)