Skip to content

Commit

Permalink
Merge pull request wxWidgets#1896 from kdschlosser/fixes_floating_poi…
Browse files Browse the repository at this point in the history
…nt_math

Fixes floating point math in wx.lib.agw.aui
  • Loading branch information
RobinD42 authored Jan 18, 2021
2 parents bcc9510 + 7afcc7f commit e32ba71
Show file tree
Hide file tree
Showing 6 changed files with 417 additions and 777 deletions.
4 changes: 2 additions & 2 deletions wx/lib/agw/aui/aui_switcherdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,12 @@ def PaintItems(self, dc, win):
and item.GetBitmap().GetHeight() <= 16:
x -= textMarginX
dc.DrawBitmap(item.GetBitmap(), x, item.GetRect().y + \
(item.GetRect().height - item.GetBitmap().GetHeight())/2,
(item.GetRect().height - item.GetBitmap().GetHeight())//2,
True)
x += 16 + textMarginX
#x += textMarginX

y = item.GetRect().y + (item.GetRect().height - h)/2
y = item.GetRect().y + (item.GetRect().height - h)//2
dc.DrawText(item.GetTitle(), x, y)
dc.DestroyClippingRegion()

Expand Down
17 changes: 10 additions & 7 deletions wx/lib/agw/aui/aui_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ def DarkenBitmap(bmp, caption_colour, new_colour):
"""

image = bmp.ConvertToImage()
red = caption_colour.Red()/float(new_colour.Red())
green = caption_colour.Green()/float(new_colour.Green())
blue = caption_colour.Blue()/float(new_colour.Blue())
red = caption_colour.Red()/new_colour.Red()
green = caption_colour.Green()/new_colour.Green()
blue = caption_colour.Blue()/new_colour.Blue()
image = image.AdjustChannels(red, green, blue)
return image.ConvertToBitmap()

Expand Down Expand Up @@ -584,13 +584,13 @@ def RescaleScreenShot(bmp, thumbnail_size=200):

if bmpW > bmpH:
if bmpW > thumbnail_size:
ratio = bmpW/float(thumbnail_size)
newW, newH = int(bmpW/ratio), int(bmpH/ratio)
ratio = bmpW/thumbnail_size
newW, newH = bmpW//ratio, bmpH//ratio
img.Rescale(newW, newH, wx.IMAGE_QUALITY_HIGH)
else:
if bmpH > thumbnail_size:
ratio = bmpH/float(thumbnail_size)
newW, newH = int(bmpW/ratio), int(bmpH/ratio)
ratio = bmpH/thumbnail_size
newW, newH = bmpW//ratio, bmpH//ratio
img.Rescale(newW, newH, wx.IMAGE_QUALITY_HIGH)

newBmp = img.ConvertToBitmap()
Expand Down Expand Up @@ -667,3 +667,6 @@ def CopyAttributes(newArt, oldArt):

return newArt




44 changes: 21 additions & 23 deletions wx/lib/agw/aui/auibar.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,16 +979,16 @@ def DrawLabel(self, dc, wnd, item, rect):

if orient == AUI_TBTOOL_HORIZONTAL:
text_x = rect.x
text_y = rect.y + (rect.height-text_height)/2
text_y = rect.y + (rect.height-text_height)//2
dc.DrawText(item.GetLabel(), text_x, text_y)

elif orient == AUI_TBTOOL_VERT_CLOCKWISE:
text_x = rect.x + (rect.width+text_width)/2
text_x = rect.x + (rect.width+text_width)//2
text_y = rect.y
dc.DrawRotatedText(item.GetLabel(), text_x, text_y, 270)

elif AUI_TBTOOL_VERT_COUNTERCLOCKWISE:
text_x = rect.x + (rect.width-text_width)/2
text_x = rect.x + (rect.width-text_width)//2
text_y = rect.y + text_height
dc.DrawRotatedText(item.GetLabel(), text_x, text_y, 90)

Expand Down Expand Up @@ -1086,8 +1086,8 @@ def DrawDropDownButton(self, dc, wnd, item, rect):
dropbmp_width = dropbmp_height
dropbmp_height = tmp

dropbmp_x = dropdown_rect.x + (dropdown_rect.width/2) - dropbmp_width/2
dropbmp_y = dropdown_rect.y + (dropdown_rect.height/2) - dropbmp_height/2
dropbmp_x = dropdown_rect.x + (dropdown_rect.width//2) - dropbmp_width//2
dropbmp_y = dropdown_rect.y + (dropdown_rect.height//2) - dropbmp_height//2

bmp_rect, text_rect = self.GetToolsPosition(dc, item, button_rect)

Expand Down Expand Up @@ -1171,7 +1171,7 @@ def DrawControlLabel(self, dc, wnd, item, rect):
# set the label's text colour
dc.SetTextForeground(wx.BLACK)

text_x = rect.x + (rect.width/2) - (text_width/2) + 1
text_x = rect.x + (rect.width//2) - (text_width//2) + 1
text_y = rect.y + rect.height - text_height - 1

if self._agwFlags & AUI_TB_TEXT and item.GetLabel() != "":
Expand Down Expand Up @@ -1264,18 +1264,18 @@ def DrawSeparator(self, dc, wnd, _rect):

if horizontal:

rect.x += (rect.width/2)
rect.x += (rect.width//2)
rect.width = 1
new_height = (rect.height*3)/4
rect.y += (rect.height/2) - (new_height/2)
new_height = (rect.height*3)//4
rect.y += (rect.height//2) - (new_height//2)
rect.height = new_height

else:

rect.y += (rect.height/2)
rect.y += (rect.height//2)
rect.height = 1
new_width = (rect.width*3)/4
rect.x += (rect.width/2) - (new_width/2)
new_width = (rect.width*3)//4
rect.x += (rect.width//2) - (new_width//2)
rect.width = new_width

start_colour = StepColour(self._base_colour, 80)
Expand Down Expand Up @@ -1359,8 +1359,8 @@ def DrawOverflowButton(self, dc, wnd, rect, state):
dc.SetBrush(wx.Brush(light_gray_bg))
dc.DrawRectangle(rect.x+1, rect.y, rect.width, rect.height)

x = rect.x + 1 + (rect.width-self._overflow_bmp.GetWidth())/2
y = rect.y + 1 + (rect.height-self._overflow_bmp.GetHeight())/2
x = rect.x + 1 + (rect.width-self._overflow_bmp.GetWidth())//2
y = rect.y + 1 + (rect.height-self._overflow_bmp.GetHeight())//2
dc.DrawBitmap(self._overflow_bmp, x, y, True)


Expand Down Expand Up @@ -1492,21 +1492,21 @@ def GetToolsPosition(self, dc, item, rect):
bmp_x = bmp_y = text_x = text_y = 0

if horizontal and text_bottom:
bmp_x = rect.x + (rect.width/2) - (bmp_width/2)
bmp_x = rect.x + (rect.width//2) - (bmp_width//2)
bmp_y = rect.y + 3
text_x = rect.x + (rect.width/2) - (text_width/2)
text_x = rect.x + (rect.width//2) - (text_width//2)
text_y = rect.y + ((bmp_y - rect.y) * 2) + bmp_height

elif horizontal and text_right:
bmp_x = rect.x + 3
bmp_y = rect.y + (rect.height/2) - (bmp_height / 2)
bmp_y = rect.y + (rect.height//2) - (bmp_height // 2)
text_x = rect.x + ((bmp_x - rect.x) * 2) + bmp_width
text_y = rect.y + (rect.height/2) - (text_height/2)
text_y = rect.y + (rect.height//2) - (text_height//2)

elif not horizontal and text_bottom:
bmp_x = rect.x + (rect.width / 2) - (bmp_width / 2)
bmp_x = rect.x + (rect.width // 2) - (bmp_width // 2)
bmp_y = rect.y + 3
text_x = rect.x + (rect.width / 2) - (text_width / 2)
text_x = rect.x + (rect.width // 2) - (text_width // 2)
text_y = rect.y + ((bmp_y - rect.y) * 2) + bmp_height

bmp_rect = wx.Rect(bmp_x, bmp_y, bmp_width, bmp_height)
Expand Down Expand Up @@ -3257,9 +3257,6 @@ def SetAuiManager(self, auiManager):
def DoIdleUpdate(self):
""" Updates the toolbar during idle times. """

if not self:
return # The action Destroyed the toolbar!

handler = self.GetEventHandler()
if not handler:
return
Expand Down Expand Up @@ -4031,3 +4028,4 @@ def StopPreviewTimer(self):

manager = self.GetAuiManager()
manager.StopPreviewTimer()

6 changes: 3 additions & 3 deletions wx/lib/agw/aui/auibook.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __init__(self, owner, tab, page_index):
x += image_w
w -= image_w + 4

y = (self._tabEdited.rect.height - h)/2 + 1
y = (self._tabEdited.rect.height - h)//2 + 1

expandoStyle = wx.WANTS_CHARS
if wx.Platform in ["__WXGTK__", "__WXMAC__"]:
Expand Down Expand Up @@ -864,7 +864,7 @@ def OnPanelPaint(self, event):
# Draw the caption title and place the bitmap
# get the bitmap optimal position, and draw it
bmpPt, txtPt = wx.Point(), wx.Point()
bmpPt.y = (rect.height - self._props.Icon.GetHeight())/2
bmpPt.y = (rect.height - self._props.Icon.GetHeight())//2
bmpPt.x = 3
mem_dc.DrawBitmap(self._props.Icon, bmpPt.x, bmpPt.y, True)

Expand All @@ -875,7 +875,7 @@ def OnPanelPaint(self, event):
fontHeight = mem_dc.GetCharHeight()

txtPt.x = bmpPt.x + self._props.Icon.GetWidth() + 4
txtPt.y = (rect.height - fontHeight)/2
txtPt.y = (rect.height - fontHeight)//2
mem_dc.SetTextForeground(wx.WHITE)
mem_dc.DrawText("Opened tabs:", txtPt.x, txtPt.y)
mem_dc.SelectObject(wx.NullBitmap)
Expand Down
Loading

0 comments on commit e32ba71

Please sign in to comment.