diff --git a/kivy/core/window/__init__.py b/kivy/core/window/__init__.py index f0a7a6a69..c972c754e 100644 --- a/kivy/core/window/__init__.py +++ b/kivy/core/window/__init__.py @@ -306,6 +306,7 @@ class WindowBase(EventDispatcher): from kivy.core.gl import * from kivy.graphics import GraphicContext from kivy.lib.transformations import clip_matrix + context = GraphicContext.instance() context.set('projection_mat', clip_matrix(0, self.width, 0, self.height, -1, 1)) diff --git a/kivy/factory.py b/kivy/factory.py index 036f5f581..5b9d02ac2 100644 --- a/kivy/factory.py +++ b/kivy/factory.py @@ -63,6 +63,8 @@ class FactoryBase(object): return cls + get = __getattr__ + #: Factory instance to use for getting new classes Factory = FactoryBase() diff --git a/kivy/factory_registers.py b/kivy/factory_registers.py index 5b585f00c..3f4024b94 100644 --- a/kivy/factory_registers.py +++ b/kivy/factory_registers.py @@ -26,3 +26,4 @@ Factory.register('TouchFactory', module='kivy.input.factory') Factory.register('TouchShape', module='kivy.input.shape') Factory.register('TouchShapeRect', module='kivy.input.shape') Factory.register('Widget', module='kivy.uix.widget') +Factory.register('Button', module='kivy.uix.button') diff --git a/kivy/uix/button.py b/kivy/uix/button.py new file mode 100644 index 000000000..a22381ba3 --- /dev/null +++ b/kivy/uix/button.py @@ -0,0 +1,40 @@ +''' +Button: +''' + +__all__ = ('Button', ) + +from kivy.uix.widget import Widget +from kivy.c_ext.properties import OptionProperty + +class Button(Widget): + + state = OptionProperty(['normal', 'down']) + + def __init__(self, **kwargs): + super(Button, self).__init__(**kwargs) + self.register_event_type('on_press') + self.register_event_type('on_release') + + def on_touch_down(self, touch): + if not self.collide_point(touch.x, touch.y): + return False + if self in touch.userdata: + return False + touch.grab(self) + touch.userdata[self] = True + self.state = 'down' + self.dispatch('on_press') + return True + + def on_touch_move(self, touch): + return self in touch.userdata + + def on_touch_up(self, touch): + if not self in touch.userdata: + return False + touch.ungrab(self) + self.state = 'normal' + self.dispatch('on_release') + return True +