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: 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 This will also create an installer DMG. If you don't want to create an installer
and just want the app, run: 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 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] #[test]
#[should_panic] #[should_panic]
#[allow(unused_must_use)] #[allow(unused_must_use)]

View File

@ -152,6 +152,7 @@ impl EntryData
} }
/// The abstract type of an entry. /// The abstract type of an entry.
#[derive(Debug, Eq, PartialEq)]
pub enum EntryType { pub enum EntryType {
Other, Other,
Map, 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. /// Converts a vector of `Endpoint`s to a vector of `Point`s.
pub fn to_pnts(v: &[Endpoint]) -> Vec<pnts::Point> 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. /// A pre-processed point in world-space.

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ public slots:
signals: signals:
void dirtyChanged(bool dirty); void dirtyChanged(bool dirty);
void deselected(); void deselected();
void selected(std::uint16_t index); void selected(quint16 index);
}; };
class IProjectView : public QWidget 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 QVariant MapModel::data(const QModelIndex &index, int role) const
{ {
switch(role) { switch(role) {
case Qt::DecorationRole: { case Qt::DecorationRole:
return QVariant::fromValue(::getIcon(propIcon(index.row()))); return QVariant::fromValue(::getIcon(propIcon(index.row())));
}
default: default:
return IMapModel::data(index, role); return IMapModel::data(index, role);
} }

View File

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

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <iostream> #include <iostream>
#include <optional> #include <optional>
#include <vector> #include <vector>
@ -28,7 +27,7 @@
class Project; class Project;
using byte = std::uint8_t; using byte = quint8;
class MapModel final : public IMapModel 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__) #define dbgPrintFunc() dbgPrint("%s", __func__)
constexpr 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) | return (static_cast<quint32>(a) << 24) |
(static_cast<std::uint32_t>(b) << 16) | (static_cast<quint32>(b) << 16) |
(static_cast<std::uint32_t>(c) << 8) | (static_cast<quint32>(c) << 8) |
static_cast<std::uint32_t>(d); static_cast<quint32>(d);
} }
QIcon getIcon(QString const &name); QIcon getIcon(QString const &name);

View File

@ -1,9 +1,36 @@
//! Map model. //! Map model.
use super::qobj::*; use super::qobj::*;
use maraiah::{backtrace, err::*, map::{self, data::*}}; use maraiah::{backtrace, err::*, fixed, map::{self, data::*}};
use crate::cc; 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 impl IMapModel
{ {
pub fn open_map(path: String) -> ResultS<EntryDataMap> pub fn open_map(path: String) -> ResultS<EntryDataMap>
@ -61,10 +88,6 @@ impl IMapModelTrait for IMapModel
/// Opens the map file at `path`. /// Opens the map file at `path`.
fn open(&mut self, path: String) -> bool fn open(&mut self, path: String) -> bool
{ {
if cfg!(debug_assertions) {
eprintln!("opening project: {}", &path);
}
match Self::open_map(path) { match Self::open_map(path) {
Ok(map) => { Ok(map) => {
self.map = map; self.map = map;
@ -107,28 +130,18 @@ impl IMapModelTrait for IMapModel
fn select(&mut self, index: u16) fn select(&mut self, index: u16)
{ {
if cfg!(debug_assertions) {
eprintln!("selecting map {}", index);
}
self.selected = Some(index); self.selected = Some(index);
} }
fn draw_view(&self, paint: *mut cc::QPainter) fn draw_view(&self, paint: *mut cc::QPainter)
{ {
cc::paint_fg(paint, 0, 255, 0, 255); if let Some(selected) = self.selected {
cc::paint_arc(paint, 30, 30, 100, 100, 77, 440); if let Some(entry) = self.map.get(&selected) {
cc::paint_chord(paint, 50, 50, 100, 100, 77, 440); if entry.get_type() == EntryType::Map {
cc::paint_ellipse(paint, 80, 80, 30, 30); draw_map(paint, entry);
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");
} }
} }