Skip to content

Commit 9b5e4dc

Browse files
committed
#187 Add new Track Painter
1 parent 2263103 commit 9b5e4dc

File tree

4 files changed

+235
-16
lines changed

4 files changed

+235
-16
lines changed

src/main/guru.py

+44-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from PyQt6.QtCore import Qt
44
from PyQt6.QtGui import QColor
5-
from PyQt6.QtWidgets import QMainWindow, QApplication, QProgressBar, QFileDialog
5+
from PyQt6.QtWidgets import QMainWindow, QApplication, QProgressBar, QFileDialog, QVBoxLayout, QLabel, QHBoxLayout
66

77
from src.log.log import Log
88
from src.configuration.config_manager import ConfigManager
@@ -14,6 +14,7 @@
1414
from src.tracks.tracks import get_all_tracks
1515
from src.ui.open_file_dialog import OpenFileDialog
1616
from ui.icons import get_custom_icon
17+
from ui.track_painter import TrackPainter
1718

1819

1920
class MainWindow(QMainWindow):
@@ -58,7 +59,23 @@ def __init__(self):
5859
# Canvas etc. comments TODO
5960

6061
self.canvas = TrackAnalysisCanvas()
61-
self.setCentralWidget(self.canvas)
62+
63+
centre_layout = QHBoxLayout()
64+
centre_layout.addWidget(self.canvas)
65+
66+
analysis_controls_area = QLabel()
67+
analysis_controls_area.setMinimumWidth(100)
68+
analysis_controls_area.setMaximumWidth(100)
69+
centre_layout.addWidget(analysis_controls_area)
70+
71+
centre_widget = QLabel()
72+
centre_widget.setLayout(centre_layout)
73+
74+
self.setCentralWidget(centre_widget)
75+
76+
77+
78+
6279
self.make_status_bar_tall_enough_to_contain_progress_bar()
6380

6481
self.show()
@@ -67,18 +84,33 @@ def __init__(self):
6784

6885
self._tracks = get_all_tracks()
6986
self._current_track = self._tracks["arctic_pro_cw"]
70-
self._current_track.configure_track_canvas(self.canvas)
7187

72-
track_grey = QColor(75, 75, 75)
73-
grid_grey = QColor(45, 45, 45)
7488

75-
self._current_track.draw_track_edges(self.canvas, track_grey)
76-
self._current_track.draw_waypoints(self.canvas, track_grey, 2, 8)
77-
self._current_track.draw_section_highlight(self.canvas, track_grey, 0, 20)
78-
self._current_track.draw_starting_line(self.canvas, track_grey)
79-
self._current_track.draw_sector_dividers(self.canvas, track_grey)
80-
self._current_track.draw_waypoint_labels(self.canvas, track_grey, 9)
81-
self._current_track.draw_grid(self.canvas, grid_grey)
89+
self._track_painter = TrackPainter()
90+
from episode.episode_filter import EpisodeFilter
91+
self._episode_filter = EpisodeFilter()
92+
93+
94+
# Code that will move to the view menu etc.
95+
96+
self._track_painter.set_waypoint_sizes_micro()
97+
self._track_painter.set_track_colour_blue()
98+
self._track_painter.set_grid_back()
99+
self._track_painter.set_waypoint_labels_on()
100+
self._track_painter.set_sectors_on()
101+
102+
## Code that will move to the analyzer
103+
104+
self._current_track.configure_track_canvas(self.canvas)
105+
self._track_painter.draw(self.canvas, self._current_track, self._episode_filter)
106+
107+
# self._current_track.draw_track_edges(self.canvas, track_grey)
108+
# self._current_track.draw_waypoints(self.canvas, track_grey, 2, 8)
109+
# self._current_track.draw_section_highlight(self.canvas, track_grey, 0, 20)
110+
# self._current_track.draw_starting_line(self.canvas, track_grey)
111+
# self._current_track.draw_sector_dividers(self.canvas, track_grey)
112+
# self._current_track.draw_waypoint_labels(self.canvas, track_grey, 9)
113+
# self._current_track.draw_grid(self.canvas, grid_grey)
82114

83115
def set_busy_cursor(self):
84116
self.setCursor(Qt.CursorShape.WaitCursor)

