Merge branch 'master' into core-gl-reload

This commit is contained in:
Mathieu Virbel 2012-03-02 01:09:52 +01:00
commit 4ee7014da9
9 changed files with 77 additions and 23 deletions

View File

@ -195,6 +195,8 @@ class WindowBase(EventDispatcher):
Fired when a key is down Fired when a key is down
`on_key_up`: key, scancode, unicode `on_key_up`: key, scancode, unicode
Fired when a key is up Fired when a key is up
`on_dropfile`: str
Fired when a file is dropped on the application
''' '''
__instance = None __instance = None
@ -367,6 +369,7 @@ class WindowBase(EventDispatcher):
self.register_event_type('on_keyboard') self.register_event_type('on_keyboard')
self.register_event_type('on_key_down') self.register_event_type('on_key_down')
self.register_event_type('on_key_up') self.register_event_type('on_key_up')
self.register_event_type('on_dropfile')
super(WindowBase, self).__init__() super(WindowBase, self).__init__()
@ -714,6 +717,19 @@ class WindowBase(EventDispatcher):
'''Event called when a key is up (same arguments as on_keyboard)''' '''Event called when a key is up (same arguments as on_keyboard)'''
pass pass
def on_dropfile(self, filename):
'''Event called when a file is dropped on the application.
.. warning::
This event is actually used only on MacOSX with a patched version of
pygame. But this will be a place for a further evolution (ios,
android etc.)
.. versionadded:: 1.1.2
'''
pass
def configure_keyboards(self): def configure_keyboards(self):
# Configure how to provide keyboards (virtual or not) # Configure how to provide keyboards (virtual or not)

View File

@ -274,6 +274,11 @@ class WindowPygame(WindowBase):
elif event.type == pygame.ACTIVEEVENT: elif event.type == pygame.ACTIVEEVENT:
pass pass
# drop file (pygame patch needed)
elif event.type == pygame.USEREVENT and hasattr(pygame,
'USEREVENT_DROPFILE') and event.code == pygame.USEREVENT_DROPFILE:
self.dispatch('on_dropfile', event.filename)
''' '''
# unhandled event ! # unhandled event !
else: else:

View File

@ -33,7 +33,7 @@
rgba: self.parent.background_color if self.parent else (1, 1, 1, 1) rgba: self.parent.background_color if self.parent else (1, 1, 1, 1)
BorderImage: BorderImage:
border: self.parent.border if self.parent else (16, 16, 16, 16) border: self.parent.border if self.parent else (16, 16, 16, 16)
texture: root.parent.background_texture if root.parent else None texture: root.parent._bk_img.texture if root.parent else None
size: self.size size: self.size
pos: self.pos pos: self.pos

View File

@ -418,6 +418,9 @@ cdef class Callback(Instruction):
cdef Shader shader cdef Shader shader
cdef int i cdef int i
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
glBindBuffer(GL_ARRAY_BUFFER, 0)
if self.func(self): if self.func(self):
self.flag_update_done() self.flag_update_done()

View File

