Skip to content

Commit 122c39b

Browse files
committed
Add draw image functionality from custom libui branch
1 parent 4fdb5dc commit 122c39b

File tree

6 files changed

+24
-112
lines changed

6 files changed

+24
-112
lines changed

ui-sys/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ extern {
743743
}
744744

745745

746-
pub enum uiImage {}
746+
pub enum uiPixmapImage {}
747747
pub type uiPixmap32Format = u32;
748748

749749
#[repr(C)]
@@ -757,20 +757,20 @@ pub struct uiImageData {
757757

758758
#[link(name = "ui")]
759759
extern {
760-
pub fn uiNewImage(width: c_int, height: c_int) -> *mut uiImage;
761-
pub fn uiFreeImage(img: *mut uiImage);
762-
pub fn uiImageGetFormat(img: *mut uiImage) -> uiPixmap32Format;
763-
pub fn uiImageGetData(img: *const uiImage, data: *mut uiImageData);
764-
pub fn uiImageLoadPixmap32Raw(img: *mut uiImage,
760+
pub fn uiNewPixmapImage(width: c_int, height: c_int) -> *mut uiPixmapImage;
761+
pub fn uiFreePixmapImage(img: *mut uiPixmapImage);
762+
pub fn uiPixmapImageGetFormat(img: *mut uiPixmapImage) -> uiPixmap32Format;
763+
pub fn uiPixmapImageGetData(img: *const uiPixmapImage, data: *mut uiImageData);
764+
pub fn uiImageLoadPixmap32Raw(img: *mut uiPixmapImage,
765765
x: c_int,
766766
y: c_int,
767767
width: c_int,
768768
height: c_int,
769769
rowstrideBytes: c_int,
770770
fmt: uiPixmap32Format,
771771
data: *const c_void);
772-
pub fn uiDrawImage(c: *mut uiDrawContext,
773-
x: c_double,
774-
y: c_double,
775-
img: *const uiImage);
772+
pub fn uiDrawPixmapImage(c: *mut uiDrawContext,
773+
x: c_double,
774+
y: c_double,
775+
img: *const uiPixmapImage);
776776
}

ui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ui"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Patrick Walton <[email protected]>"]
55

66
[dependencies]

ui/examples/image.rs

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
33
extern crate ui;
44

5-
use ui::{BoxControl, Button, Checkbox, ColorButton, Combobox, DateTimePicker, Entry};
6-
use ui::{FontButton, Group, InitOptions, Label, Menu, MenuItem, ProgressBar, RadioButtons};
7-
use ui::{Separator, Slider, Spinbox, Tab, Window};
5+
use ui::{BoxControl, Window, InitOptions};
86
use ui::{Image, Area, AreaHandler, AreaKeyEvent, AreaDrawParams};
97

108
struct ImageAreaHandler {
@@ -25,21 +23,6 @@ impl AreaHandler for ImageAreaHandler {
2523
}
2624

2725
fn run() {
28-
let menu = Menu::new("File");
29-
menu.append_item("Open").on_clicked(Box::new(open_clicked));
30-
menu.append_item("Save").on_clicked(Box::new(save_clicked));
31-
32-
let menu = Menu::new("Edit");
33-
menu.append_check_item("Checkable Item");
34-
menu.append_separator();
35-
let item = menu.append_item("Disabled Item");
36-
item.disable();
37-
menu.append_preferences_item();
38-
39-
let menu = Menu::new("Help");
40-
menu.append_item("Help");
41-
menu.append_about_item();
42-
4326
let mainwin = Window::new("ui Control Gallery", 640, 480, true);
4427
mainwin.set_margined(true);
4528
mainwin.on_closing(Box::new(|_| {
@@ -51,58 +34,8 @@ fn run() {
5134
vbox.set_padded(true);
5235
mainwin.set_child(vbox.clone().into());
5336

54-
let hbox = BoxControl::new_horizontal();
55-
hbox.set_padded(true);
56-
vbox.append(hbox.clone().into(), true);
57-
58-
let group = Group::new("Basic Controls");
59-
group.set_margined(true);
60-
hbox.append(group.clone().into(), false);
61-
62-
let inner = BoxControl::new_vertical();
63-
inner.set_padded(true);
64-
group.set_child(inner.clone().into());
65-
66-
inner.append(Button::new("Button").into(), false);
67-
inner.append(Checkbox::new("Checkbox").into(), false);
68-
let entry = Entry::new();
69-
entry.set_text("Entry");
70-
inner.append(entry.into(), false);
71-
inner.append(Label::new("Label").into(), false);
72-
inner.append(Separator::new_horizontal().into(), false);
73-
74-
inner.append(DateTimePicker::new_date_picker().into(), false);
75-
inner.append(DateTimePicker::new_time_picker().into(), false);
76-
inner.append(DateTimePicker::new_date_time_picker().into(), false);
77-
78-
inner.append(FontButton::new().into(), false);
79-
inner.append(ColorButton::new().into(), false);
80-
81-
let inner2 = BoxControl::new_vertical();
82-
inner2.set_padded(true);
83-
hbox.append(inner2.clone().into(), true);
84-
85-
let group = Group::new("Numbers");
86-
group.set_margined(true);
87-
inner2.append(group.clone().into(), false);
88-
89-
let inner = BoxControl::new_vertical();
90-
inner.set_padded(true);
91-
group.set_child(inner.clone().into());
92-
93-
let spinbox = Spinbox::new(0, 100);
94-
spinbox.on_changed(Box::new(|spinbox| update(spinbox.value())));
95-
inner.append(spinbox.into(), false);
96-
97-
let slider = Slider::new(0, 100);
98-
slider.on_changed(Box::new(|slider| update(slider.value())));
99-
inner.append(slider.into(), false);
100-
101-
let progress_bar = ProgressBar::new();
102-
inner.append(progress_bar.into(), false);
103-
10437
let area = Area::new(Box::new(ImageAreaHandler {data: vec![0xff123456;100*100]}));
105-
inner2.append(area.into(),false);
38+
vbox.append(area.into(),false);
10639

10740
mainwin.show();
10841
ui::main();
@@ -113,24 +46,3 @@ pub fn main() {
11346
run();
11447
ui::uninit();
11548
}
116-
117-
fn open_clicked(_: &MenuItem, mainwin: &Window) {
118-
match ui::open_file(mainwin) {
119-
Some(filename) => ui::msg_box(mainwin, "File selected", &*filename),
120-
None => ui::msg_box_error(mainwin, "No file selected", "Don't be alarmed!"),
121-
}
122-
}
123-
124-
fn save_clicked(_: &MenuItem, mainwin: &Window) {
125-
match ui::open_file(mainwin) {
126-
Some(filename) => {
127-
ui::msg_box(mainwin, "File selected (don't worry, it's still there)", &*filename)
128-
}
129-
None => ui::msg_box_error(mainwin, "No file selected", "Don't be alarmed!"),
130-
}
131-
}
132-
133-
fn update(_: i64) {
134-
// TODO(pcwalton)
135-
}
136-

ui/src/draw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Context {
9090

9191
pub fn draw_image(&self, x: f64, y: f64, img: &image::Image) {
9292
unsafe {
93-
ui_sys::uiDrawImage(self.ui_draw_context, x, y, img.as_ui_draw_image())
93+
ui_sys::uiDrawPixmapImage(self.ui_draw_context, x, y, img.as_ui_draw_image())
9494
}
9595
}
9696
}

ui/src/image.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use libc::c_void;
2-
use ui_sys::{self, uiImage, uiImageData, uiNewImage,
3-
uiFreeImage, uiImageGetFormat, uiImageGetData,
4-
uiImageLoadPixmap32Raw, uiDrawImage};
2+
use ui_sys::{self, uiPixmapImage, uiImageData, uiNewPixmapImage,
3+
uiFreePixmapImage, uiPixmapImageGetFormat, uiPixmapImageGetData,
4+
uiImageLoadPixmap32Raw, uiDrawPixmapImage};
55
use ui_sys::uiDrawContext;
66

77
pub struct Image {
8-
ui_image: *mut uiImage
8+
ui_image: *mut uiPixmapImage
99
}
1010

1111
// #define uiPixmap32FormatOffsets(a,r,g,b) ((a) << 0 | (r) << 2 | (g) << 4 | (b) << 6)
@@ -18,13 +18,13 @@ impl Image {
1818
pub fn new(w: i32, h: i32) -> Image {
1919
unsafe {
2020
Image {
21-
ui_image: uiNewImage(w, h)
21+
ui_image: uiNewPixmapImage(w, h)
2222
}
2323
}
2424
}
2525

2626
#[inline]
27-
pub fn as_ui_draw_image(&self) -> *const uiImage {
27+
pub fn as_ui_draw_image(&self) -> *const uiPixmapImage {
2828
self.ui_image
2929
}
3030

@@ -40,11 +40,11 @@ impl Image {
4040

4141
impl Drop for Image {
4242
fn drop(&mut self) {
43-
unsafe { uiFreeImage(self.ui_image) };
43+
unsafe { uiFreePixmapImage(self.ui_image) };
4444
}
4545
}
4646

47-
fn get_image_data(img: *const uiImage) -> uiImageData {
47+
fn get_image_data(img: *const uiPixmapImage) -> uiImageData {
4848
use std::ptr;
4949
let mut d = uiImageData {
5050
fmt: 0,
@@ -54,7 +54,7 @@ fn get_image_data(img: *const uiImage) -> uiImageData {
5454
data: ptr::null_mut(),
5555
};
5656

57-
unsafe { uiImageGetData(img, &mut d) }
57+
unsafe { uiPixmapImageGetData(img, &mut d) }
5858

5959
d
6060
}

0 commit comments

Comments
 (0)