src/tracks/track.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def draw_starting_line(self, track_canvas: TrackAnalysisCanvas, colour: QColor):
149149
def draw_sector_dividers(self, track_canvas: TrackAnalysisCanvas, colour: QColor):
150150
for p in self._drawing_points:
151151
if p.is_divider:
152-
track_canvas.add_fixed_shape(Line(p.left, p.right, 3, colour, (2, 3)))
152+
track_canvas.add_fixed_shape(Line(p.left, p.right, 3, colour, (1, 2)))
153153

154154
def draw_waypoints(self, track_canvas: TrackAnalysisCanvas, colour: QColor, minor_size: int, major_size: int):
155155
assert major_size >= minor_size
@@ -208,16 +208,16 @@ def draw_grid(self, track_canvas: TrackAnalysisCanvas, colour: QColor):
208208
colour))
209209
y += 1
210210

211-
def draw_sector_labels(self, track_graphics: TrackGraphics, colour: str):
211+
def draw_sector_labels(self, track_canvas: TrackAnalysisCanvas, colour: QColor):
212212
for name in self.get_all_sector_names():
213213
(start, finish) = self.get_sector_start_and_finish(name)
214214
label_waypoint = int((start + finish) / 2)
215215
point = self._drawing_points[label_waypoint].middle
216216

217217
if self._is_vertical_at_waypoint(label_waypoint):
218-
track_graphics.plot_text(point, name, 20, colour, 14, 0)
218+
track_canvas.add_fixed_shape(Text(point, name, 18, colour, 14, 0))
219219
else:
220-
track_graphics.plot_text(point, name, 20, colour, 0, -14)
220+
track_canvas.add_fixed_shape(Text(point, name, 18, colour, 0, -14))
221221

222222
def get_bearing_and_distance_to_next_waypoint(self, waypoint_id: int):
223223
this_point = self._drawing_points[waypoint_id].middle

src/ui/colours.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from PyQt6.QtGui import QColor
2+
3+
4+
class Colours:
5+
TRACK_GREY = QColor(75, 75, 75)
6+
TRACK_BLUE = QColor(0, 0, 220)
7+
8+
GRID_GREY = QColor(45, 45, 45)

