Compare commits

..

No commits in common. "9625eb16183b5beb6bbbfe0684d2cb2b3a11ac12" and "8fb49b8929e01a668c7cadb612fa232052dea9cc" have entirely different histories.

7 changed files with 16 additions and 281 deletions

View File

@ -30,9 +30,8 @@ To compile, run `cargo build -p maraiah-leela`.
`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
compilation script and the bundle script. You will need CMake as well. The
runtime dependencies are Qt5's Core, GUI, and Widgets libraries, and a C++
runtime.
compilation script and the bundle script. The 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
`cargo build -p maraiah-tycho`. If you wish to create a Macintosh Application

View File

@ -33,7 +33,6 @@ add_library(
cc/mapprops.cc
cc/mapview.cc
cc/menu.cc
cc/paint.cc
cc/project.cc
cc/tycho.h
cc/utility.cc

View File

@ -47,9 +47,8 @@ public:
protected:
void paintEvent(QPaintEvent *event) override
{
QPainter paint{this};
paint.fillRect(QRectF(0, 0, width(), height()), QColor(0, 0, 0, 255));
drawView(static_cast<void *>(&paint));
QPainter painter{this};
drawView(static_cast<void *>(&painter));
}
};

View File

@ -14,4 +14,12 @@ MapView::~MapView()
dbgPrintFunc();
}
// TODO: move to paint.cc
extern "C" {
void paint_point(QPainter *paint, int x, int y)
{
paint->drawPoint(x, y);
}
}
// EOF

View File

@ -1,111 +0,0 @@
#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,171 +1,24 @@
//! C++ functions.
#![allow(dead_code)]
use maraiah::ffi;
mod static_ffi {
use maraiah::ffi;
#[repr(C)]
pub struct Int2 {
pub x: i16,
pub y: i16,
}
pub type QPainter = ffi::c_void;
extern "C" {
pub fn critical_msg(title: ffi::NT, msg: ffi::NT);
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 fn paint_point(paint: *mut QPainter, x: ffi::c_int, y: ffi::c_int);
}
}
pub use static_ffi::{Int2, QPainter};
pub use static_ffi::QPainter;
pub fn paint_arc(paint: *mut QPainter,
x: i16,
y: i16,
w: i16,
h: i16,
t: i16,
p: i16)
pub fn paint_point(paint: *mut QPainter, x: i32, y: i32)
{
unsafe {
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);
static_ffi::paint_point(paint, x.into(), y.into());
}
}

View File

@ -20,19 +20,7 @@ impl IMapViewTrait for IMapView
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_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");
}
}