From 1ebc89004218788b7bb67fae9c699e22d0b16365 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Thu, 4 Nov 2010 00:05:03 -0400 Subject: [PATCH 1/2] graphics: add instance() as a default context windows: create default matrix projection --- kivy/c_ext/graphics.pyx | 7 +++++++ kivy/core/window/__init__.py | 13 +++++++------ kivy/uix/widget.py | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/kivy/c_ext/graphics.pyx b/kivy/c_ext/graphics.pyx index 1cdc9a956..17f80c8a8 100644 --- a/kivy/c_ext/graphics.pyx +++ b/kivy/c_ext/graphics.pyx @@ -204,6 +204,10 @@ cdef class Shader: else: Logger.debug('Shader compiled sucessfully') +def Context_instance(): + global _default_context + print 'get', _default_context + return _default_context cdef class GraphicContext: '''Handle the saving/restore of the context @@ -224,6 +228,8 @@ cdef class GraphicContext: self._default_shader = Shader(_default_vertex_shader, _default_fragment_shader) return self._default_shader + instance = staticmethod(Context_instance) + def __cinit__(self): self.state = {} self.stack = [] @@ -393,6 +399,7 @@ cdef class Canvas: cdef list batch_slices def __cinit__(self): + global _default_context if _default_context == None: _default_context = GraphicContext() self._context = _default_context diff --git a/kivy/core/window/__init__.py b/kivy/core/window/__init__.py index ce0d3996f..f0a7a6a69 100644 --- a/kivy/core/window/__init__.py +++ b/kivy/core/window/__init__.py @@ -304,6 +304,10 @@ class WindowBase(EventDispatcher): def update_viewport(self): # XXX FIXME 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)) width, height = self.system_size w2 = width / 2. @@ -312,13 +316,9 @@ class WindowBase(EventDispatcher): # prepare the viewport glViewport(0, 0, width, height) - # set the projection - glMatrixMode(GL_PROJECTION) - glLoadIdentity() - glFrustum(-w2, w2, -h2, h2, .1, 1000) - glScalef(5000, 5000, 1) - # use the rotated size. + # XXX FIXME fix rotation + ''' width, height = self.size w2 = width / 2. h2 = height / 2. @@ -330,6 +330,7 @@ class WindowBase(EventDispatcher): glTranslatef(w2, h2, 0) glRotatef(self._rotation, 0, 0, 1) glTranslatef(-w2, -h2, 0) + ''' # update window size for w in self.children: diff --git a/kivy/uix/widget.py b/kivy/uix/widget.py index ecefc7055..3a19194c2 100644 --- a/kivy/uix/widget.py +++ b/kivy/uix/widget.py @@ -12,9 +12,8 @@ __all__ = ('Widget', ) from kivy.weakmethod import WeakMethod from kivy.c_ext.event import EventDispatcher from kivy.c_ext.properties import * -from kivy.base import EventLoop -EventLoop.ensure_window() from kivy.graphics import Canvas +from kivy.base import EventLoop class Widget(EventDispatcher): ''' @@ -64,6 +63,7 @@ class Widget(EventDispatcher): self.register_event_type('on_touch_up') self.register_event_type('on_draw') + EventLoop.ensure_window() self.canvas = Canvas() From 3b7560b2902afd8baa41ede6ab3cbf019420e67f Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Thu, 4 Nov 2010 00:05:25 -0400 Subject: [PATCH 2/2] textcanvas: remove uneeded transform_mat --- examples/testcanvas.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/testcanvas.py b/examples/testcanvas.py index 16e2d0211..9daf37f92 100644 --- a/examples/testcanvas.py +++ b/examples/testcanvas.py @@ -2,15 +2,13 @@ import kivy from kivy.base import runTouchApp from kivy.core.window import Window from kivy.core.image import Image -from kivy.graphics import Canvas, Rectangle, BorderRectangle -from kivy.lib.transformations import clip_matrix +from kivy.graphics import Canvas, Rectangle, BorderRectangle, GraphicContext img = Image('examples/test.png') c = Canvas() with c: c.context.set('color', (1,1,1,1)) - c.context.set('projection_mat', clip_matrix(0,Window.width,0,Window.height,-1,1)) BorderRectangle(size=(100, 100), texture=img.texture)