On Sat, Oct 18, 2008 at 6:44 PM, Timothy Ball <[EMAIL PROTECTED]> wrote:
>
> Lucio,
> I was trying to do something similar to do this and I didn't follow
> what you ment by "adding pyglet.text.document.UnformattedDocument to
> the batch" method.
>
> can you please explain that?
>
class textInputLayer(cocos.layer.Layer):
# For the layer to receive events this variable must be set to 'True'
is_event_handler = True
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs):
super(textInputLayer, self).__init__()
self.batch = pyglet.graphics.Batch()
self.labels = [
Label('Name', x=10, y=100, anchor_y='bottom', color=(0, 0,0, 255)),
]
map(self.add, self.labels)
self.width, self.height = director.get_window_size()
self.widgets = [
TextWidget('Zip', 200, 100, self.width - 210,self.batch),
]
self.text_cursor = director.window.get_system_mouse_cursor('text')
map(self.add, self.widgets)
self.focus = None
self.set_focus(self.widgets[0])
Here he creates all his TextWidgets, all he does is 'add' them to the
cocosnode. All this means is that the "draw" method will be called for
every frame. (it means more stuff, but for this case, thats enough)
class TextWidget(CocosNode):
def __init__(self, text, x, y, width, batch):
super(TextWidget, self).__init__()
self.document = pyglet.text.document.UnformattedDocument(text)
self.document.set_style(0, len(self.document.text),
dict(color=(0, 0, 0, 255))
)
font = self.document.get_font()
height = font.ascent - font.descent
self.layout = pyglet.text.layout.IncrementalTextLayout(
self.document, width, height, multiline=False,
batch=batch)
self.caret = pyglet.text.caret.Caret(self.layout)
self.layout.x = x
self.layout.y = y
Here he defines his text widget. He doesnt override on_draw, so
nothing gets drawn. Ever.
When he is creating the widgets, he also uses a batch, where all
widgets belong. but no is calling batch.draw. So, again, thers nothing
on screen.
So, the solution can be:
Do a TextWidget.draw function that knows how to render TextWidgets
(most likely just self.layout.draw() or something like that)
Do a textInputLayer.draw function that does self.batch.draw.
Hope this helps.
Lucio.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cocos-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---