tycho: add painter API
parent
74e11a727f
commit
0a0b6f9c5f
|
@ -33,6 +33,7 @@ add_library(
|
||||||
cc/mapprops.cc
|
cc/mapprops.cc
|
||||||
cc/mapview.cc
|
cc/mapview.cc
|
||||||
cc/menu.cc
|
cc/menu.cc
|
||||||
|
cc/paint.cc
|
||||||
cc/project.cc
|
cc/project.cc
|
||||||
cc/tycho.h
|
cc/tycho.h
|
||||||
cc/utility.cc
|
cc/utility.cc
|
||||||
|
|
|
@ -47,8 +47,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override
|
void paintEvent(QPaintEvent *event) override
|
||||||
{
|
{
|
||||||
QPainter painter{this};
|
QPainter paint{this};
|
||||||
drawView(static_cast<void *>(&painter));
|
paint.fillRect(QRectF(0, 0, width(), height()), QColor(0, 0, 0, 255));
|
||||||
|
drawView(static_cast<void *>(&paint));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,4 @@ MapView::~MapView()
|
||||||
dbgPrintFunc();
|
dbgPrintFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move to paint.cc
|
|
||||||
extern "C" {
|
|
||||||
void paint_point(QPainter *paint, int x, int y)
|
|
||||||
{
|
|
||||||
paint->drawPoint(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
#include "tycho.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
struct int2 {
|
||||||
|
std::int16_t x, y;
|
||||||
|
};
|
||||||
|
|
||||||
|
void paint_arc(QPainter *paint,
|
||||||
|
std::int16_t x,
|
||||||
|
std::int16_t y,
|
||||||
|
std::int16_t w,
|
||||||
|
std::int16_t h,
|
||||||
|
std::int16_t t,
|
||||||
|
std::int16_t p)
|
||||||
|
{
|
||||||
|
paint->drawArc(x, y, w, h, t, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_chord(QPainter *paint,
|
||||||
|
std::int16_t x,
|
||||||
|
std::int16_t y,
|
||||||
|
std::int16_t w,
|
||||||
|
std::int16_t h,
|
||||||
|
std::int16_t t,
|
||||||
|
std::int16_t p)
|
||||||
|
{
|
||||||
|
paint->drawChord(x, y, w, h, t, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_ellipse(QPainter *paint,
|
||||||
|
std::int16_t x,
|
||||||
|
std::int16_t y,
|
||||||
|
std::int16_t w,
|
||||||
|
std::int16_t h)
|
||||||
|
{
|
||||||
|
paint->drawEllipse(x, y, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_image(QPainter *paint,
|
||||||
|
std::int16_t x,
|
||||||
|
std::int16_t y,
|
||||||
|
char const *fname)
|
||||||
|
{
|
||||||
|
paint->drawImage(x, y, QImage(QString(fname)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_line(QPainter *paint,
|
||||||
|
std::int16_t x1,
|
||||||
|
std::int16_t y1,
|
||||||
|
std::int16_t x2,
|
||||||
|
std::int16_t y2)
|
||||||
|
{
|
||||||
|
paint->drawLine(x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_point(QPainter *paint, std::int16_t x, std::int16_t y)
|
||||||
|
{
|
||||||
|
paint->drawPoint(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_polygon(QPainter *paint, int2 const *points, std::size_t len)
|
||||||
|
{
|
||||||
|
QPolygon poly;
|
||||||
|
|
||||||
|
for(auto i = 0; i < len; i++) {
|
||||||
|
poly << QPoint(points[i].x, points[i].y);
|
||||||
|
}
|
||||||
|
|
||||||
|
paint->drawPolygon(poly);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_rect(QPainter *paint,
|
||||||
|
std::int16_t x,
|
||||||
|
std::int16_t y,
|
||||||
|
std::int16_t w,
|
||||||
|
std::int16_t h)
|
||||||
|
{
|
||||||
|
paint->drawRect(x, y, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_squircle(QPainter *paint,
|
||||||
|
std::int16_t x,
|
||||||
|
std::int16_t y,
|
||||||
|
std::int16_t w,
|
||||||
|
std::int16_t h,
|
||||||
|
std::int16_t r1,
|
||||||
|
std::int16_t r2)
|
||||||
|
{
|
||||||
|
paint->drawRoundedRect(x, y, w, h, r1, r2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_text(QPainter *paint,
|
||||||
|
std::int16_t x,
|
||||||
|
std::int16_t y,
|
||||||
|
char const *text)
|
||||||
|
{
|
||||||
|
paint->drawText(x, y, QString(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint_fg(QPainter *paint,
|
||||||
|
std::uint8_t r,
|
||||||
|
std::uint8_t g,
|
||||||
|
std::uint8_t b,
|
||||||
|
std::uint8_t a)
|
||||||
|
{
|
||||||
|
QColor color{r, g, b, a};
|
||||||
|
paint->setPen(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EOF
|
|
@ -1,24 +1,171 @@
|
||||||
//! C++ functions.
|
//! C++ functions.
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use maraiah::ffi;
|
use maraiah::ffi;
|
||||||
|
|
||||||
mod static_ffi {
|
mod static_ffi {
|
||||||
use maraiah::ffi;
|
use maraiah::ffi;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct Int2 {
|
||||||
|
pub x: i16,
|
||||||
|
pub y: i16,
|
||||||
|
}
|
||||||
|
|
||||||
pub type QPainter = ffi::c_void;
|
pub type QPainter = ffi::c_void;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn critical_msg(title: ffi::NT, msg: ffi::NT);
|
pub fn critical_msg(title: ffi::NT, msg: ffi::NT);
|
||||||
pub fn paint_point(paint: *mut QPainter, x: ffi::c_int, y: ffi::c_int);
|
|
||||||
|
pub fn paint_arc(paint: *mut QPainter,
|
||||||
|
x: i16,
|
||||||
|
y: i16,
|
||||||
|
w: i16,
|
||||||
|
h: i16,
|
||||||
|
t: i16,
|
||||||
|
p: i16);
|
||||||
|
|
||||||
|
pub fn paint_chord(paint: *mut QPainter,
|
||||||
|
x: i16,
|
||||||
|
y: i16,
|
||||||
|
w: i16,
|
||||||
|
h: i16,
|
||||||
|
t: i16,
|
||||||
|
p: i16);
|
||||||
|
|
||||||
|
pub fn paint_ellipse(paint: *mut QPainter,
|
||||||
|
x: i16,
|
||||||
|
y: i16,
|
||||||
|
w: i16,
|
||||||
|
h: i16);
|
||||||
|
|
||||||
|
pub fn paint_image(paint: *mut QPainter, x: i16, y: i16, fname: ffi::NT);
|
||||||
|
|
||||||
|
pub fn paint_line(paint: *mut QPainter,
|
||||||
|
x1: i16,
|
||||||
|
y1: i16,
|
||||||
|
x2: i16,
|
||||||
|
y2: i16);
|
||||||
|
|
||||||
|
pub fn paint_point(paint: *mut QPainter, x: i16, y: i16);
|
||||||
|
|
||||||
|
pub fn paint_polygon(paint: *mut QPainter,
|
||||||
|
points: *const Int2,
|
||||||
|
len: usize);
|
||||||
|
|
||||||
|
pub fn paint_rect(paint: *mut QPainter, x: i16, y: i16, w: i16, h: i16);
|
||||||
|
|
||||||
|
pub fn paint_squircle(paint: *mut QPainter,
|
||||||
|
x: i16,
|
||||||
|
y: i16,
|
||||||
|
w: i16,
|
||||||
|
h: i16,
|
||||||
|
xr: i16,
|
||||||
|
yr: i16);
|
||||||
|
|
||||||
|
pub fn paint_text(paint: *mut QPainter, x: i16, y: i16, text: ffi::NT);
|
||||||
|
pub fn paint_fg(paint: *mut QPainter, r: u8, g: u8, b: u8, a: u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use static_ffi::QPainter;
|
pub use static_ffi::{Int2, QPainter};
|
||||||
|
|
||||||
pub fn paint_point(paint: *mut QPainter, x: i32, y: i32)
|
pub fn paint_arc(paint: *mut QPainter,
|
||||||
|
x: i16,
|
||||||
|
y: i16,
|
||||||
|
w: i16,
|
||||||
|
h: i16,
|
||||||
|
t: i16,
|
||||||
|
p: i16)
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
static_ffi::paint_point(paint, x.into(), y.into());
|
static_ffi::paint_arc(paint, x, y, w, h, t, p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_chord(paint: *mut QPainter,
|
||||||
|
x: i16,
|
||||||
|
y: i16,
|
||||||
|
w: i16,
|
||||||
|
h: i16,
|
||||||
|
t: i16,
|
||||||
|
p: i16)
|
||||||
|
{
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_chord(paint, x, y, w, h, t, p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_ellipse(paint: *mut QPainter, x: i16, y: i16, w: i16, h: i16)
|
||||||
|
{
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_ellipse(paint, x, y, w, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_image(paint: *mut QPainter, x: i16, y: i16, fname: &str)
|
||||||
|
{
|
||||||
|
let fname = ffi::CString::new(fname).unwrap();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_image(paint, x, y, fname.as_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_line(paint: *mut QPainter, x1: i16, y1: i16, x2: i16, y2: i16)
|
||||||
|
{
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_line(paint, x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_point(paint: *mut QPainter, x: i16, y: i16)
|
||||||
|
{
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_point(paint, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_polygon(paint: *mut QPainter, points: &[Int2])
|
||||||
|
{
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_polygon(paint, points.as_ptr(), points.len());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_rect(paint: *mut QPainter, x: i16, y: i16, w: i16, h: i16)
|
||||||
|
{
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_rect(paint, x, y, w, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_squircle(paint: *mut QPainter,
|
||||||
|
x: i16,
|
||||||
|
y: i16,
|
||||||
|
w: i16,
|
||||||
|
h: i16,
|
||||||
|
r1: i16,
|
||||||
|
r2: i16)
|
||||||
|
{
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_squircle(paint, x, y, w, h, r1, r2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_text(paint: *mut QPainter, x: i16, y: i16, text: &str)
|
||||||
|
{
|
||||||
|
let text = ffi::CString::new(text).unwrap();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_text(paint, x, y, text.as_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paint_fg(paint: *mut QPainter, r: u8, g: u8, b: u8, a: u8)
|
||||||
|
{
|
||||||
|
unsafe {
|
||||||
|
static_ffi::paint_fg(paint, r, g, b, a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue