diff options
author | florent <florent.pigout@gmail.com> | 2011-04-28 23:18:16 (GMT) |
---|---|---|
committer | florent <florent.pigout@gmail.com> | 2011-04-28 23:18:16 (GMT) |
commit | 43fe18a121c37bcbce1e66fce0d805d60281616d (patch) | |
tree | c907d50aef9d7f3d554a9f7a7bb62d41549aa770 | |
parent | f4460e57fb45474f9c6737fe46d077e11041f75d (diff) |
manage dnd position update in edit scene
-rw-r--r-- | atoidejouer/ui/screens.py | 98 |
1 files changed, 75 insertions, 23 deletions
diff --git a/atoidejouer/ui/screens.py b/atoidejouer/ui/screens.py index fd1be69..ad9c1bd 100644 --- a/atoidejouer/ui/screens.py +++ b/atoidejouer/ui/screens.py @@ -36,23 +36,22 @@ COLOR_GREY_WHITE = ui.get_color(0.85, 0.85, 0.85) COLOR_WHITE = ui.get_color(1.0, 1.0, 1.0) -def _on_drag_finish(image, event, scene, size): - # _align = self._get_keys('graphics').set_align(sequence_name, - # frame, _current) - # DEBUG - logger.debug('[screens] _on_drag_finish - image.x: %s' % image.x) - logger.debug('[screens] _on_drag_finish - image.y: %s' % image.y) - # DEBUG - # parse size - _w , _h = size - # compute align - _x = float(image.x) / _w - _y = float(image.x) / _h - # DEBUG - logger.debug('[screens] _on_drag_finish - _x: %s' % _x) - logger.debug('[screens] _on_drag_finish - _y: %s' % _y) - # DEBUG - # TODO - compute new align +def _on_drag_finish(image, event, scene, sequence_name, frame, filename, + image_size, scene_size): + # get align values + _a_x, _a_y = scene._reverse_x_y(image_size, (image.x, image.y)) + # update keys + scene._get_keys('graphics').set_align(sequence_name, frame, filename, + (_a_x, _a_y)) + # refresh scene with rounded values + scene.refresh() + # get current screen + _screen = scene.toolbar.activity.get_current_screen() + # update position in panel + if hasattr(_screen, 'panel'): + _screen.panel.refresh() + else: + pass def _on_click(image, event, scene, sequence_name): @@ -64,7 +63,7 @@ def _on_click(image, event, scene, sequence_name): else: pass # update panel - if hasattr(_s, 'panel'): + if hasattr(_screen, 'panel'): _screen.panel.refresh() else: pass @@ -200,6 +199,27 @@ class ScreenStory(graphics.Scene): # return new values return self.__sizes[filename] + def _reverse_x_y(self, size, position): + # .. + _w, _h = size + _x, _y = position + # .. + if self.fullscreen is True\ + or self._screen_width < 1024: + _scene_with = self._screen_width + _scene_height = 516 * _scene_with / 1024.0 + else: + _scene_with = 1024 + _scene_height = 516 + # update x + _a_x = _x - (self._screen_width - _w) / 2 + _a_x = int(_a_x * 100.0 / _scene_with) + # update y + _a_y = _y - (self._screen_height - _h - 88) / 2 + _a_y = int(_a_y * 100.0 / _scene_height) + # return it + return _a_x, _a_y + def _update_x_y(self, size, align): # .. _new_w, _new_h, _w, _h = size @@ -221,6 +241,33 @@ class ScreenStory(graphics.Scene): # return it return _new_x, _new_y + def __get_scene_size(self): + # + if self.fullscreen is True\ + or self._screen_width < 1024: + _scene_with = self._screen_width + _scene_height = 516 * _scene_with / 1024.0 + else: + _scene_with = 1024 + _scene_height = 516 + # .. + return _scene_with, _scene_height + + def __get_offset(self, scene_size): + # .. + _s_with, _s_height = scene_size + # .. + _o_x = float(self._screen_width - _s_with) / 2 + _o_y = float(self._screen_height - _s_height) / 2 + # DEBUG + logger.debug('[screens] __get_offset - self._screen_width: %s' % self._screen_width) + logger.debug('[screens] __get_offset - self._screen_height: %s' % self._screen_height) + logger.debug('[screens] __get_offset - _s_with: %s' % _s_with) + logger.debug('[screens] __get_offset - _s_height: %s' % _s_height) + # DEBUG + # .. + return _o_x, _o_y - 46 + def __refresh_default(self, default_name): _code = '__%s' % default_name # ensure current image @@ -288,7 +335,8 @@ class ScreenStory(graphics.Scene): _draggable = self._set_canvas is False # .. _image = self.__update_drawing_area(_current, _size, _align, - sequence_name=sequence_name, draggable=_draggable) + sequence_name=sequence_name, frame=int(time), + draggable=_draggable) # .. self.__graphics[_code] = _image # .. @@ -297,8 +345,8 @@ class ScreenStory(graphics.Scene): # and return displayed code return _code - def __update_drawing_area(self, filename, size, align, sequence_name=None, - draggable=False): + def __update_drawing_area(self, filename, size, align, + sequence_name=None, frame=None, draggable=False): # get path _path = storage.get_image_path(filename) # update x, y @@ -307,7 +355,6 @@ class ScreenStory(graphics.Scene): _new_w, _new_h, _w, _h = size # .. _scale = float(_new_w)/_w - # _scale_y = float(_new_h)/_h # get z_order if sequence_name is None: _z_order = 1000 @@ -320,7 +367,12 @@ class ScreenStory(graphics.Scene): if self._set_canvas is True: pass else: - _image.connect('on-drag-finish', _on_drag_finish, self, (_w, _h)) + # .. + _scene_size = self.__get_scene_size() + _offset = self.__get_offset(_scene_size) + # .. + _image.connect('on-drag-finish', _on_drag_finish, self, sequence_name, + frame, filename, _offset, (_new_w, _new_h), _scene_size) # connect on click if sequence_name is None: pass |