Repository navigation
Expand file tree
/
Copy pathDrawIntf.h
More file actions
73 lines (54 loc) · 3.19 KB
/
Copy pathDrawIntf.h
File metadata and controls
73 lines (54 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//-----------------------------------------------------------------------------
// This file is part of the the QParser2 project. You can find the complete
// project here: https://github.com/robdunn4/QSpice/
//-----------------------------------------------------------------------------
/*
* DrawIntf.h -- Interface for drawable schematic items.
*
* Drawable Item* classes inherit from both ItemBase and DrawIntf.
* Non-drawable items (e.g., ItemDesc, ItemLib) inherit ItemBase only.
*
* This class has no knowledge of QSpice parsing internals -- it defines
* only the visual/spatial contract.
*/
#pragma once
#include "DrawUtils.h" // for Point and Rect
class DrawIntf {
public:
virtual ~DrawIntf() = default;
// Non-assignable; ItemBase owns copy/clone semantics
DrawIntf &operator=(const DrawIntf &) = delete;
// ── Spatial ──────────────────────────────────────────────────────────────
/// Axis-aligned bounding box in schematic (canvas) coordinates.
[[nodiscard]] virtual Rect getRect() const noexcept = 0;
/// Centre of bounding box. Default derives from getRect().
[[nodiscard]] virtual Point getCenter() const noexcept;
/// True if bounding box contains p. Override for non-rectangular shapes.
[[nodiscard]] virtual bool contains(Point p) const noexcept;
/// True if bounding box overlaps r.
[[nodiscard]] virtual bool intersects(Rect r) const noexcept;
// ── Transform ────────────────────────────────────────────────────────────
/// Reference (anchor) position -- typically pt1 in the parsed item.
[[nodiscard]] virtual Point getPosition() const noexcept = 0;
/// Reposition the item. Concrete class updates its ArgPoint members.
/// Implementations should preserve shape size (move pt1 and pt2 together).
virtual void moveTo(Point p) noexcept = 0;
/// Shift by delta. Default calls moveTo(getPosition() + delta).
virtual void moveBy(Point delta) noexcept;
// ── Hit testing ──────────────────────────────────────────────────────────
/// Pixel-precise hit test. Default delegates to contains().
/// Override for hollow shapes (ellipse outlines, etc.).
[[nodiscard]] virtual bool hitTest(Point p) const noexcept;
// ── Visibility ───────────────────────────────────────────────────────────
/// Whether the item is currently rendered. Default: true.
[[nodiscard]] virtual bool isVisible() const noexcept;
/// Show/hide the item.
virtual void setVisible(bool vis) noexcept;
// ── Rendering (signature deferred until canvas type is decided) ──────────
// virtual void draw(...) = 0;
protected:
DrawIntf() = default;
DrawIntf(const DrawIntf &) = default; // for derived class copy constructors
private:
bool visible_ = true;
};