mirror of https://github.com/kivy/kivy.git
graphics: add instance() as a default context
windows: create default matrix projection
This commit is contained in:
parent
f4be7975fc
commit
1ebc890042
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue