Skip to content

Commit

Permalink
♻️ refactor: extract window base drawing logic into a shared function
Browse files Browse the repository at this point in the history
The window base drawing logic was duplicated across different window styles
(GNOME, Mac, Windows). Now it's consolidated into a single DrawWindowBase
function for better maintainability.
  • Loading branch information
watzon committed Nov 21, 2024
1 parent d0e1104 commit eb6a640
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
17 changes: 8 additions & 9 deletions pkg/chrome/gnome.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,15 @@ func (c *GNOMEChrome) Render(content image.Image) (image.Image, error) {
// Create context for drawing
dc := gg.NewContext(width, height+titleBarHeight)

// Draw title bar background with corner radius
if c.titleBar {
dc.SetColor(c.theme.Properties.TitleBackground)
if c.cornerRadius > 0 {
dc.DrawRoundedRectangle(0, 0, float64(width), float64(height+titleBarHeight), c.cornerRadius)
} else {
dc.DrawRectangle(0, 0, float64(width), float64(height+titleBarHeight))
}
dc.Fill()
// Draw the base window with rounded corners
if err := DrawWindowBase(dc, width, height+titleBarHeight, c.cornerRadius,
c.theme.Properties.TitleBackground,
c.theme.Properties.TitleBackground,
titleBarHeight); err != nil {
return nil, err
}

if c.titleBar {
// Draw title text if enabled
if c.title != "" {
DrawTitleText(dc, c.title, width, titleBarHeight, c.theme.Properties.TitleText, c.theme.Properties.TitleFontSize, c.theme.Properties.TitleFont)
Expand Down
17 changes: 8 additions & 9 deletions pkg/chrome/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,15 @@ func (c *MacChrome) Render(content image.Image) (image.Image, error) {
// Create context for drawing
dc := gg.NewContext(width, height+titleBarHeight)

// Draw title bar background with corner radius
if c.titleBar {
dc.SetColor(c.theme.Properties.TitleBackground)
if c.cornerRadius > 0 {
dc.DrawRoundedRectangle(0, 0, float64(width), float64(height+titleBarHeight), c.cornerRadius)
} else {
dc.DrawRectangle(0, 0, float64(width), float64(height+titleBarHeight))
}
dc.Fill()
// Draw the base window with rounded corners
if err := DrawWindowBase(dc, width, height+titleBarHeight, c.cornerRadius,
c.theme.Properties.TitleBackground,
c.theme.Properties.TitleBackground,
titleBarHeight); err != nil {
return nil, err
}

if c.titleBar {
// Draw window controls
c.renderWindowControls(dc, titleBarHeight)

Expand Down
14 changes: 8 additions & 6 deletions pkg/chrome/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,15 @@ func (c *WindowsChrome) Render(content image.Image) (image.Image, error) {
// Create context for drawing
dc := gg.NewContext(width, height+titleBarHeight)

// Draw title bar background with corner radius
if c.titleBar {
// Draw title bar background
dc.SetColor(c.theme.Properties.TitleBackground)
dc.DrawRectangle(0, 0, float64(width), float64(titleBarHeight))
dc.Fill()
// Draw the base window with rounded corners
if err := DrawWindowBase(dc, width, height+titleBarHeight, c.cornerRadius,
c.theme.Properties.TitleBackground,
c.theme.Properties.TitleBackground,
titleBarHeight); err != nil {
return nil, err
}

if c.titleBar {
// Draw title text
if c.title != "" {
DrawTitleText(dc, c.title, width, titleBarHeight, c.theme.Properties.TitleText, winDefaultTitleFontSize, c.theme.Properties.TitleFont)
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package version

// Version is the current version of goshot
const Version = "0.3.0"
const Version = "0.3.1"

0 comments on commit eb6a640

Please sign in to comment.