本文整理汇总了Python中kivy.graphics.transformation.Matrix方法的典型用法代码示例。如果您正苦于以下问题:Python transformation.Matrix方法的具体用法?Python transformation.Matrix怎么用?Python transformation.Matrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.graphics.transformation
的用法示例。
在下文中一共展示了transformation.Matrix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clear
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def clear(self):
self.app.unbind(wpos=self.update_tool)
if self.li:
self.remove_widget(self.li)
self.li = None
if self.select_mode:
self.stop_cursor(0, 0)
self.select_mode = False
self.ids.select_mode_but.state = 'normal'
self.valid = False
self.is_visible = False
self.canv.clear()
self.ids.surface.canvas.remove(self.canv)
self.last_target_layer = 0
# reset scale and translation
m = Matrix()
m.identity()
self.ids.surface.transform = m
# not sure why we need to do this
self.ids.surface.top = Window.height
示例2: on_touch_down
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def on_touch_down(self, touch):
#print(self.ids.surface.bbox)
if self.ids.view_window.collide_point(touch.x, touch.y):
# if within the scatter window
if self.select_mode:
touch.grab(self)
return True
elif touch.is_mouse_scrolling:
# Allow mouse scroll wheel to zoom in/out
if touch.button == 'scrolldown':
# zoom in
if self.ids.surface.scale < 100:
rescale = 1.1
self.ids.surface.apply_transform(Matrix().scale(rescale, rescale, rescale), post_multiply=True, anchor=self.ids.surface.to_widget(*touch.pos))
elif touch.button == 'scrollup':
# zoom out
if self.ids.surface.scale > 0.01:
rescale = 0.8
self.ids.surface.apply_transform(Matrix().scale(rescale, rescale, rescale), post_multiply=True, anchor=self.ids.surface.to_widget(*touch.pos))
self.moved(None, touch)
return True
return super(GcodeViewerScreen, self).on_touch_down(touch)
示例3: set_zoom_at
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def set_zoom_at(self, zoom, x, y, scale=None):
"""Sets the zoom level, leaving the (x, y) at the exact same point
in the view.
"""
zoom = clamp(zoom,
self.map_source.get_min_zoom(),
self.map_source.get_max_zoom())
if int(zoom) == int(self._zoom):
if scale is None:
return
elif scale == self.scale:
return
scale = scale or 1.
# first, rescale the scatter
scatter = self._scatter
scale = clamp(scale, scatter.scale_min, scatter.scale_max)
rescale = scale * 1.0 / scatter.scale
scatter.apply_transform(Matrix().scale(rescale, rescale, rescale),
post_multiply=True,
anchor=scatter.to_local(x, y))
# adjust position if the zoom changed
c1 = self.map_source.get_col_count(self._zoom)
c2 = self.map_source.get_col_count(zoom)
if c1 != c2:
f = float(c2) / float(c1)
self.delta_x = scatter.x + self.delta_x * f
self.delta_y = scatter.y + self.delta_y * f
# back to 0 every time
scatter.apply_transform(Matrix().translate(
-scatter.x, -scatter.y, 0
), post_multiply=True)
# avoid triggering zoom changes.
self._zoom = zoom
self.zoom = self._zoom
示例4: scale_at
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def scale_at(self, scale, x, y):
scatter = self._scatter
scale = clamp(scale, scatter.scale_min, scatter.scale_max)
rescale = scale * 1.0 / scatter.scale
scatter.apply_transform(Matrix().scale(rescale, rescale, rescale),
post_multiply=True,
anchor=scatter.to_local(x, y))
示例5: moveToCenter
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def moveToCenter(self, *args):
#This moves the simulation onto the screen, I would love if it were centered
#but for now it doesn't adapt to screen size (Window.width, Window.height)
moveVertical = self.bedHeight/1.4
moveHorizontal = self.bedWidth/1.4
mat = Matrix().translate(moveHorizontal, moveVertical, 0)
self.scatterInstance.apply_transform(mat)
#scale it down to fit on the screen
self.scatterInstance.apply_transform(Matrix().scale(.3, .3, 1))
示例6: setInitialZoom
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def setInitialZoom(self):
mat = Matrix().scale(.4, .4, 1)
self.scatterInstance.apply_transform(mat, (0,0))
mat = Matrix().translate(200, 100, 0)
self.scatterInstance.apply_transform(mat)
示例7: zoomCanvas
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def zoomCanvas(self, touch):
if touch.is_mouse_scrolling:
scaleFactor = .1
if touch.button == 'scrollup':
mat = Matrix().scale(1-scaleFactor, 1-scaleFactor, 1)
self.scatterInstance.apply_transform(mat, anchor = touch.pos)
elif touch.button == 'scrolldown':
mat = Matrix().scale(1+scaleFactor, 1+scaleFactor, 1)
self.scatterInstance.apply_transform(mat, anchor = touch.pos)
示例8: centerCanvas
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def centerCanvas(self, *args):
'''
Return the canvas to the center of the screen.
'''
mat = Matrix().translate(Window.width/2, Window.height/2, 0)
self.scatterInstance.transform = mat
anchor = (0,0)
scale = self.data.config.get('Ground Control Settings', 'viewScale')
mat = Matrix().scale(dp(scale), dp(scale), 1)
self.scatterInstance.apply_transform(mat, anchor)
示例9: on_bypass
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def on_bypass(self, instance, bypass):
if bypass:
self.transform = Matrix()
示例10: _set_rotation
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def _set_rotation(self, rotation):
angle_change = self.rotation - rotation
r = Matrix().rotate(-radians(angle_change), 0, 0, 1)
self.apply_transform(r, post_multiply=True,
anchor=self.to_local(*self.center))
示例11: _set_scale
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def _set_scale(self, scale):
rescale = scale * 1.0 / self.scale
self.apply_transform(Matrix().scale(rescale, rescale, rescale),
post_multiply=True,
anchor=self.to_local(*self.center))
示例12: _set_center
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def _set_center(self, center):
if center == self.center:
return False
t = Vector(*center) - self.center
trans = Matrix().translate(t.x, t.y, 0)
self.apply_transform(trans)
示例13: _set_pos
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def _set_pos(self, pos):
_pos = self.bbox[0]
if pos == _pos:
return
t = Vector(*pos) - _pos
trans = Matrix().translate(t.x, t.y, 0)
self.apply_transform(trans)
示例14: apply_transform
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def apply_transform(self, trans, post_multiply=False, anchor=(0, 0)):
'''
Transforms the scatter by applying the "trans" transformation
matrix (on top of its current transformation state). The resultant
matrix can be found in the :attr:`~Scatter.transform` property.
:Parameters:
`trans`: :class:`~kivy.graphics.transformation.Matrix`.
Transformation matix to be applied to the scatter widget.
`anchor`: tuple, defaults to (0, 0).
The point to use as the origin of the transformation
(uses local widget space).
`post_multiply`: bool, defaults to False.
If True, the transform matrix is post multiplied
(as if applied before the current transform).
Usage example::
from kivy.graphics.transformation import Matrix
mat = Matrix().scale(3, 3, 3)
scatter_instance.apply_transform(mat)
'''
t = Matrix().translate(anchor[0], anchor[1], 0)
t = t.multiply(trans)
t = t.multiply(Matrix().translate(-anchor[0], -anchor[1], 0))
if post_multiply:
self.transform = self.transform.multiply(t)
else:
self.transform = t.multiply(self.transform)
示例15: get_window_matrix
# 需要导入模块: from kivy.graphics import transformation [as 别名]
# 或者: from kivy.graphics.transformation import Matrix [as 别名]
def get_window_matrix(self, x=0, y=0):
'''Calculate the transformation matrix to convert between window and
widget coordinates.
:Parameters:
`x`: float, defaults to 0
Translates the matrix on the x axis.
`y`: float, defaults to 0
Translates the matrix on the y axis.
'''
m = Matrix()
m.translate(self.x + x, self.y + y, 0)
m = self._apply_transform(m)
return m