Skip to content

Commit

Permalink
Fixes to the flash color of the portals.
Browse files Browse the repository at this point in the history
  • Loading branch information
groboclown committed Dec 2, 2016
1 parent d18ddd9 commit a5a27e7
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions src/petronia/shell/view/portal_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def __init__(self, portal_id, bus, pos_x, pos_y, width, height, manager):
# Make configuration better
self.color_1 = 0
self.color_2 = 0
self.color_1f = 0x202020
self.color_2f = 0x202020
self._flashing = False
self._use_flash_color = False
self.accent_width = 64

left, right, top, bottom = manager.get_chrome_size(pos_x, pos_y, width, height)
Expand All @@ -69,23 +73,29 @@ def set_portal_size(self, pos_x, pos_y, width, height):
self.move_resize(left, top, right - left, bottom - top, self._is_active)

def _on_paint(self, hwnd, hdc, width, height):
self._draw_rect(hdc, 0, 0, width, height, self.color_1)
c1 = self.color_1
c2 = self.color_2
if self._use_flash_color:
c1 = self.color_1f
c2 = self.color_2f
self._log_debug("Using colors #{0} #{1}".format(hex(c1), hex(c2)))
self._draw_rect(hdc, 0, 0, width, height, c1)
if width >= self.accent_width * 3:
if height >= self.accent_width * 3:
# 4 corners of color
self._draw_rect(hdc, 0, 0, self.accent_width, self.accent_width, self.color_2)
self._draw_rect(hdc, width - self.accent_width, 0, self.accent_width, self.accent_width, self.color_2)
self._draw_rect(hdc, 0, height - self.accent_width, self.accent_width, self.accent_width, self.color_2)
self._draw_rect(hdc, 0, 0, self.accent_width, self.accent_width, c2)
self._draw_rect(hdc, width - self.accent_width, 0, self.accent_width, self.accent_width, c2)
self._draw_rect(hdc, 0, height - self.accent_width, self.accent_width, self.accent_width, c2)
self._draw_rect(hdc, width - self.accent_width, height - self.accent_width, self.accent_width,
self.accent_width, self.color_2)
self.accent_width, c2)
else:
# Vertical bars of color
self._draw_rect(hdc, 0, 0, self.accent_width, height, self.color_2)
self._draw_rect(hdc, width - self.accent_width, 0, self.accent_width, height, self.color_2)
self._draw_rect(hdc, 0, 0, self.accent_width, height, c2)
self._draw_rect(hdc, width - self.accent_width, 0, self.accent_width, height, c2)
elif height >= self.accent_width * 3:
# Horizontal bars of color
self._draw_rect(hdc, 0, 0, width, self.accent_width, self.color_2)
self._draw_rect(hdc, 0, height - self.accent_width, width, self.accent_width, self.color_2)
self._draw_rect(hdc, 0, 0, width, self.accent_width, c2)
self._draw_rect(hdc, 0, height - self.accent_width, width, self.accent_width, c2)

# noinspection PyUnusedLocal
def _on_portal_removed(self, event_id, target_id, event_obj):
Expand All @@ -108,21 +118,19 @@ def _on_border_size_change(self, event_id, target_id, event_obj):

# noinspection PyUnusedLocal
def _on_portal_flashing(self, event_id, target_id, event_obj):
self._log_verbose("Flashing portal chrome {0}".format(self.cid))
color_c1 = self.color_1
color_c2 = self.color_2
color_f1 = _brighten_color(self.color_1)
color_f2 = _brighten_color(self.color_2)
self._log_debug("Flashing portal chrome {0}".format(self.cid))

def flash():
# Just flash once. Windows will send a message if another flash is required.
self.color_1 = color_f1
self.color_2 = color_f2
if self._flashing:
return
self._flashing = True
self._use_flash_color = True
self.draw()
time.sleep(self._manager.flash_time)
self.color_1 = color_c1
self.color_2 = color_c2
self._use_flash_color = False
self.draw()
self._flashing = False

threading.Thread(
target=flash,
Expand All @@ -143,6 +151,8 @@ def _on_portal_activated(self, event_id, target_id, event_obj):
height = portal_size['height']

self.color_1, self.color_2 = self._manager.active_colors
self.color_1f = _brighten_color(self.color_1)
self.color_2f = _brighten_color(self.color_2)
self.set_portal_size(pos_x, pos_y, width, height)
self.draw()

Expand All @@ -160,6 +170,8 @@ def _on_portal_deactivated(self, event_id, target_id, event_obj):
height = portal_size['height']

self.color_1, self.color_2 = self._manager.inactive_colors
self.color_1f = _brighten_color(self.color_1)
self.color_2f = _brighten_color(self.color_2)
self.set_portal_size(pos_x, pos_y, width, height)
self.draw()

Expand All @@ -169,7 +181,7 @@ def _brighten_color(c):
r = (c >> 16) & 0xff
g = (c >> 8) & 0xff
b = c & 0xff
return ((max(0xff, r << 1) << 16) & 0xff0000) | ((max(0xff, g << 1) << 8) & 0xff00) | (max(0xff, b << 1) & 0xff)
return ((min(0xff, r << 1) << 16) & 0xff0000) | ((min(0xff, g << 1) << 8) & 0xff00) | (min(0xff, b << 1) & 0xff)


def _darken_color(c):
Expand Down Expand Up @@ -199,8 +211,8 @@ def __init__(self, bus, config):
self._inactive_color2 = 0x404040
self._position = 'bottom'
self._width = 10
self.flash_time = 1.2
self.flash_count = 3
self.flash_time = 0.8
self.flash_count = 3 # FIXME remove
self.update_border()

@property
Expand Down Expand Up @@ -287,5 +299,7 @@ def _on_portal_resized(self, event_id, target_id, event_obj):
gui = _PortalGuiWindow(target_id, self._bus, pos_x, pos_y, width, height, self)
gui.color_1 = self._inactive_color1
gui.color_2 = self._inactive_color2
gui.color_1f = _brighten_color(self._inactive_color1)
gui.color_2f = _brighten_color(self._inactive_color2)
# TODO setup flash
self.__portal_map[target_id]['gui'] = gui

0 comments on commit a5a27e7

Please sign in to comment.