Просмотр исходного кода

wxGUI/animation: add text background/foreground in settings

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65736 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 9 лет назад
Родитель
Сommit
2083d8fcbd

+ 4 - 2
gui/wxpython/animation/controller.py

@@ -495,6 +495,8 @@ class AnimationController(wx.EvtHandler):
         busy = wx.BusyInfo(message=_("Preparing export, please wait..."), parent=self.frame)
         wx.Yield()
         lastBitmaps = {}
+        fgcolor = UserSettings.Get(group='animation', key='font', subkey='fgcolor')
+        bgcolor = UserSettings.Get(group='animation', key='font', subkey='bgcolor')
         for frameIndex in range(frameCount):
             image = wx.EmptyImage(*size)
             image.Replace(0, 0, 0, 255, 255, 255)
@@ -547,10 +549,10 @@ class AnimationController(wx.EvtHandler):
                             text = _("%(start)s %(unit)s") % \
                                     {'start': timeLabel[0], 'unit': timeLabel[2]}
 
-                    decImage = RenderText(text, decoration['font']).ConvertToImage()
+                    decImage = RenderText(text, decoration['font'], bgcolor, fgcolor).ConvertToImage()
                 elif decoration['name'] == 'text':
                     text = decoration['text']
-                    decImage = RenderText(text, decoration['font']).ConvertToImage()
+                    decImage = RenderText(text, decoration['font'], bgcolor, fgcolor).ConvertToImage()
 
                 image.Paste(decImage, x, y)
 

+ 26 - 0
gui/wxpython/animation/dialogs.py

@@ -1519,6 +1519,32 @@ class PreferencesDialog(PreferencesBaseDialog):
 
         gridSizer.Add(item=nprocs, pos=(row, 1), flag=wx.ALIGN_RIGHT)
 
+        row += 1
+        gridSizer.Add(item=wx.StaticText(parent=panel,
+                                         label=_("Text foreground color:")),
+                      flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
+        color = csel.ColourSelect(parent=panel,
+                                  colour=UserSettings.Get(group='animation',
+                                                          key='font', subkey='fgcolor'),
+                                  size=globalvar.DIALOG_COLOR_SIZE)
+        color.SetName('GetColour')
+        self.winId['animation:font:fgcolor'] = color.GetId()
+
+        gridSizer.Add(item=color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
+
+        row += 1
+        gridSizer.Add(item=wx.StaticText(parent=panel,
+                                         label=_("Text background color:")),
+                      flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
+        color = csel.ColourSelect(parent=panel,
+                                  colour=UserSettings.Get(group='animation',
+                                                          key='font', subkey='bgcolor'),
+                                  size=globalvar.DIALOG_COLOR_SIZE)
+        color.SetName('GetColour')
+        self.winId['animation:font:bgcolor'] = color.GetId()
+
+        gridSizer.Add(item=color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
+
         gridSizer.AddGrowableCol(1)
         sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=3)
         border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)

+ 4 - 4
gui/wxpython/animation/utils.py

@@ -240,19 +240,19 @@ def ComputeScaledRect(sourceSize, destSize):
     return {'width': width, 'height': height, 'x': x, 'y': y, 'scale': scale}
 
 
-def RenderText(text, font):
+def RenderText(text, font, bgcolor, fgcolor):
     """Renderes text with given font to bitmap."""
     dc = wx.MemoryDC()
     dc.SetFont(font)
     w, h = dc.GetTextExtent(text)
     bmp = wx.EmptyBitmap(w + 2, h + 2)
     dc.SelectObject(bmp)
-    dc.SetBrush(wx.TRANSPARENT_BRUSH)
-    dc.SetBackgroundMode(wx.TRANSPARENT)
+    dc.SetBackgroundMode(wx.SOLID)
+    dc.SetTextBackground(wx.Colour(*bgcolor))
+    dc.SetTextForeground(wx.Colour(*fgcolor))
     dc.Clear()
     dc.DrawText(text, 1, 1)
     dc.SelectObject(wx.NullBitmap)
-    bmp.SetMaskColour(wx.WHITE)
 
     return bmp