2828using System . Diagnostics ;
2929using System . Linq ;
3030using System . Threading . Tasks ;
31+ using Adw ;
3132using Cairo ;
3233using Pinta . Core ;
3334
@@ -42,15 +43,13 @@ public sealed class StatusBarColorPaletteWidget : Gtk.DrawingArea
4243 private readonly RectangleD swap_rect = new ( 27 , 2 , 15 , 15 ) ;
4344 private readonly RectangleD reset_rect = new ( 2 , 27 , 15 , 15 ) ;
4445
45- private readonly ChromeManager chrome ;
46- private readonly PaletteManager palette ;
46+ private readonly IChromeService chrome ;
47+ private readonly IPaletteService palette ;
4748
4849 private RectangleD palette_rect ;
4950 private RectangleD recent_palette_rect ;
5051
51- public StatusBarColorPaletteWidget (
52- ChromeManager chrome ,
53- PaletteManager palette )
52+ public StatusBarColorPaletteWidget ( IChromeService chrome , IPaletteService palette )
5453 {
5554 this . chrome = chrome ;
5655 this . palette = palette ;
@@ -176,12 +175,24 @@ private async void HandleClick (PointD point, uint button)
176175
177176 private void Draw ( Context g )
178177 {
178+ const int TILE_SIZE = 16 ;
179+ using Pattern checkeredPattern =
180+ CairoExtensions . CreateTransparentBackgroundPattern ( TILE_SIZE ) ;
181+
179182 // Draw Secondary color swatch
183+
184+ if ( palette . SecondaryColor . A < 1 )
185+ g . FillRectangle ( secondary_rect , checkeredPattern ) ;
186+
180187 g . FillRectangle ( secondary_rect , palette . SecondaryColor ) ;
181188 g . DrawRectangle ( new RectangleD ( secondary_rect . X + 1 , secondary_rect . Y + 1 , secondary_rect . Width - 2 , secondary_rect . Height - 2 ) , new Color ( 1 , 1 , 1 ) , 1 ) ;
182189 g . DrawRectangle ( secondary_rect , new Color ( 0 , 0 , 0 ) , 1 ) ;
183190
184191 // Draw Primary color swatch
192+
193+ if ( palette . PrimaryColor . A < 1 )
194+ g . FillRectangle ( primary_rect , checkeredPattern ) ;
195+
185196 g . FillRectangle ( primary_rect , palette . PrimaryColor ) ;
186197 g . DrawRectangle ( new RectangleD ( primary_rect . X + 1 , primary_rect . Y + 1 , primary_rect . Width - 2 , primary_rect . Height - 2 ) , new Color ( 1 , 1 , 1 ) , 1 ) ;
187198 g . DrawRectangle ( primary_rect , new Color ( 0 , 0 , 0 ) , 1 ) ;
@@ -198,14 +209,30 @@ private void Draw (Context g)
198209 // Draw recently used color swatches
199210 var recent = palette . RecentlyUsedColors ;
200211
201- for ( int i = 0 ; i < recent . Count ; i ++ )
202- g . FillRectangle ( PaletteWidget . GetSwatchBounds ( palette , i , recent_palette_rect , true ) , recent . ElementAt ( i ) ) ;
212+ for ( int i = 0 ; i < recent . Count ; i ++ ) {
213+
214+ RectangleD swatchBounds = PaletteWidget . GetSwatchBounds ( palette , i , recent_palette_rect , true ) ;
215+ Color recentColor = recent . ElementAt ( i ) ;
216+
217+ if ( recentColor . A < 1 ) // Only draw checkered pattern if there is transparency
218+ g . FillRectangle ( swatchBounds , checkeredPattern ) ;
219+
220+ g . FillRectangle ( swatchBounds , recentColor ) ;
221+ }
203222
204223 // Draw color swatches
205224 var currentPalette = palette . CurrentPalette ;
206225
207- for ( int i = 0 ; i < currentPalette . Colors . Count ; i ++ )
208- g . FillRectangle ( PaletteWidget . GetSwatchBounds ( palette , i , palette_rect ) , currentPalette . Colors [ i ] ) ;
226+ for ( int i = 0 ; i < currentPalette . Colors . Count ; i ++ ) {
227+
228+ RectangleD swatchBounds = PaletteWidget . GetSwatchBounds ( palette , i , palette_rect ) ;
229+ Color paletteColor = currentPalette . Colors [ i ] ;
230+
231+ if ( paletteColor . A < 1 ) // Only draw checkered pattern if there is transparency
232+ g . FillRectangle ( swatchBounds , checkeredPattern ) ;
233+
234+ g . FillRectangle ( swatchBounds , paletteColor ) ;
235+ }
209236
210237 g . Dispose ( ) ;
211238 }
0 commit comments