src/ui/track_painter.py

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
from episode.episode_filter import EpisodeFilter
2+
from graphics.track_analysis_canvas import TrackAnalysisCanvas
3+
from tracks.track import Track
4+
from ui.colours import Colours
5+
6+
SECTOR_BORDER = 0.2
7+
8+
class TrackPainter:
9+
def __init__(self):
10+
self.track_colour = Colours.TRACK_GREY
11+
12+
self.waypoint_major_size = 0
13+
self.waypoint_minor_size = 0
14+
15+
self.waypoints_on = True
16+
self.waypoint_labels_on = False
17+
self.grid_on = False
18+
self.annotations_on = False
19+
self.sectors_on = False
20+
21+
self.drawing_order = [ "G", "A", "T", "N" ]
22+
23+
self.set_track_colour_grey()
24+
self.set_waypoint_sizes_micro()
25+
26+
self.zoom_x = None
27+
self.zoom_y = None
28+
self.zoom_x2 = None
29+
self.zoom_y2 = None
30+
31+
self.zoom_in = False
32+
33+
def set_track_colour_grey(self):
34+
self.track_colour = Colours.TRACK_GREY
35+
36+
def set_track_colour_blue(self):
37+
self.track_colour = Colours.TRACK_BLUE
38+
39+
def set_waypoint_sizes_large(self):
40+
self.waypoint_minor_size = 5
41+
self.waypoint_major_size = 9
42+
self.waypoints_on = True
43+
44+
def set_waypoint_sizes_small(self):
45+
self.waypoint_minor_size = 3
46+
self.waypoint_major_size = 5
47+
self.waypoints_on = True
48+
49+
def set_waypoint_sizes_micro(self):
50+
self.waypoint_minor_size = 2
51+
self.waypoint_major_size = 3
52+
self.waypoints_on = True
53+
54+
def set_waypoints_off(self):
55+
self.waypoints_on = False
56+
57+
def set_waypoint_labels_on(self):
58+
self.waypoint_labels_on = True
59+
60+
def set_waypoint_labels_off(self):
61+
self.waypoint_labels_on = False
62+
63+
def set_grid_front(self):
64+
self.grid_on = True
65+
self.drawing_order.remove("G")
66+
self.drawing_order.append("G")
67+
68+
def set_grid_back(self):
69+
self.grid_on = True
70+
self.drawing_order.remove("G")
71+
self.drawing_order.insert(0, "G")
72+
73+
def set_grid_off(self):
74+
self.grid_on = False
75+
76+
def set_track_front(self):
77+
self.drawing_order.remove("T")
78+
self.drawing_order.append("T")
79+
80+
def set_track_back(self):
81+
self.drawing_order.remove("T")
82+
self.drawing_order.insert(0, "T")
83+
84+
def set_analyze_front(self):
85+
self.drawing_order.remove("A")
86+
self.drawing_order.append("A")
87+
88+
def set_analyze_back(self):
89+
self.drawing_order.remove("A")
90+
self.drawing_order.insert(0, "A")
91+
92+
def set_annotations_front(self):
93+
self.annotations_on = True
94+
self.drawing_order.remove("N")
95+
self.drawing_order.append("N")
96+
97+
def set_annotations_back(self):
98+
self.annotations_on = True
99+
self.drawing_order.remove("N")
100+
self.drawing_order.insert(0, "N")
101+
102+
def set_annotations_off(self):
103+
self.annotations_on = False
104+
105+
def set_sectors_on(self):
106+
self.sectors_on = True
107+
108+
def set_sectors_off(self):
109+
self.sectors_on = False
110+
111+
def draw(self, track_canvas: TrackAnalysisCanvas, current_track: Track, episode_filter: EpisodeFilter):
112+
# analyzer.recalculate()
113+
# if background_analyser:
114+
# background_analyser.recalculate()
115+
#
116+
# track_graphics.reset_to_blank()
117+
#
118+
# if self.zoom_in and self.zoom_x:
119+
# track_graphics.set_track_area(self.zoom_x, self.zoom_y, self.zoom_x2, self.zoom_y2)
120+
# else:
121+
# current_track.configure_track_graphics(track_graphics)
122+
123+
for do in self.drawing_order:
124+
if do == "G" and self.grid_on:
125+
current_track.draw_grid(track_canvas, Colours.GRID_GREY)
126+
127+
if do == "T":
128+
current_track.draw_track_edges(track_canvas, self.track_colour)
129+
if episode_filter.filter_complete_section:
130+
(start, finish) = episode_filter.filter_complete_section
131+
current_track.draw_section_highlight(track_canvas, self.track_colour, start, finish)
132+
133+
current_track.draw_starting_line(track_canvas, self.track_colour)
134+
if self.sectors_on:
135+
current_track.draw_sector_dividers(track_canvas, self.track_colour)
136+
current_track.draw_sector_labels(track_canvas, self.track_colour)
137+
if self.waypoints_on:
138+
current_track.draw_waypoints(track_canvas, self.track_colour, self.waypoint_minor_size,
139+
self.waypoint_major_size)
140+
if self.waypoint_labels_on:
141+
current_track.draw_waypoint_labels(track_canvas, self.track_colour, 9)
142+
143+
# if do == "A":
144+
# if background_analyser:
145+
# background_analyser.redraw()
146+
# analyzer.redraw()
147+
148+
if do == "N" and self.annotations_on:
149+
current_track.draw_annotations(track_canvas)
150+
151+
# def zoom_set(self, track_graphics, x, y, x2, y2):
152+
# real_x, real_y = track_graphics.get_real_point_for_widget_location(x, y)
153+
# real_x2, real_y2 = track_graphics.get_real_point_for_widget_location(x2, y2)
154+
#
155+
# self.zoom_x = min(real_x, real_x2)
156+
# self.zoom_x2 = max(real_x, real_x2)
157+
# self.zoom_y = min(real_y, real_y2)
158+
# self.zoom_y2 = max(real_y, real_y2)
159+
#
160+
# self.zoom_in = True
161+
#
162+
# def zoom_sector(self, track: Track, sector: str):
163+
# (self.zoom_x, self.zoom_y, self.zoom_x2, self.zoom_y2) = track.get_sector_coordinates(sector)
164+
# self.zoom_x -= SECTOR_BORDER
165+
# self.zoom_y -= SECTOR_BORDER
166+
# self.zoom_x2 += SECTOR_BORDER
167+
# self.zoom_y2 += SECTOR_BORDER
168+
# self.zoom_in = True
169+
#
170+
# def zoom_toggle(self):
171+
# self.zoom_in = not self.zoom_in
172+
#
173+
# def zoom_clear(self):
174+
# self.zoom_x = None
175+
# self.zoom_y = None
176+
# self.zoom_x2 = None
177+
# self.zoom_y2 = None
178+
#
179+
# self.zoom_in = False

0 commit comments

Comments
 (0)