summaryrefslogtreecommitdiffstats
path: root/Project/Bus.cpp
blob: c188bebaec14df29b09788dcb08916f11d872c66 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "Bus.h"

Bus::Bus(wxPoint2DDouble position) : Element()
{
    m_width = 100.0;
    m_height = 5.0;
    SetPosition(position);
}
Bus::~Bus() {}
void Bus::Draw(wxPoint2DDouble translation, double scale) const
{
    // Draw selection (behind)
    if(m_selected) {
	    // If the object is selected, the matrix is reset to remove scale effects applied to it, thus keeping the
	    // edges with fixed sizes for all zoom levels.
	    glPushMatrix();
	    glLoadIdentity();
	    // The matrix was reset, so we must use screen coordinates (WorldToScreen).
	    wxPoint2DDouble screenPt = WorldToScreen(translation, scale);
	    glTranslated(screenPt.m_x, screenPt.m_y, 0.0);
	    glRotated(m_angle, 0.0, 0.0, 1.0);
	    glTranslated(-screenPt.m_x, -screenPt.m_y, 0.0);

	    glColor4d(0.0, 0.5, 1.0, 0.5);

	    wxPoint2DDouble pts[4] = {WorldToScreen(translation, scale, -(m_width / 2.0), -(m_height / 2.0)) -
	                                  wxPoint2DDouble(m_borderSize, m_borderSize),
	                              WorldToScreen(translation, scale, -(m_width / 2.0), (m_height / 2.0)) -
	                                  wxPoint2DDouble(m_borderSize, -m_borderSize),
	                              WorldToScreen(translation, scale, (m_width / 2.0), (m_height / 2.0)) -
	                                  wxPoint2DDouble(-m_borderSize, -m_borderSize),
	                              WorldToScreen(translation, scale, (m_width / 2.0), -(m_height / 2.0)) -
	                                  wxPoint2DDouble(-m_borderSize, m_borderSize)};
	    DrawRectangle(pts);
	    glPopMatrix();
	}
    // Draw element (middle)
    // Push the current matrix on stack.
    glPushMatrix();
    // Rotate the matrix around the object position.
    glTranslated(m_position.m_x, m_position.m_y, 0.0);
    glRotated(m_angle, 0.0, 0.0, 1.0);
    glTranslated(-m_position.m_x, -m_position.m_y, 0.0);

    glColor4d(0.0, 0.3, 1.0, 1.0);
    DrawRectangle(m_position, m_width, m_height);
    // Pop the old matrix back.
    glPopMatrix();

    // Draw pickbox (above)
    if(m_showPickbox) {
	    glPushMatrix();
	    glLoadIdentity();

	    wxPoint2DDouble screenPt = WorldToScreen(translation, scale);
	    glTranslated(screenPt.m_x, screenPt.m_y, 0.0);
	    glRotated(m_angle, 0.0, 0.0, 1.0);
	    glTranslated(-screenPt.m_x, -screenPt.m_y, 0.0);

	    wxPoint2DDouble pbPosition[2] = {WorldToScreen(translation, scale, m_width / 2.0),
	                                     WorldToScreen(translation, scale, -m_width / 2.0)};
	    DrawPickbox(pbPosition[0]);
	    DrawPickbox(pbPosition[1]);

	    glPopMatrix();
	}
}
bool Bus::Contains(wxPoint2DDouble position) const
{
    wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle);
    return m_rect.Contains(ptR);
}
int Bus::PickboxContains(wxPoint2DDouble position) const { return 0; }
wxCursor Bus::GetBestPickboxCursor() const
{
    double angle = m_angle;
    while(angle >= 157.5) angle -= 180.0;

    if(angle >= -22.5 && angle < 22.5)
	return wxCursor(wxCURSOR_SIZEWE);
    else if(angle >= 22.5 && angle < 67.5)
	return wxCursor(wxCURSOR_SIZENWSE);
    else if(angle >= 67.5 && angle < 112.5)
	return wxCursor(wxCURSOR_SIZENS);
    else if(angle >= 112.5 && angle < 157.5)
	return wxCursor(wxCURSOR_SIZENESW);

    return wxCursor(wxCURSOR_ARROW);
}
void Bus::MovePickbox(wxPoint2DDouble position, int pickboxID) {}
void Bus::Rotate()
{
    m_angle += 45.0;
    if(m_angle >= 360.0) m_angle = 0.0;
}