BitmapLoader.getBitmap will now load a @2x (or whatever the main window's content scale is) bitmap, if one is available.
This commit is contained in:
@@ -27,6 +27,8 @@ import wx
|
||||
|
||||
import config
|
||||
|
||||
import gui.mainFrame as mainFrame
|
||||
|
||||
from logbook import Logger
|
||||
logging = Logger(__name__)
|
||||
|
||||
@@ -55,9 +57,7 @@ class BitmapLoader(object):
|
||||
@classmethod
|
||||
def getBitmap(cls, name, location):
|
||||
if cls.dont_use_cached_bitmaps:
|
||||
img = cls.getImage(name, location)
|
||||
if img is not None:
|
||||
return img.ConvertToBitmap()
|
||||
return cls.loadBitmap(name, location)
|
||||
|
||||
path = "%s%s" % (name, location)
|
||||
|
||||
@@ -65,11 +65,7 @@ class BitmapLoader(object):
|
||||
cls.cached_bitmaps.popitem(False)
|
||||
|
||||
if path not in cls.cached_bitmaps:
|
||||
img = cls.getImage(name, location)
|
||||
if img is not None:
|
||||
bmp = img.ConvertToBitmap()
|
||||
else:
|
||||
bmp = None
|
||||
bmp = cls.loadBitmap(name, location)
|
||||
cls.cached_bitmaps[path] = bmp
|
||||
else:
|
||||
bmp = cls.cached_bitmaps[path]
|
||||
@@ -78,8 +74,29 @@ class BitmapLoader(object):
|
||||
|
||||
@classmethod
|
||||
def getImage(cls, name, location):
|
||||
filename = "{0}.png".format(name)
|
||||
return cls.getBitmap(name, location).ConvertToImage()
|
||||
|
||||
@classmethod
|
||||
def loadBitmap(cls, name, location):
|
||||
filename = "{0}.png".format(name)
|
||||
scale = int(mainFrame.MainFrame.getInstance().GetContentScaleFactor())
|
||||
if scale == 1:
|
||||
img = cls.loadImage(filename, location)
|
||||
else:
|
||||
filenameScaled = "{0}@{1}x.png".format(name, scale)
|
||||
img = cls.loadImage(filenameScaled, location)
|
||||
if img is None:
|
||||
img = cls.loadImage(filename, location)
|
||||
scale = 1
|
||||
if img is None:
|
||||
return None
|
||||
bmp: wx.Bitmap = img.ConvertToBitmap()
|
||||
if scale > 1:
|
||||
bmp.SetSize((int(bmp.GetWidth()/scale), int(bmp.GetHeight()/scale)))
|
||||
return bmp
|
||||
|
||||
@classmethod
|
||||
def loadImage(cls, filename, location):
|
||||
if cls.archive:
|
||||
path = os.path.join(location, filename)
|
||||
if os.sep != "/" and os.sep in path:
|
||||
|
||||
Reference in New Issue
Block a user