Compare commits

...

3 Commits

Author SHA1 Message Date
an 9625eb1618 tycho: add painter test 2019-07-12 12:02:53 -04:00
an 0a0b6f9c5f tycho: add painter API 2019-07-12 12:02:46 -04:00
an 74e11a727f specify that CMake is needed for compiling Tycho 2019-07-12 12:02:09 -04:00
7 changed files with 281 additions and 16 deletions

View File

@ -30,8 +30,9 @@ To compile, run `cargo build -p maraiah-leela`.
`maraiah-tycho` requires `librsvg` and `pigz` to compile the icons. `librsvg` is `maraiah-tycho` requires `librsvg` and `pigz` to compile the icons. `librsvg` is
also required for the bundle script.`fish` is also required for the icon also required for the bundle script.`fish` is also required for the icon
compilation script and the bundle script. The runtime dependencies are Qt5's compilation script and the bundle script. You will need CMake as well. The
Core, GUI, and Widgets libraries, and a C++ runtime. runtime dependencies are Qt5's Core, GUI, and Widgets libraries, and a C++
runtime.
To compile, `cd` to `tycho`, run `./gen_icons.fish`, and then compile with To compile, `cd` to `tycho`, run `./gen_icons.fish`, and then compile with
`cargo build -p maraiah-tycho`. If you wish to create a Macintosh Application `cargo build -p maraiah-tycho`. If you wish to create a Macintosh Application

View File

@ -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

View File

@ -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));
} }
}; };

View File

@ -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

111
tycho/cc/paint.cc Normal file
View File

@ -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

View File

@ -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);
} }
} }

View File

@ -20,7 +20,19 @@ impl IMapViewTrait for IMapView
fn draw_view(&self, paint: *mut cc::QPainter) fn draw_view(&self, paint: *mut cc::QPainter)
{ {
cc::paint_fg(paint, 0, 255, 0, 255);
cc::paint_arc(paint, 30, 30, 100, 100, 77, 440);
cc::paint_chord(paint, 50, 50, 100, 100, 77, 440);
cc::paint_ellipse(paint, 80, 80, 30, 30);
cc::paint_image(paint, 200, 10, ":/tycho/images/tycho1.png");
cc::paint_line(paint, 100, 60, 140, 100);
cc::paint_point(paint, 20, 20); cc::paint_point(paint, 20, 20);
cc::paint_polygon(paint, &[cc::Int2{x: 250, y: 170},
cc::Int2{x: 270, y: 190},
cc::Int2{x: 230, y: 190}]);
cc::paint_rect(paint, 150, 170, 20, 20);
cc::paint_squircle(paint, 90, 170, 30, 30, 7, 9);
cc::paint_text(paint, 50, 50, "hello, world");
} }
} }