From c5d1ab507fab00ad7d53ba07983ea05c039d8dc7 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Wed, 26 Sep 2018 20:50:28 +0900 Subject: [PATCH] [python] fix some decoration bounds calculations --- base/home/local/python-demos/dialog.py | 22 ++++++++++---------- base/home/local/python-demos/input_box.py | 12 +++++------ base/home/local/python-demos/mines.py | 10 ++++----- base/home/local/python-demos/progress-bar.py | 14 ++++++------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/base/home/local/python-demos/dialog.py b/base/home/local/python-demos/dialog.py index d46ed71e..43da8779 100644 --- a/base/home/local/python-demos/dialog.py +++ b/base/home/local/python-demos/dialog.py @@ -90,10 +90,10 @@ class DialogWindow(yutani.Window): def draw(self): surface = self.get_cairo_surface() - WIDTH, HEIGHT = self.width - self.decorator.width(), self.height - self.decorator.height() + WIDTH, HEIGHT = self.width - self.decorator.width(self), self.height - self.decorator.height(self) ctx = cairo.Context(surface) - ctx.translate(self.decorator.left_width(), self.decorator.top_height()) + ctx.translate(self.decorator.left_width(self), self.decorator.top_height(self)) ctx.rectangle(0,0,WIDTH,HEIGHT) ctx.set_source_rgb(204/255,204/255,204/255) ctx.fill() @@ -102,7 +102,7 @@ class DialogWindow(yutani.Window): ctx.paint() self.tr.resize(WIDTH-90,HEIGHT-self.text_offset) - self.tr.move(self.decorator.left_width() + 90,self.decorator.top_height()+self.text_offset) + self.tr.move(self.decorator.left_width(self) + 90,self.decorator.top_height(self)+self.text_offset) self.tr.draw(self) self.button_ok.draw(self,ctx,WIDTH-130,HEIGHT-60,100,30) @@ -130,8 +130,8 @@ class DialogWindow(yutani.Window): return elif decor_event == yutani.Decor.EVENT_RIGHT: self.decorator.show_menu(self, msg) - x,y = msg.new_x - self.decorator.left_width(), msg.new_y - self.decorator.top_height() - w,h = self.width - self.decorator.width(), self.height - self.decorator.height() + x,y = msg.new_x - self.decorator.left_width(self), msg.new_y - self.decorator.top_height(self) + w,h = self.width - self.decorator.width(self), self.height - self.decorator.height(self) redraw = False if self.down_button: @@ -335,10 +335,10 @@ class OpenFileDialog(DialogWindow): def draw(self): surface = self.get_cairo_surface() - WIDTH, HEIGHT = self.width - self.decorator.width(), self.height - self.decorator.height() + WIDTH, HEIGHT = self.width - self.decorator.width(self), self.height - self.decorator.height(self) ctx = cairo.Context(surface) - ctx.translate(self.decorator.left_width(), self.decorator.top_height()) + ctx.translate(self.decorator.left_width(self), self.decorator.top_height(self)) ctx.rectangle(0,0,WIDTH,HEIGHT) ctx.set_source_rgb(204/255,204/255,204/255) ctx.fill() @@ -347,7 +347,7 @@ class OpenFileDialog(DialogWindow): #ctx.paint() self.tr.resize(WIDTH,30) - self.tr.move(self.decorator.left_width(),self.decorator.top_height()+10) + self.tr.move(self.decorator.left_width(self),self.decorator.top_height(self)+10) self.tr.set_alignment(2) self.tr.draw(self) @@ -373,7 +373,7 @@ class OpenFileDialog(DialogWindow): self.flip() def scroll(self, amount): - w,h = self.width - self.decorator.width(), self.height - self.decorator.height() + w,h = self.width - self.decorator.width(self), self.height - self.decorator.height(self) self.scroll_y += amount if self.scroll_y > 0: self.scroll_y = 0 @@ -385,8 +385,8 @@ class OpenFileDialog(DialogWindow): def mouse_event(self, msg): super(OpenFileDialog,self).mouse_event(msg) - x,y = msg.new_x - self.decorator.left_width(), msg.new_y - self.decorator.top_height() - w,h = self.width - self.decorator.width(), self.height - self.decorator.height() + x,y = msg.new_x - self.decorator.left_width(self), msg.new_y - self.decorator.top_height(self) + w,h = self.width - self.decorator.width(self), self.height - self.decorator.height(self) if y < 0: return if x < 0 or x >= w: return diff --git a/base/home/local/python-demos/input_box.py b/base/home/local/python-demos/input_box.py index 8aecfed9..2d84b31e 100755 --- a/base/home/local/python-demos/input_box.py +++ b/base/home/local/python-demos/input_box.py @@ -321,10 +321,10 @@ class TextInputWindow(yutani.Window): surface = self.get_cairo_surface() - WIDTH, HEIGHT = self.width - self.decorator.width(), self.height - self.decorator.height() + WIDTH, HEIGHT = self.width - self.decorator.width(self), self.height - self.decorator.height(self) ctx = cairo.Context(surface) - ctx.translate(self.decorator.left_width(), self.decorator.top_height()) + ctx.translate(self.decorator.left_width(self), self.decorator.top_height(self)) ctx.rectangle(0,0,WIDTH,HEIGHT) ctx.set_source_rgb(204/255,204/255,204/255) ctx.fill() @@ -346,8 +346,8 @@ class TextInputWindow(yutani.Window): """Accept a resize.""" self.resize_accept(msg.width, msg.height) self.reinit() - self.int_width = msg.width - self.decorator.width() - self.int_height = msg.height - self.decorator.height() + self.int_width = msg.width - self.decorator.width(self) + self.int_height = msg.height - self.decorator.height(self) self.draw() self.resize_done() self.flip() @@ -356,8 +356,8 @@ class TextInputWindow(yutani.Window): if self.closed: return if self.decorator.handle_event(msg) == yutani.Decor.EVENT_CLOSE: self.cancel_click(None) - x,y = msg.new_x - self.decorator.left_width(), msg.new_y - self.decorator.top_height() - w,h = self.width - self.decorator.width(), self.height - self.decorator.height() + x,y = msg.new_x - self.decorator.left_width(self), msg.new_y - self.decorator.top_height(self) + w,h = self.width - self.decorator.width(self), self.height - self.decorator.height(self) redraw = False if self.down_button: diff --git a/base/home/local/python-demos/mines.py b/base/home/local/python-demos/mines.py index cd6fba52..7fa1a8b2 100755 --- a/base/home/local/python-demos/mines.py +++ b/base/home/local/python-demos/mines.py @@ -129,7 +129,7 @@ class MinesWindow(yutani.Window): self.menubar = MenuBarWidget(self,menus) - self.tr = text_region.TextRegion(self.decorator.left_width()+5,self.decorator.top_height()+self.menubar.height,self.base_width-10,40) + self.tr = text_region.TextRegion(self.decorator.left_width(self)+5,self.decorator.top_height(self)+self.menubar.height,self.base_width-10,40) self.tr.set_font(toaru_fonts.Font(toaru_fonts.FONT_SANS_SERIF,18)) self.tr.set_alignment(2) self.tr.set_valignment(2) @@ -253,10 +253,10 @@ class MinesWindow(yutani.Window): def draw(self): surface = self.get_cairo_surface() - WIDTH, HEIGHT = self.width - self.decorator.width(), self.height - self.decorator.height() + WIDTH, HEIGHT = self.width - self.decorator.width(self), self.height - self.decorator.height(self) ctx = cairo.Context(surface) - ctx.translate(self.decorator.left_width(), self.decorator.top_height()) + ctx.translate(self.decorator.left_width(self), self.decorator.top_height(self)) ctx.rectangle(0,0,WIDTH,HEIGHT) ctx.set_source_rgb(204/255,204/255,204/255) ctx.fill() @@ -300,8 +300,8 @@ class MinesWindow(yutani.Window): sys.exit(0) elif decor_event == yutani.Decor.EVENT_RIGHT: d.show_menu(self, msg) - x,y = msg.new_x - self.decorator.left_width(), msg.new_y - self.decorator.top_height() - w,h = self.width - self.decorator.width(), self.height - self.decorator.height() + x,y = msg.new_x - self.decorator.left_width(self), msg.new_y - self.decorator.top_height(self) + w,h = self.width - self.decorator.width(self), self.height - self.decorator.height(self) if x >= 0 and x < w and y >= 0 and y < self.menubar.height: self.menubar.mouse_event(msg, x, y) diff --git a/base/home/local/python-demos/progress-bar.py b/base/home/local/python-demos/progress-bar.py index 2582adfc..5b4c61b9 100755 --- a/base/home/local/python-demos/progress-bar.py +++ b/base/home/local/python-demos/progress-bar.py @@ -59,10 +59,10 @@ class ProgressBarWindow(yutani.Window): def draw(self): surface = self.get_cairo_surface() - WIDTH, HEIGHT = self.width - self.decorator.width(), self.height - self.decorator.height() + WIDTH, HEIGHT = self.width - self.decorator.width(self), self.height - self.decorator.height(self) ctx = cairo.Context(surface) - ctx.translate(self.decorator.left_width(), self.decorator.top_height()) + ctx.translate(self.decorator.left_width(self), self.decorator.top_height(self)) ctx.rectangle(0,0,WIDTH,HEIGHT) ctx.set_source_rgb(204/255,204/255,204/255) ctx.fill() @@ -72,7 +72,7 @@ class ProgressBarWindow(yutani.Window): percent = int(100 * self.progress / self.total) self.tr.set_text(f"{percent}%") self.tr.resize(WIDTH-30,HEIGHT-self.text_offset) - self.tr.move(self.decorator.left_width() + 15,self.decorator.top_height()+self.text_offset) + self.tr.move(self.decorator.left_width(self) + 15,self.decorator.top_height(self)+self.text_offset) self.tr.draw(self) self.decorator.render(self) @@ -82,8 +82,8 @@ class ProgressBarWindow(yutani.Window): """Accept a resize.""" self.resize_accept(msg.width, msg.height) self.reinit() - self.int_width = msg.width - self.decorator.width() - self.int_height = msg.height - self.decorator.height() + self.int_width = msg.width - self.decorator.width(self) + self.int_height = msg.height - self.decorator.height(self) self.draw() self.resize_done() self.flip() @@ -92,8 +92,8 @@ class ProgressBarWindow(yutani.Window): if d.handle_event(msg) == yutani.Decor.EVENT_CLOSE: window.close() sys.exit(0) - x,y = msg.new_x - self.decorator.left_width(), msg.new_y - self.decorator.top_height() - w,h = self.width - self.decorator.width(), self.height - self.decorator.height() + x,y = msg.new_x - self.decorator.left_width(self), msg.new_y - self.decorator.top_height(self) + w,h = self.width - self.decorator.width(self), self.height - self.decorator.height(self) def keyboard_event(self, msg): pass