2016-01-04 14:48:58 +01:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016 Werner Schweer
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2
|
|
|
|
// as published by the Free Software Foundation and appearing in
|
|
|
|
// the file LICENCE.GPL
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#ifndef __SHAPE_H__
|
|
|
|
#define __SHAPE_H__
|
|
|
|
|
|
|
|
namespace Ms {
|
|
|
|
|
2016-05-04 09:54:52 +02:00
|
|
|
#ifndef NDEBUG
|
2016-11-17 09:46:58 +01:00
|
|
|
// #define DEBUG_SHAPES // enable shape debugging
|
2016-05-04 09:54:52 +02:00
|
|
|
#endif
|
2016-01-04 14:48:58 +01:00
|
|
|
|
|
|
|
class Segment;
|
|
|
|
|
2017-12-06 12:03:53 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// ShapeElement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
struct ShapeElement : public QRectF {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
const char* text;
|
|
|
|
void dump() const;
|
|
|
|
ShapeElement(const QRectF& f, const char* t = 0) : QRectF(f), text(t) {}
|
|
|
|
#else
|
|
|
|
ShapeElement(const QRectF& f) : QRectF(f) {}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2016-01-04 14:48:58 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// Shape
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-08-25 19:22:01 +02:00
|
|
|
class Shape : public std::vector<ShapeElement> {
|
2018-09-03 09:54:09 +02:00
|
|
|
// class Shape : std::vector<ShapeElement> {
|
2016-01-04 14:48:58 +01:00
|
|
|
public:
|
2018-12-05 15:34:35 +01:00
|
|
|
enum HorizontalSpacingType {
|
|
|
|
SPACING_GENERAL = 0,
|
|
|
|
SPACING_LYRICS,
|
|
|
|
SPACING_HARMONY,
|
|
|
|
};
|
|
|
|
|
2016-01-04 14:48:58 +01:00
|
|
|
Shape() {}
|
2017-12-06 12:03:53 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
Shape(const QRectF& r, const char* s = 0) { add(r, s); }
|
|
|
|
#else
|
2016-07-20 12:45:34 +02:00
|
|
|
Shape(const QRectF& r) { add(r); }
|
2017-12-06 12:03:53 +01:00
|
|
|
#endif
|
2016-02-06 22:03:43 +01:00
|
|
|
void add(const Shape& s) { insert(end(), s.begin(), s.end()); }
|
2017-12-06 12:03:53 +01:00
|
|
|
#ifndef NDEBUG
|
2018-01-16 13:38:17 +01:00
|
|
|
void add(const QRectF& r, const char* t = 0);
|
2017-12-06 12:03:53 +01:00
|
|
|
#else
|
2016-02-06 22:03:43 +01:00
|
|
|
void add(const QRectF& r) { push_back(r); }
|
2017-12-06 12:03:53 +01:00
|
|
|
#endif
|
2016-03-18 14:35:15 +01:00
|
|
|
void remove(const QRectF&);
|
|
|
|
void remove(const Shape&);
|
2018-02-01 10:37:12 +01:00
|
|
|
|
2018-12-05 15:34:35 +01:00
|
|
|
void addHorizontalSpacing(HorizontalSpacingType type, qreal left, qreal right);
|
|
|
|
|
2016-01-04 14:48:58 +01:00
|
|
|
void translate(const QPointF&);
|
2018-02-01 10:37:12 +01:00
|
|
|
void translateX(qreal);
|
|
|
|
void translateY(qreal);
|
2016-01-04 14:48:58 +01:00
|
|
|
Shape translated(const QPointF&) const;
|
2018-02-01 10:37:12 +01:00
|
|
|
|
2016-01-04 14:48:58 +01:00
|
|
|
qreal minHorizontalDistance(const Shape&) const;
|
|
|
|
qreal minVerticalDistance(const Shape&) const;
|
2016-11-15 16:33:27 +01:00
|
|
|
qreal topDistance(const QPointF&) const;
|
|
|
|
qreal bottomDistance(const QPointF&) const;
|
2016-01-04 14:48:58 +01:00
|
|
|
qreal left() const;
|
|
|
|
qreal right() const;
|
|
|
|
qreal top() const;
|
|
|
|
qreal bottom() const;
|
|
|
|
|
2018-09-11 16:56:50 +02:00
|
|
|
size_t size() const { return std::vector<ShapeElement>::size(); }
|
|
|
|
bool empty() const { return std::vector<ShapeElement>::empty(); }
|
|
|
|
void clear() { std::vector<ShapeElement>::clear(); }
|
2016-01-04 14:48:58 +01:00
|
|
|
|
2016-12-29 13:42:55 +01:00
|
|
|
bool contains(const QPointF&) const;
|
|
|
|
bool intersects(const QRectF& rr) const;
|
2018-11-21 14:34:20 +01:00
|
|
|
bool intersects(const Shape&) const;
|
2018-09-03 09:54:09 +02:00
|
|
|
void paint(QPainter&) const;
|
2016-12-29 13:42:55 +01:00
|
|
|
|
2017-08-02 18:19:08 +02:00
|
|
|
#ifndef NDEBUG
|
2016-01-04 14:48:58 +01:00
|
|
|
void dump(const char*) const;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2016-06-09 13:56:30 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// intersects
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
inline static bool intersects(qreal a, qreal b, qreal c, qreal d)
|
|
|
|
{
|
|
|
|
// return (a >= c && a < d) || (b >= c && b < d) || (a < c && b >= b);
|
|
|
|
// return (std::max(a,b) > std::min(c,d)) && (std::min(a,b) < std::max(c,d));
|
2016-08-17 12:52:35 +02:00
|
|
|
// if we can assume a <= b and c <= d
|
2016-08-29 14:49:59 +02:00
|
|
|
if (a == b || c == d) // zero height
|
|
|
|
return false;
|
2016-06-09 13:56:30 +02:00
|
|
|
return (b > c) && (a < d);
|
|
|
|
}
|
|
|
|
|
2016-01-04 14:48:58 +01:00
|
|
|
#ifdef DEBUG_SHAPES
|
|
|
|
extern void testShapes();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace Ms
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|