Texture browser: Added scrolling.
You can scroll indefinitely for now. Might fix that in a later commit.
This commit is contained in:
parent
f0d829da49
commit
d5139c767e
@ -31,6 +31,7 @@ import pillarsdk
|
|||||||
from . import async_loop, pillar, cache
|
from . import async_loop, pillar, cache
|
||||||
|
|
||||||
REQUIRED_ROLES_FOR_TEXTURE_BROWSER = {'subscriber', 'demo'}
|
REQUIRED_ROLES_FOR_TEXTURE_BROWSER = {'subscriber', 'demo'}
|
||||||
|
MOUSE_SCROLL_PIXELS_PER_TICK = 50
|
||||||
|
|
||||||
ICON_WIDTH = 128
|
ICON_WIDTH = 128
|
||||||
ICON_HEIGHT = 128
|
ICON_HEIGHT = 128
|
||||||
@ -230,6 +231,8 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
|
|
||||||
mouse_x = 0
|
mouse_x = 0
|
||||||
mouse_y = 0
|
mouse_y = 0
|
||||||
|
scroll_offset = 0
|
||||||
|
scroll_offset_target = 0
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
# Refuse to start if the file hasn't been saved.
|
# Refuse to start if the file hasn't been saved.
|
||||||
@ -259,6 +262,7 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
|
|
||||||
self.current_display_content = []
|
self.current_display_content = []
|
||||||
self.loaded_images = set()
|
self.loaded_images = set()
|
||||||
|
self._scroll_reset()
|
||||||
|
|
||||||
context.window.cursor_modal_set('DEFAULT')
|
context.window.cursor_modal_set('DEFAULT')
|
||||||
async_loop.AsyncModalOperatorMixin.invoke(self, context, event)
|
async_loop.AsyncModalOperatorMixin.invoke(self, context, event)
|
||||||
@ -276,6 +280,7 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
async_loop.ensure_async_loop()
|
async_loop.ensure_async_loop()
|
||||||
|
|
||||||
if event.type == 'TIMER':
|
if event.type == 'TIMER':
|
||||||
|
self._scroll_smooth()
|
||||||
context.area.tag_redraw()
|
context.area.tag_redraw()
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
@ -298,6 +303,14 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
else:
|
else:
|
||||||
context.window.cursor_set('DEFAULT')
|
context.window.cursor_set('DEFAULT')
|
||||||
|
|
||||||
|
# Scrolling
|
||||||
|
if event.type == 'WHEELUPMOUSE':
|
||||||
|
self._scroll_by(MOUSE_SCROLL_PIXELS_PER_TICK)
|
||||||
|
context.area.tag_redraw()
|
||||||
|
elif event.type == 'WHEELDOWNMOUSE':
|
||||||
|
self._scroll_by(-MOUSE_SCROLL_PIXELS_PER_TICK)
|
||||||
|
context.area.tag_redraw()
|
||||||
|
|
||||||
if left_mouse_release:
|
if left_mouse_release:
|
||||||
if selected is None:
|
if selected is None:
|
||||||
# No item clicked, ignore it.
|
# No item clicked, ignore it.
|
||||||
@ -445,6 +458,7 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
self.log.info('Asynchronously downloading previews to %r', thumbnails_directory)
|
self.log.info('Asynchronously downloading previews to %r', thumbnails_directory)
|
||||||
self.log.info('Current BCloud path is %r', self.current_path)
|
self.log.info('Current BCloud path is %r', self.current_path)
|
||||||
self.clear_images()
|
self.clear_images()
|
||||||
|
self._scroll_reset()
|
||||||
|
|
||||||
def thumbnail_loading(node, texture_node):
|
def thumbnail_loading(node, texture_node):
|
||||||
self.add_menu_item(node, None, 'SPINNER', texture_node['name'])
|
self.add_menu_item(node, None, 'SPINNER', texture_node['name'])
|
||||||
@ -557,11 +571,19 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
bgl.glRectf(0, 0, window_region.width, window_region.height)
|
bgl.glRectf(0, 0, window_region.width, window_region.height)
|
||||||
|
|
||||||
if self.current_display_content:
|
if self.current_display_content:
|
||||||
|
# The -1 / +2 are for extra rows that are drawn only half at the top/bottom.
|
||||||
|
first_item_idx = max(0, int(-self.scroll_offset // block_height - 1) * col_count)
|
||||||
|
items_per_page = int(content_height // item_height + 2) * col_count
|
||||||
|
last_item_idx = first_item_idx + items_per_page
|
||||||
|
|
||||||
for item_idx, item in enumerate(self.current_display_content):
|
for item_idx, item in enumerate(self.current_display_content):
|
||||||
x = content_x + (item_idx % col_count) * block_width
|
x = content_x + (item_idx % col_count) * block_width
|
||||||
y = content_y - (item_idx // col_count) * block_height
|
y = content_y - (item_idx // col_count) * block_height - self.scroll_offset
|
||||||
|
|
||||||
item.update_placement(x, y, item_width, item_height)
|
item.update_placement(x, y, item_width, item_height)
|
||||||
|
|
||||||
|
if first_item_idx <= item_idx < last_item_idx:
|
||||||
|
# Only draw if the item is actually on screen.
|
||||||
item.draw(highlighted=item.hits(self.mouse_x, self.mouse_y))
|
item.draw(highlighted=item.hits(self.mouse_x, self.mouse_y))
|
||||||
else:
|
else:
|
||||||
font_id = 0
|
font_id = 0
|
||||||
@ -713,6 +735,23 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
|
|||||||
|
|
||||||
self.report({'INFO'}, 'We just started a browser for you.')
|
self.report({'INFO'}, 'We just started a browser for you.')
|
||||||
|
|
||||||
|
def _scroll_smooth(self):
|
||||||
|
diff = self.scroll_offset_target - self.scroll_offset
|
||||||
|
if diff == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
if abs(round(diff)) < 1:
|
||||||
|
self.scroll_offset = self.scroll_offset_target
|
||||||
|
return
|
||||||
|
|
||||||
|
self.scroll_offset += diff * 0.5
|
||||||
|
|
||||||
|
def _scroll_by(self, amount):
|
||||||
|
self.scroll_offset_target = min(0, self.scroll_offset_target + amount)
|
||||||
|
|
||||||
|
def _scroll_reset(self):
|
||||||
|
self.scroll_offset_target = self.scroll_offset = 0
|
||||||
|
|
||||||
|
|
||||||
# store keymaps here to access after registration
|
# store keymaps here to access after registration
|
||||||
addon_keymaps = []
|
addon_keymaps = []
|
||||||
|
Reference in New Issue
Block a user