Ensure legends colored properly in dark mode
This commit is contained in:
		
							parent
							
								
									f692b2061c
								
							
						
					
					
						commit
						d357734996
					
				
					 2 changed files with 38 additions and 10 deletions
				
			
		|  | @ -84,7 +84,7 @@ args = argparser.parse_args() | |||
| config = Config.load() | ||||
| db     = Database.from_config(config) | ||||
| 
 | ||||
| conus  = SPCOutlookMap() | ||||
| conus  = SPCOutlookMap(args.dark) | ||||
| 
 | ||||
| if args.file is None: | ||||
|     outlook = SPCOutlook.for_timestamp(db, args.valid, args.day) | ||||
|  |  | |||
|  | @ -647,15 +647,23 @@ class SPCOutlookLegend(): | |||
| 
 | ||||
|         return self.width, self.height | ||||
| 
 | ||||
|     def draw_item(self, cr: cairo.Context, key: str, x: float, y: float): | ||||
|     def draw_item(self, | ||||
|                   cr: cairo.Context, | ||||
|                   key: str, | ||||
|                   x: float, | ||||
|                   y: float, | ||||
|                   dark: bool=False): | ||||
|         cr.save() | ||||
| 
 | ||||
|         cr.set_source_rgb(*self.colors[key]) | ||||
|         cr.rectangle(x, y, self.COLOR_WIDTH, self.COLOR_HEIGHT) | ||||
|         cr.fill() | ||||
| 
 | ||||
|         color = (1, 1, 1) if dark else (0, 0, 0) | ||||
| 
 | ||||
|         cr.set_source_rgb(*color) | ||||
| 
 | ||||
|         cr.set_line_width(1) | ||||
|         cr.set_source_rgb(0, 0, 0) | ||||
|         cr.rectangle(x, y, self.COLOR_WIDTH, self.COLOR_HEIGHT) | ||||
|         cr.stroke() | ||||
| 
 | ||||
|  | @ -666,11 +674,12 @@ class SPCOutlookLegend(): | |||
|         cr.move_to(x + self.COLOR_WIDTH + self.MARGIN, | ||||
|                    y + self.COLOR_WIDTH / 2 + extents.height / 2) | ||||
| 
 | ||||
|         cr.set_source_rgb(*color) | ||||
|         cr.show_text(text) | ||||
| 
 | ||||
|         cr.restore() | ||||
| 
 | ||||
|     def draw(self, cr: cairo.Context, x: float, y: float): | ||||
|     def draw(self, cr: cairo.Context, x: float, y: float, dark: bool=False): | ||||
|         cr.save() | ||||
| 
 | ||||
|         cr.select_font_face(self.FONT_FACE, | ||||
|  | @ -679,7 +688,11 @@ class SPCOutlookLegend(): | |||
| 
 | ||||
|         cr.set_font_size(self.FONT_SIZE) | ||||
| 
 | ||||
|         if dark: | ||||
|             cr.set_source_rgba(0.2, 0.2, 0.2, 0.8) | ||||
|         else: | ||||
|             cr.set_source_rgba(0.2, 0.2, 0.2, 0.1) | ||||
| 
 | ||||
|         draw_rounded_rect(cr, x, y, self.width, self.height, self.RADIUS) | ||||
| 
 | ||||
|         cr.fill() | ||||
|  | @ -692,7 +705,7 @@ class SPCOutlookLegend(): | |||
| 
 | ||||
|             item_y = y + self.MARGIN + i * (self.COLOR_HEIGHT + self.MARGIN) | ||||
| 
 | ||||
|             self.draw_item(cr, key, x + self.MARGIN, item_y) | ||||
|             self.draw_item(cr, key, x + self.MARGIN, item_y, dark) | ||||
| 
 | ||||
|             i += 1 | ||||
| 
 | ||||
|  | @ -727,7 +740,7 @@ class SPCOutlookMap(EquirectMap): | |||
|         None: ( 20/255.0,  20/255.0,  20/255.0), | ||||
|     } | ||||
| 
 | ||||
|     def __init__(self): | ||||
|     def __init__(self, dark: bool=False): | ||||
|         super().__init__(*MAP_SCREEN_DIMENSIONS, MAP_BOUNDS) | ||||
| 
 | ||||
|         self.hatched_surface = cairo.RecordingSurface(cairo.CONTENT_COLOR_ALPHA, | ||||
|  | @ -739,6 +752,8 @@ class SPCOutlookMap(EquirectMap): | |||
|         cr.line_to(4, 4) | ||||
|         cr.stroke() | ||||
| 
 | ||||
|         self.dark = dark | ||||
| 
 | ||||
|     def draw_legend(self, | ||||
|                     cr: cairo.Context, | ||||
|                     kind: SPCOutlookType): | ||||
|  | @ -772,7 +787,7 @@ class SPCOutlookMap(EquirectMap): | |||
|         x = self.width  - 3 * self.MARGIN - size[0] | ||||
|         y = self.height - 6 * self.MARGIN - size[1] | ||||
| 
 | ||||
|         legend.draw(cr, x, y) | ||||
|         legend.draw(cr, x, y, self.dark) | ||||
| 
 | ||||
|     def draw_logo(self, cr: cairo.Context, path: str): | ||||
|         cr.save() | ||||
|  | @ -808,6 +823,11 @@ class SPCOutlookMap(EquirectMap): | |||
|         x = self.width  - extents.width - 48 | ||||
|         y = self.height - extents.height - 16 | ||||
| 
 | ||||
|         if self.dark: | ||||
|             cr.set_source_rgb(1, 1, 1) | ||||
|         else: | ||||
|             cr.set_source_rgb(0, 0, 0) | ||||
| 
 | ||||
|         cr.move_to(x, y) | ||||
|         cr.show_text(text) | ||||
| 
 | ||||
|  | @ -826,11 +846,19 @@ class SPCOutlookMap(EquirectMap): | |||
|         x = self.width - extents.width - 32 | ||||
|         y = 8 + extents.height | ||||
| 
 | ||||
|         if self.dark: | ||||
|             cr.set_source_rgba(0, 0, 0, 0.2) | ||||
|         else: | ||||
|             cr.set_source_rgba(1, 1, 1, 0.8) | ||||
| 
 | ||||
|         cr.rectangle(x - 4, y - 3, extents.width + 8, extents.height + 8) | ||||
|         cr.fill() | ||||
| 
 | ||||
|         if self.dark: | ||||
|             cr.set_source_rgb(1, 1, 1) | ||||
|         else: | ||||
|             cr.set_source_rgb(0, 0, 0) | ||||
| 
 | ||||
|         cr.move_to(x, y + extents.height) | ||||
|         cr.show_text(text) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue