Compare commits

...

6 Commits

12 changed files with 100 additions and 83 deletions

View File

@ -23,9 +23,9 @@ To compile:
If you wish to create a Macintosh Application Bundle, run:
`tools/bundle`
`tools/bundle Tycho <path-to-executable>`
This will also create an installer DMG. If you don't want to create an installer
and just want the app, run:
`env NO_DMG=1 tools/bundle`
`env NO_DMG=1 tools/bundle Tycho <path-to-executable>`

View File

@ -623,6 +623,14 @@ define_fixed_types! {
struct FixedLong(i64, 8) : u64, i128, 32; fixed_long_tests
}
impl FixedLong
{
/// Creates a value of this type from a `Unit`.
#[inline]
pub fn from_unit(n: Unit) -> Self {Self(i64::from(n.to_bits()) << 22)}
}
#[test]
#[should_panic]
#[allow(unused_must_use)]

View File

@ -152,6 +152,7 @@ impl EntryData
}
/// The abstract type of an entry.
#[derive(Debug, Eq, PartialEq)]
pub enum EntryType {
Other,
Map,

View File

@ -22,7 +22,7 @@ pub fn read(b: &[u8]) -> ResultS<(Endpoint, usize)>
/// Converts a vector of `Endpoint`s to a vector of `Point`s.
pub fn to_pnts(v: &[Endpoint]) -> Vec<pnts::Point>
{
v.iter().map(|p| p.pos).collect()
v.iter().map(|p| p.into()).collect()
}
/// A pre-processed point in world-space.

View File

@ -1,5 +1,6 @@
//! `Point` type.
use super::epnt;
use crate::{err::*, fixed::Unit};
/// Reads a `Point` object.
@ -27,6 +28,21 @@ pub fn write_o(v: Point) -> Vec<u8>
/// Reads a `PNTS` chunk.
pub fn read(b: &[u8]) -> ResultS<(Point, usize)> {Ok((read_o(b)?, 4))}
impl From<&Point> for Point
{
fn from(pnts: &Point) -> Self {*pnts}
}
impl From<epnt::Endpoint> for Point
{
fn from(epnt: epnt::Endpoint) -> Self {epnt.pos}
}
impl From<&epnt::Endpoint> for Point
{
fn from(epnt: &epnt::Endpoint) -> Self {epnt.pos}
}
/// A point in world-space.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]

View File

@ -38,6 +38,7 @@ function comp_icon -a f i
wait rsvg-convert
compress "$out_s"
compress "$out_h"
echo "OK $out"
end
for f in resources/mini/*.svg

View File

@ -5,6 +5,8 @@ IProjectView::IProjectView(Project *parent) :
m_model(parent->model())
{
setMinimumSize(320, 240);
connect(m_model, SIGNAL(selected(quint16)), this, SLOT(update()));
}
void IProjectView::paintEvent(QPaintEvent *event)

View File

@ -34,7 +34,7 @@ public slots:
signals:
void dirtyChanged(bool dirty);
void deselected();
void selected(std::uint16_t index);
void selected(quint16 index);
};
class IProjectView : public QWidget

View File

@ -30,9 +30,8 @@ void MapModel::select(QModelIndex const &index)
QVariant MapModel::data(const QModelIndex &index, int role) const
{
switch(role) {
case Qt::DecorationRole: {
case Qt::DecorationRole:
return QVariant::fromValue(::getIcon(propIcon(index.row())));
}
default:
return IMapModel::data(index, role);
}

View File

@ -2,58 +2,47 @@
extern "C" {
struct int2 {
std::int16_t x, y;
qint16 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)
qint16 x,
qint16 y,
qint16 w,
qint16 h,
qint16 t,
qint16 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)
qint16 x,
qint16 y,
qint16 w,
qint16 h,
qint16 t,
qint16 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)
void paint_ellipse(QPainter *paint, qint16 x, qint16 y, qint16 w, qint16 h)
{
paint->drawEllipse(x, y, w, h);
}
void paint_image(QPainter *paint,
std::int16_t x,
std::int16_t y,
char const *fname)
void paint_image(QPainter *paint, qint16 x, qint16 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)
void paint_line(QPainter *paint, qint16 x1, qint16 y1, qint16 x2, qint16 y2)
{
paint->drawLine(x1, y1, x2, y2);
}
void paint_point(QPainter *paint, std::int16_t x, std::int16_t y)
void paint_point(QPainter *paint, qint16 x, qint16 y)
{
paint->drawPoint(x, y);
}
@ -69,39 +58,28 @@ extern "C" {
paint->drawPolygon(poly);
}
void paint_rect(QPainter *paint,
std::int16_t x,
std::int16_t y,
std::int16_t w,
std::int16_t h)
void paint_rect(QPainter *paint, qint16 x, qint16 y, qint16 w, qint16 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)
qint16 x,
qint16 y,
qint16 w,
qint16 h,
qint16 r1,
qint16 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)
void paint_text(QPainter *paint, qint16 x, qint16 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)
void paint_fg(QPainter *paint, quint8 r, quint8 g, quint8 b, quint8 a)
{
QColor color{r, g, b, a};
paint->setPen(color);

View File

@ -1,7 +1,6 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <optional>
#include <vector>
@ -28,7 +27,7 @@
class Project;
using byte = std::uint8_t;
using byte = quint8;
class MapModel final : public IMapModel
{
@ -143,12 +142,12 @@ void dbgPrint([[maybe_unused]] char const *fmt, [[maybe_unused]] VA &&...va)
#define dbgPrintFunc() dbgPrint("%s", __func__)
constexpr
std::uint32_t fourCC(byte a, byte b, byte c, byte d)
quint32 fourCC(byte a, byte b, byte c, byte d)
{
return (static_cast<std::uint32_t>(a) << 24) |
(static_cast<std::uint32_t>(b) << 16) |
(static_cast<std::uint32_t>(c) << 8) |
static_cast<std::uint32_t>(d);
return (static_cast<quint32>(a) << 24) |
(static_cast<quint32>(b) << 16) |
(static_cast<quint32>(c) << 8) |
static_cast<quint32>(d);
}
QIcon getIcon(QString const &name);

View File

@ -1,9 +1,36 @@
//! Map model.
use super::qobj::*;
use maraiah::{backtrace, err::*, map::{self, data::*}};
use maraiah::{backtrace, err::*, fixed, map::{self, data::*}};
use crate::cc;
fn to_screen(coord: fixed::Unit) -> i16
{
let long = fixed::FixedLong::from_unit(coord);
(long * 10).integ() as i16
}
fn draw_points<'a, P>(paint: *mut cc::QPainter, pnts: &'a [P])
where P: Into<map::pnts::Point>,
map::pnts::Point: From<&'a P>
{
for p in pnts.iter() {
let p: map::pnts::Point = p.into();
cc::paint_point(paint, to_screen(p.x), to_screen(p.y));
}
}
fn draw_map(paint: *mut cc::QPainter, entry: &EntryData)
{
cc::paint_fg(paint, 0, 255, 0, 255);
if let Some(pnts) = &entry.pnts {
draw_points(paint, pnts.as_slice());
} else if let Some(epnt) = &entry.epnt {
draw_points(paint, epnt.as_slice());
}
}
impl IMapModel
{
pub fn open_map(path: String) -> ResultS<EntryDataMap>
@ -61,10 +88,6 @@ impl IMapModelTrait for IMapModel
/// Opens the map file at `path`.
fn open(&mut self, path: String) -> bool
{
if cfg!(debug_assertions) {
eprintln!("opening project: {}", &path);
}
match Self::open_map(path) {
Ok(map) => {
self.map = map;
@ -107,28 +130,18 @@ impl IMapModelTrait for IMapModel
fn select(&mut self, index: u16)
{
if cfg!(debug_assertions) {
eprintln!("selecting map {}", index);
}
self.selected = Some(index);
}
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");
if let Some(selected) = self.selected {
if let Some(entry) = self.map.get(&selected) {
if entry.get_type() == EntryType::Map {
draw_map(paint, entry);
}
}
}
}
}