def draw(self, cr: cairo.Context) -> None: line = self._line stroke_color = self._stroke_color stroke_width = self._stroke_width scale_strokes = self._scale_strokes if line is None: return if line.pt0 == line.pt1: return clip_extents = Rect2(cr.clip_extents()) start = line.eval(x=clip_extents.x0) end = line.eval(x=clip_extents.x1) if not clip_extents.contains(start): start = line.eval(y=clip_extents.y0 if start.y < clip_extents.y0 else clip_extents.y1) if not clip_extents.contains(end): end = line.eval(y=clip_extents. y0 if end.y < clip_extents.y0 else clip_extents.y1) cr.move_to(*start) cr.line_to(*end) cr.save() if scale_strokes: cr.identity_matrix() cr.set_source_rgb(*stroke_color) cr.set_line_width(stroke_width) cr.stroke() cr.restore()
def _do_draw(self, _, cr: cairo.Context): # Get the size drawing_area_height = self.get_allocated_height() canvas_width = self.get_allocated_width() clip_start_x, _, clip_stop_x, _ = cr.clip_extents() # Show the activity as a background for the time area for ae in self.visible_activity_entries: if ae.stop_x < clip_start_x or clip_stop_x < ae.start_x: continue r, g, b = ae.color cr.set_source_rgb(r, g, b) cr.rectangle(ae.start_x, 0, ae.width, drawing_area_height) cr.fill() # Draw the hour lines cr.set_font_size(16) cr.set_source_rgb(0.35, 0.35, 0.35) cr.rectangle(0, 0, canvas_width, self.guidingline_on_timeline_start + 10) cr.fill() for timeline_timeline in self.timeline_timelines: # Hour line hx = timeline_timeline.x cr.set_source_rgb(0.7, 0.7, 0.7) cr.new_path() cr.move_to(hx, self.guidingline_on_timeline_start) cr.line_to(hx, self.guidingline_on_timeline_start + 10) cr.stroke() # Hour text time = timeline_timeline.time if time.minute == 0: cr.set_source_rgb(0.9, 0.9, 0.3) else: cr.set_source_rgb(0.2, 0.8, 1) tx, hour_text_width = timeline_timeline.text_extents cr.move_to(hx - tx - (hour_text_width / 2), self.time_guidingline_text_height) cr.show_text(timeline_timeline.text) # Draw the rectangles for the entries by colors for color, drawing_entries in self.timeline_entries_by_color.items(): cr.set_source_rgb(*color) for drawing_entry in drawing_entries: if drawing_entry.stop_x < clip_start_x or clip_stop_x < drawing_entry.start_x: continue cr.rectangle(drawing_entry.start_x, drawing_entry.start_y, drawing_entry.width, drawing_entry.height) cr.fill() # The marker for the logged entries cr.set_source_rgb(0.3, 0.3, 0.8) for le in self.visible_logged_entries: if le.stop_x < clip_start_x or clip_stop_x < le.start_x: continue cr.rectangle(le.start_x, self.le_start_y, le.width, 10) cr.fill() # The marker for the tagged entries cr.set_source_rgb(1, 0.64, 0) for te in self.visible_tagged_entries: if te.stop_x < clip_start_x or clip_stop_x < te.start_x: continue cr.rectangle(te.start_x, self.te_end_y - 10, te.width, 10) cr.fill() if self.current_tagged_entry is not None: start_x = self.timeline_helper.datetime_to_pixel( self.current_tagged_entry.start) stop_x = self.timeline_helper.datetime_to_pixel( self.current_tagged_entry.stop) cr.set_source_rgba(0.2, 0.2, 0.2, 0.4) cr.rectangle(start_x, 0, stop_x - start_x, drawing_area_height) cr.fill() # Draw the sides cr.set_source_rgba(0.5, 0.5, 0.5, 0.5) cr.rectangle(0, 0, self.timeline_side_padding, drawing_area_height) cr.fill() cr.rectangle(canvas_width - self.timeline_side_padding, 0, canvas_width, drawing_area_height) cr.fill()