@@ -75,6 +75,12 @@ type HlBgKey struct {
75
75
length int
76
76
}
77
77
78
+ type BrushKey struct {
79
+ pattern core.Qt__BrushStyle
80
+ color * RGBA
81
+ transparent int
82
+ }
83
+
78
84
// Cell is
79
85
type Cell struct {
80
86
highlight * Highlight
@@ -187,6 +193,11 @@ func purgeQimage(key, value interface{}) {
187
193
image .DestroyQImage ()
188
194
}
189
195
196
+ func purgeQBrush (key , value interface {}) {
197
+ brush := value .(* gui.QBrush )
198
+ brush .DestroyQBrush ()
199
+ }
200
+
190
201
func newCache () Cache {
191
202
g := gcache .New (editor .config .Editor .CacheSize ).LRU ().
192
203
EvictedFunc (purgeQimage ).
@@ -195,6 +206,14 @@ func newCache() Cache {
195
206
return * (* Cache )(unsafe .Pointer (& g ))
196
207
}
197
208
209
+ func newBrushCache () Cache {
210
+ g := gcache .New (64 ).LRU ().
211
+ EvictedFunc (purgeQBrush ).
212
+ PurgeVisitorFunc (purgeQBrush ).
213
+ Build ()
214
+ return * (* Cache )(unsafe .Pointer (& g ))
215
+ }
216
+
198
217
func (c * Cache ) set (key , value interface {}) error {
199
218
return c .Set (key , value )
200
219
}
@@ -2045,70 +2064,49 @@ func (w *Window) fillCellRect(p *gui.QPainter, lastHighlight *Highlight, lastBg
2045
2064
}
2046
2065
2047
2066
font := w .getFont ()
2067
+ pattern , color , transparent := w .getFillpatternAndTransparent (lastHighlight )
2068
+
2069
+ var brush * gui.QBrush
2070
+ if editor .config .Editor .CachedDrawing {
2071
+ brushv , err := w .s .bgcache .get (BrushKey {
2072
+ pattern : pattern ,
2073
+ color : color ,
2074
+ transparent : transparent ,
2075
+ })
2076
+ if err != nil {
2077
+ brush = newBgBrushCache (pattern , color , transparent )
2078
+ w .setBgBrushCache (pattern , color , transparent , brush )
2079
+ } else {
2080
+ brush = brushv .(* gui.QBrush )
2081
+ }
2082
+ } else {
2083
+ brush = newBgBrushCache (pattern , color , transparent )
2084
+ }
2048
2085
2049
2086
if verScrollPixels == 0 ||
2050
2087
verScrollPixels > 0 && (y < w .rows - w .viewportMargins [1 ]- 1 ) ||
2051
2088
verScrollPixels < 0 && (y > w .viewportMargins [0 ]) {
2052
- if editor .config .Editor .CachedDrawing {
2053
- cache := w .getCache ()
2054
- if cache == (Cache {}) {
2055
- return
2056
- }
2057
- var image * gui.QImage
2058
- imagev , err := cache .get (HlBgKey {
2059
- bg : lastHighlight .bg (),
2060
- length : width ,
2061
- })
2062
-
2063
- if err != nil {
2064
- image = w .newBgCache (lastHighlight , width )
2065
- w .setBgCache (lastHighlight , width , image )
2066
- } else {
2067
- image = imagev .(* gui.QImage )
2068
- }
2069
2089
2070
- p .DrawImage9 (
2071
- int (float64 (start )* font .cellwidth + float64 (horScrollPixels )),
2072
- int (float64 ((y )* font .lineHeight + verScrollPixels )),
2073
- image ,
2074
- 0 , 0 ,
2075
- - 1 , - 1 ,
2076
- core .Qt__AutoColor ,
2077
- )
2090
+ // Fill background with pattern
2091
+ rectF := core .NewQRectF4 (
2092
+ float64 (start )* font .cellwidth + float64 (horScrollPixels ),
2093
+ float64 ((y )* font .lineHeight + verScrollPixels ),
2094
+ float64 (width )* font .cellwidth ,
2095
+ float64 (font .lineHeight ),
2096
+ )
2078
2097
2079
- } else {
2080
- // Set diff pattern
2081
- pattern , color , transparent := w .getFillpatternAndTransparent (lastHighlight )
2098
+ p .FillRect (
2099
+ rectF ,
2100
+ brush ,
2101
+ )
2082
2102
2083
- // Fill background with pattern
2084
- rectF := core .NewQRectF4 (
2085
- float64 (start )* font .cellwidth + float64 (horScrollPixels ),
2086
- float64 ((y )* font .lineHeight + verScrollPixels ),
2087
- float64 (width )* font .cellwidth ,
2088
- float64 (font .lineHeight ),
2089
- )
2090
- p .FillRect (
2091
- rectF ,
2092
- gui .NewQBrush3 (
2093
- gui .NewQColor3 (
2094
- color .R ,
2095
- color .G ,
2096
- color .B ,
2097
- transparent ,
2098
- ),
2099
- pattern ,
2100
- ),
2101
- )
2102
- }
2103
2103
}
2104
2104
2105
2105
// Addresses an issue where smooth scrolling with a touchpad causes incomplete
2106
2106
// background rendering at the top or bottom of floating windows.
2107
2107
// Adds compensation drawing for areas partially scrolled into view by checking
2108
2108
// `verScrollPixels` and filling the necessary background to prevent visual gaps.
2109
2109
2110
- pattern , color , transparent := w .getFillpatternAndTransparent (lastHighlight )
2111
-
2112
2110
if verScrollPixels > 0 {
2113
2111
if y == w .viewportMargins [0 ] {
2114
2112
@@ -2126,15 +2124,7 @@ func (w *Window) fillCellRect(p *gui.QPainter, lastHighlight *Highlight, lastBg
2126
2124
)
2127
2125
p .FillRect (
2128
2126
rectF ,
2129
- gui .NewQBrush3 (
2130
- gui .NewQColor3 (
2131
- color .R ,
2132
- color .G ,
2133
- color .B ,
2134
- transparent ,
2135
- ),
2136
- pattern ,
2137
- ),
2127
+ brush ,
2138
2128
)
2139
2129
}
2140
2130
@@ -2148,15 +2138,7 @@ func (w *Window) fillCellRect(p *gui.QPainter, lastHighlight *Highlight, lastBg
2148
2138
)
2149
2139
p .FillRect (
2150
2140
rectF ,
2151
- gui .NewQBrush3 (
2152
- gui .NewQColor3 (
2153
- color .R ,
2154
- color .G ,
2155
- color .B ,
2156
- transparent ,
2157
- ),
2158
- pattern ,
2159
- ),
2141
+ brush ,
2160
2142
)
2161
2143
}
2162
2144
@@ -2172,15 +2154,7 @@ func (w *Window) fillCellRect(p *gui.QPainter, lastHighlight *Highlight, lastBg
2172
2154
)
2173
2155
p .FillRect (
2174
2156
rectF ,
2175
- gui .NewQBrush3 (
2176
- gui .NewQColor3 (
2177
- color .R ,
2178
- color .G ,
2179
- color .B ,
2180
- transparent ,
2181
- ),
2182
- pattern ,
2183
- ),
2157
+ brush ,
2184
2158
)
2185
2159
}
2186
2160
if y == w .rows - w .viewportMargins [1 ]- 1 {
@@ -2197,22 +2171,39 @@ func (w *Window) fillCellRect(p *gui.QPainter, lastHighlight *Highlight, lastBg
2197
2171
)
2198
2172
p .FillRect (
2199
2173
rectF ,
2200
- gui .NewQBrush3 (
2201
- gui .NewQColor3 (
2202
- color .R ,
2203
- color .G ,
2204
- color .B ,
2205
- transparent ,
2206
- ),
2207
- pattern ,
2208
- ),
2174
+ brush ,
2209
2175
)
2210
2176
}
2211
2177
2212
2178
}
2213
2179
2214
2180
}
2215
2181
2182
+ func newBgBrushCache (pattern core.Qt__BrushStyle , color * RGBA , transparent int ) * gui.QBrush {
2183
+
2184
+ return gui .NewQBrush3 (
2185
+ gui .NewQColor3 (
2186
+ color .R ,
2187
+ color .G ,
2188
+ color .B ,
2189
+ transparent ,
2190
+ ),
2191
+ pattern ,
2192
+ )
2193
+
2194
+ }
2195
+
2196
+ func (w * Window ) setBgBrushCache (pattern core.Qt__BrushStyle , color * RGBA , transparent int , brush * gui.QBrush ) {
2197
+ w .s .bgcache .set (
2198
+ BrushKey {
2199
+ pattern : pattern ,
2200
+ color : color ,
2201
+ transparent : transparent ,
2202
+ },
2203
+ brush ,
2204
+ )
2205
+ }
2206
+
2216
2207
func (w * Window ) newBgCache (lastHighlight * Highlight , length int ) * gui.QImage {
2217
2208
font := w .getFont ()
2218
2209
width := float64 (length ) * font .cellwidth
0 commit comments