@ -34,6 +34,10 @@ cdef class VertexBatch:
cdef Buffer vbo_index cdef Buffer vbo_index
cdef GLuint mode cdef GLuint mode
cdef str mode_str cdef str mode_str
cdef GLuint id
cdef int usage
cdef int elements_size
cdef int need_upload
cdef void clear_data(self) cdef void clear_data(self)
cdef void set_data(self, vertex_t *vertices, int vertices_count, cdef void set_data(self, vertex_t *vertices, int vertices_count,

View File

@ -129,16 +129,27 @@ cdef class VBO:
cdef class VertexBatch: cdef class VertexBatch:
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.usage = GL_DYNAMIC_DRAW
cdef object lushort = sizeof(unsigned short) cdef object lushort = sizeof(unsigned short)
self.vbo = kwargs.get('vbo') self.vbo = kwargs.get('vbo')
if self.vbo is None: if self.vbo is None:
self.vbo = VBO() self.vbo = VBO()
self.vbo_index = Buffer(lushort) #index of every vertex in the vbo self.vbo_index = Buffer(lushort) #index of every vertex in the vbo
self.elements = Buffer(lushort) #indices translated to vbo indices self.elements = Buffer(lushort) #indices translated to vbo indices
self.elements_size = 0
self.need_upload = 1
glGenBuffers(1, &self.id)
self.set_data(NULL, 0, NULL, 0) self.set_data(NULL, 0, NULL, 0)
self.set_mode(kwargs.get('mode')) self.set_mode(kwargs.get('mode'))
def __dealloc__(self):
# Add texture deletion outside GC call.
if _vbo_release_list is not None:
_vbo_release_list.append(self.id)
if _vbo_release_trigger is not None:
_vbo_release_trigger()
cdef void clear_data(self): cdef void clear_data(self):
# clear old vertices from vbo and then reset index buffer # clear old vertices from vbo and then reset index buffer
self.vbo.remove_vertex_data(<unsigned short*>self.vbo_index.pointer(), self.vbo.remove_vertex_data(<unsigned short*>self.vbo_index.pointer(),
@ -146,7 +157,6 @@ cdef class VertexBatch:
self.vbo_index.clear() self.vbo_index.clear()
self.elements.clear() self.elements.clear()
cdef void set_data(self, vertex_t *vertices, int vertices_count, cdef void set_data(self, vertex_t *vertices, int vertices_count,
unsigned short *indices, int indices_count): unsigned short *indices, int indices_count):
#clear old vertices first #clear old vertices first
@ -155,6 +165,7 @@ cdef class VertexBatch:
# now append the vertices and indices to vbo # now append the vertices and indices to vbo
self.append_data(vertices, vertices_count, indices, indices_count) self.append_data(vertices, vertices_count, indices, indices_count)
self.need_upload = 1
cdef void append_data(self, vertex_t *vertices, int vertices_count, cdef void append_data(self, vertex_t *vertices, int vertices_count,
unsigned short *indices, int indices_count): unsigned short *indices, int indices_count):
@ -174,12 +185,28 @@ cdef class VertexBatch:
for i in xrange(indices_count): for i in xrange(indices_count):
local_index = indices[i] local_index = indices[i]
self.elements.add(&vbi[local_index], NULL, 1) self.elements.add(&vbi[local_index], NULL, 1)
self.need_upload = 1
cdef void draw(self): cdef void draw(self):
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.id)
# cache indices in a gpu buffer too
if self.need_upload:
if self.elements_size == self.elements.size():
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, self.elements_size,
self.elements.pointer())
else:
glBufferData(GL_ELEMENT_ARRAY_BUFFER, self.elements.size(),
self.elements.pointer(), self.usage)
self.elements_size = self.elements.size()
self.need_upload = 0
self.vbo.bind() self.vbo.bind()
glDrawElements(self.mode, self.elements.count(), glDrawElements(self.mode, self.elements.count(),
GL_UNSIGNED_SHORT, self.elements.pointer()) GL_UNSIGNED_SHORT, NULL)
self.vbo.unbind()
# XXX if the user is doing its own things, Callback instruction will
# reset the context.
# self.vbo.unbind()
# glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
cdef void set_mode(self, str mode): cdef void set_mode(self, str mode):
# most common case in top; # most common case in top;

View File

@ -131,13 +131,6 @@ class Bubble(GridLayout):
default to 'bottom_mid'. default to 'bottom_mid'.
''' '''
background_texture = ObjectProperty(None)
'''Specifies the background texture of the bubble
:data:`background_texture` is a :class:`~kivy.properties.ObjectProperty`,
default to 'None'.
'''
content = ObjectProperty(None) content = ObjectProperty(None)
'''This is the object where the main content of the bubble is held '''This is the object where the main content of the bubble is held
@ -165,12 +158,8 @@ class Bubble(GridLayout):
self.content = content = BubbleContent(parent=self) self.content = content = BubbleContent(parent=self)
super(Bubble, self).__init__(**kwargs) super(Bubble, self).__init__(**kwargs)
self.add_widget(content) self.add_widget(content)
self._bk_img.bind(on_texture=self._on_texture)
self.on_arrow_pos() self.on_arrow_pos()
def _on_texture(self, *l):
self.background_texture = self._bk_img.texture
def add_widget(self, *l): def add_widget(self, *l):
content = self.content content = self.content
if content is None: if content is None:

View File

@ -67,7 +67,8 @@ class Button(Label):
default to [1, 1, 1, 1]. default to [1, 1, 1, 1].
''' '''
background_normal = StringProperty('atlas://data/images/defaulttheme/button') background_normal = StringProperty(
'atlas://data/images/defaulttheme/button')
'''Background image of the button used for default graphical representation, '''Background image of the button used for default graphical representation,
when the button is not pressed. when the button is not pressed.
@ -77,7 +78,8 @@ class Button(Label):
default to 'atlas://data/images/defaulttheme/button' default to 'atlas://data/images/defaulttheme/button'
''' '''
background_down = StringProperty('atlas://data/images/defaulttheme/button_pressed') background_down = StringProperty(
'atlas://data/images/defaulttheme/button_pressed')
'''Background image of the button used for default graphical representation, '''Background image of the button used for default graphical representation,
when the button is pressed. when the button is pressed.
@ -111,6 +113,8 @@ class Button(Label):
self.state = 'normal' self.state = 'normal'
def on_touch_down(self, touch): def on_touch_down(self, touch):
if super(Button, self).on_touch_down(touch):
return True
if not self.collide_point(touch.x, touch.y): if not self.collide_point(touch.x, touch.y):
return False return False
if self in touch.ud: if self in touch.ud:
@ -122,11 +126,15 @@ class Button(Label):
return True return True
def on_touch_move(self, touch): def on_touch_move(self, touch):
if touch.grab_current is self:
return True
if super(Button, self).on_touch_move(touch):
return True
return self in touch.ud return self in touch.ud
def on_touch_up(self, touch): def on_touch_up(self, touch):
if touch.grab_current is not self: if touch.grab_current is not self:
return return super(Button, self).on_touch_up(touch)
assert(self in touch.ud) assert(self in touch.ud)
touch.ungrab(self) touch.ungrab(self)
self._do_release() self._do_release()

View File

@ -179,6 +179,8 @@ class Label(Widget):
self.texture_size = list(self.texture.size) self.texture_size = list(self.texture.size)
def on_touch_down(self, touch): def on_touch_down(self, touch):
if super(Label, self).on_touch_down(touch):
return True
if not len(self.refs): if not len(self.refs):
return False return False
tx, ty = touch.pos tx, ty = touch.pos