当前位置: 首页>>代码示例>>Python>>正文


Python Label.draw方法代码示例

本文整理汇总了Python中pyglet.text.Label.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Label.draw方法的具体用法?Python Label.draw怎么用?Python Label.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyglet.text.Label的用法示例。


在下文中一共展示了Label.draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Button

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class Button(Rectangle):
    def __init__(self, x, y, width, height, image=None, caption=None, batch=None, group=None):
        super(Button, self).__init__(x, y, width, height)
        self.batch = batch
        self.group = group
        self.sprite = None
        self.label = None
        if image:
            self.sprite = Sprite(image.get_region(0, 0, self.width, self.height), batch=self.batch, group=self.group)
        if caption:
            self.label = Label(caption, font_name='Arial', font_size=12,
                anchor_x='center', anchor_y='center', color=(255, 255, 255, 255), batch=self.batch,
                group=self.group)
        self.set_position(x, y)
	
    def set_position(self, x, y):
        super(Button, self).set_position(x, y)
        if self.sprite:
            self.sprite.x, self.sprite.y = x, y
        if self.label:
            self.label.x, self.label.y = self.get_center()

    def draw(self):
        if self.sprite:
            self.sprite.draw()
        if self.label:
            self.label.draw()
开发者ID:caront,项目名称:Minecraft,代码行数:29,代码来源:gui.py

示例2: QuitScreen

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class QuitScreen(MenuClass):
    """docstring for QuitScreen"""
    def __init__(self, *args, **kwargs):
        super(QuitScreen, self).__init__(*args, **kwargs)
        self.buttons['quit'] = btn([300, 300], 'yes')
        self.buttons['dont_quit'] = btn([680, 300], 'no')
        self.text = 'do you really want to quit?'
        self.Label = Label(self.text, font_name=font,
                           font_size=36, bold=False,
                           x=640,
                           y=500,
                           anchor_x='center', anchor_y='center')
        self.Box = Box([340, 200], [600, 400], 2)

    def handle_clicks(self, key):
        if key == 'quit':
            self.send_message('kill_self')
        if key == 'dont_quit':
            self.send_message('menu_transition_-')

    def draw(self):
        self.Box.draw()
        for key_, panel in self.buttons.iteritems():
            panel.draw()
        self.Label.draw()
开发者ID:ashisdhara,项目名称:python_game,代码行数:27,代码来源:screens.py

示例3: draw_text

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
def draw_text(text, x, y, position, font_size):
    score = Label(
        text,
        font_name='League Gothic',
        font_size=font_size,
        x=x, y=y, anchor_x=position)
    score.draw()
开发者ID:SDRU,项目名称:had,代码行数:9,代码来源:draw.py

示例4: UIHarvestChoose

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class UIHarvestChoose(Panel, InputHandler):
    def __init__(self, trans, *a, **k):
        self.trans = trans
        cards = trans.cards
        self.inputlet = None

        w = 20 + (91 + 10) * 4 + 20
        h = 20 + 125 + 20 + 125 + 20 + 20

        self.lbl = Label(
            text=u"等待其他玩家操作", x=w//2, y=300, font_size=12,
            color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230),
            anchor_x='center', anchor_y='bottom'
        )

        Panel.__init__(self, width=1, height=1, zindex=5, *a, **k)
        parent = self.parent
        self.x, self.y = (parent.width - w)//2, (parent.height - h)//2 + 20
        self.width, self.height = w, h
        self.update()

        self.mapping = mapping = {}
        for i, c in enumerate(cards):
            y, x = divmod(i, 4)
            x, y = 20 + (91 + 10) * x, 20 + (125 + 20) * (1 - y)
            cs = CardSprite(c, parent=self, x=x, y=y)
            cs.associated_card = c
            mapping[id(c)] = cs

            @cs.event
            def on_mouse_dblclick(x, y, button, modifier, cs=cs):
                if cs.gray: return
                ilet = self.inputlet
                if not ilet: return
                ilet.set_card(cs.associated_card)
                ilet.done()

    def draw(self):
        Panel.draw(self)
        self.lbl.draw()

    def process_user_input_start(self, ilet):
        self.lbl.text = u'等待%s选择卡牌' % (ilet.actor.ui_meta.name)
        self.lbl.color = (255, 255, 160, 255)

    def process_user_input(self, ilet):
        assert ilet.actor is Game.getgame().me
        self.inputlet = ilet
        self.lbl.text = u'请你选择一张卡牌'
        self.lbl.color = (160, 251, 255, 255)

    def process_user_input_finish(self, ilet, rst):
        self.lbl.text = u'等待其他玩家操作'
        self.lbl.color = (255, 255, 160, 255)
        self.inputlet = None

    def on_harvest_choose(self, card):
        self.mapping[id(card)].gray = True
开发者ID:feisuzhu,项目名称:thbattle,代码行数:60,代码来源:inputs.py

示例5: drawLabel

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
def drawLabel(text, pos=(0,0),center=True):
    _standard_label = Label(text='standard Label', font_size=200,bold=True, color=(255,255,255,75))
    _standard_label.anchor_x = 'left'
    _standard_label.anchor_y = 'bottom'
    _standard_label.x = 0
    _standard_label.y = 0
    _standard_label.text = text
    glPushMatrix()
    glTranslated(pos[0], pos[1], 0.0)
    glScaled(0.3,0.3,1)
    _standard_label.draw()
    glPopMatrix()
开发者ID:patali,项目名称:toccoui,代码行数:14,代码来源:bloop.py

示例6: drawLabel

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
def drawLabel(text, pos=(0,0),center=True,alpha = 75,scale=0.3,red=255,green=255,blue=255):
    _standard_label = Label(text='standard Label', font_size=200,bold=True, color=(red,green,blue,alpha))
    _standard_label.anchor_x = 'left'
    _standard_label.anchor_y = 'bottom'
    _standard_label.x = 0
    _standard_label.y = 0
    _standard_label.text = text
    glPushMatrix()
    glTranslated(pos[0], pos[1], 0.0)
    glScaled(scale,scale,1)
    _standard_label.draw()
    glPopMatrix()
开发者ID:azoon,项目名称:pymt,代码行数:14,代码来源:explosions.py

示例7: drawLabel

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
def drawLabel(text, pos=(0, 0), center=True, textcolor=(255, 255, 255, 75)):
    _standard_label = Label(text="standard Label", font_size=200, bold=True, color=textcolor)
    _standard_label.anchor_x = "center"
    _standard_label.anchor_y = "center"
    _standard_label.x = 0
    _standard_label.y = 0
    _standard_label.text = text
    glPushMatrix()
    glTranslated(pos[0], pos[1], 0.0)
    glScaled(0.3, 0.3, 1)
    _standard_label.draw()
    glPopMatrix()
开发者ID:patali,项目名称:toccoui,代码行数:14,代码来源:newlauncher.py

示例8: Label

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class Label(Control):
    def __init__(self, text=u'Label',
                font_size=30, color=(0,0,0,255),
                x=0, y=0, bold=False, italic=False, *a, **k):
        self.rawlabel = RawLabel(
            text=text, font_size=font_size,
            color=color,x=0,y=0,
            anchor_x='left', anchor_y='bottom',
            bold=bold, italic=italic
        )
        w, h = self.rawlabel.content_width, self.rawlabel.content_height
        Control.__init__(self, x=x, y=y, width=w, height=h, *a, **k)

    def draw(self):
        self.rawlabel.draw()
开发者ID:17night,项目名称:thbattle,代码行数:17,代码来源:layouter.py

示例9: Button

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class Button(pyglet.event.EventDispatcher, Rectangle):
    def __init__(self, parent, x, y, width, height, image=None, image_highlighted=None, caption=None, batch=None, group=None, label_group=None, font_name=G.DEFAULT_FONT):
        super(Button, self).__init__(x, y, width, height)
        parent.push_handlers(self)
        self.batch, self.group, self.label_group = batch, group, label_group
        self.sprite = image_sprite(image, self.batch, self.group)
        self.sprite_highlighted = hidden_image_sprite(image_highlighted, self.batch, self.group)
        self.highlighted = False
        self.label = Label(str(caption), font_name, 12, anchor_x='center', anchor_y='center',
            color=(255, 255, 255, 255), batch=self.batch, group=self.label_group) if caption else None
        self.position = x, y

    @property
    def position(self):
        return self.x, self.y

    @position.setter
    def position(self, position):
        self.x, self.y = position
        if hasattr(self, 'sprite') and self.sprite:
            self.sprite.x, self.sprite.y = position
        if hasattr(self, 'sprite_highlighted') and self.sprite_highlighted:
            self.sprite_highlighted.x, self.sprite_highlighted.y = position
        if hasattr(self, 'label') and self.label:
            self.label.x, self.label.y = self.center

    def draw(self):
        self.draw_sprite()
        self.draw_label()

    def draw_sprite(self):
        if self.sprite and not (self.sprite_highlighted and self.highlighted):
            self.sprite_highlighted.visible, self.sprite.visible = False, True
            self.sprite.draw()
        elif self.sprite_highlighted and self.highlighted:
            self.sprite_highlighted.visible, self.sprite.visible = True, False
            self.sprite_highlighted.draw()

    def draw_label(self):
        if self.label:
            self.label.draw()

    def on_mouse_click(self, x, y, button, modifiers):
        if self.hit_test(x, y):
            self.dispatch_event('on_click')
开发者ID:tfaris,项目名称:Minecraft,代码行数:47,代码来源:gui.py

示例10: drawLabel

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
def drawLabel(text, pos=(0,0), **kwargs):
    kwargs.setdefault('font_size', 16)
    kwargs.setdefault('center', False)
    if kwargs.get('center'):
        kwargs.setdefault('anchor_x', 'center')
        kwargs.setdefault('anchor_y', 'center')
    else:
        kwargs.setdefault('anchor_x', 'left')
        kwargs.setdefault('anchor_y', 'bottom')
    del kwargs['center']
    temp_label = Label(text, **kwargs)
    #temp_label.x, temp_label.y = pos
    glPushMatrix()
    #glTranslated(-pos[0]-8.5,-pos[1]-8,0)
    glScaled(0.02,0.02,0.02)
    temp_label.draw()
    glPopMatrix()
    return temp_label.content_width
开发者ID:gpsajeev,项目名称:pychord,代码行数:20,代码来源:chordViz.py

示例11: LoadScreen

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class LoadScreen(MenuClass):
    """docstring for LoadScreen"""
    def __init__(self, *args, **kwargs):
        super(LoadScreen, self).__init__(*args, **kwargs)
        self.label = Label('connecting to server', font_name=font,
                           font_size=36, bold=False, x=200, y=550,
                           anchor_x='left', anchor_y='baseline')

    def draw(self):
        self.label.draw()

    def on_connect(self):
        self.send_message('menu_transition_-')

    def add_update(self, dt):
        try:
            if self.keys[key.ESCAPE] and not self.keys_old[key.ESCAPE]:
                self.send_message('to_main')
        except:
            pass
开发者ID:ashisdhara,项目名称:python_game,代码行数:22,代码来源:screens.py

示例12: FridgeLetterAtomic

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class FridgeLetterAtomic(MTDragable):
    def __init__(self, **kwargs):
        kwargs.setdefault("letter", "A")
        kwargs.setdefault("color", (1, 0, 0, 1))
        super(FridgeLetterAtomic, self).__init__(**kwargs)

        self.letter = Label(
            font_name="AlphaFridgeMagnets.ttf",
            font_size=48,
            bold=True,
            anchor_x="left",
            anchor_y="bottom",
            multiline=False,
            halign="top",
            color=map(lambda x: int(x * 255), kwargs.get("color")),
            text=kwargs.get("letter"),
        )
        self.size = self.letter.content_width, self.letter.content_height

    def draw(self):
        self.letter.x, self.letter.y = self.pos
        self.letter.draw()
开发者ID:azoon,项目名称:pymt,代码行数:24,代码来源:fridgeletter.py

示例13: UIBaseChooseGirl

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class UIBaseChooseGirl(Panel, InputHandler):
    hover_pic = None

    def __init__(self, trans, *a, **k):
        self.trans = trans
        self.pbar = None
        self.selecting = False

        g = Game.getgame()
        choices = trans.mapping[g.me]
        n_choices = len(choices)

        cols = 5 if n_choices > 16 else 4
        rows = max((n_choices - 1) / cols + 1, 4)

        w, h = 20 + cols*160, 51 + rows*113 + 30
        Panel.__init__(self, width=w, height=h, zindex=5, *a, **k)
        p = self.parent
        pw, ph = p.width, p.height
        self.x, self.y = (pw - w)/2, (ph - h)/2
        self.inputlet = None
        choices = self.choices = [c for c in choices if c.char_cls and not getattr(c, 'chosen', False)]
        self.selectors = selectors = []
        for i, c in enumerate(choices):
            y, x = divmod(i, cols)
            x, y = 15 + 160*x, 45 + 113*(rows - 1 - y)
            gs = GirlSelector(c, selectors, parent=self, hover_pic=self.hover_pic, x=x, y=y)

            @gs.event
            def on_dblclick(gs=gs):
                c = gs.choice
                ilet = self.inputlet
                if not c.chosen and ilet:
                    ilet.set_choice(c)
                    ilet.done()
                    self.end_selection()

            selectors.append(gs)

        self.label = Label(
            text='等待其他玩家操作', x=w//2, y=51+rows*113, font_size=12,
            color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230),
            anchor_x='center', anchor_y='bottom'
        )

    def draw(self):
        Panel.draw(self)
        self.label.draw()

    def on_girl_chosen(self, arg):
        actor, choice = arg
        for c in self.selectors:
            if c.choice is choice:
                c.disable()
                break

        self.parent.update_portraits()

    def begin_selection(self):
        self.selecting = True
        self.pbar and self.pbar.delete()
        self.pbar = BigProgressBar(
            parent=self, x=(self.width-250)//2, y=9, width=250,
        )

        def on_done(*a):
            # self.inputlet.done()
            # FIXME: blindly did this.
            self.inputlet and self.inputlet.done()
            self.end_selection()

        self.pbar.value = LinearInterp(
            1.0, 0.0, self.inputlet.timeout,
            on_done=on_done,
        )

    def end_selection(self):
        self.inputlet = None
        self.selecting = False
        self.pbar.delete()
开发者ID:feisuzhu,项目名称:thbattle,代码行数:82,代码来源:inputs.py

示例14: __init__

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class UI:

    def __init__(self, window):
        self.window = window
        self.buttons = []
        self.bars = []
        self.progressbars = []
        self.combat_text = []
        self.auto_target_rings = []
        self.target_rings = []
        self.target_label = None
        self.stats = None
        self.settings = dict(
            draw_mob_hp=True,
            allways_draw_mob_hp=False,
            redraw_time=0.5
        )
        self.redraw_timer = self.settings["redraw_time"]
        self.bg_batch = self.window.batches["gui1"]
        self.fg_batch = self.window.batches["gui2"]
        self.bar_fg_batch = self.window.batches["gui3"]
        self.behind_batch = self.window.batches["gui0"]

    def add_button(
        self, x, y, text="Default",
        cb=None, cb_arg=None
    ):
        button = Button(
            self.window, x=x, y=y, text=text, callback=cb, callback_arg=cb_arg,
            bg_batch=self.bg_batch, fg_batch=self.fg_batch
        )
        self.buttons.append(button)

    def add_bar(
        self, x, y,
        text="Default", width=200, height=30, color="blue", shows="default"
    ):
        bar = Bar(
            self.window,
            x=x, y=y,
            text=text, w=width, h=height, c=color, s=shows,
            bg_batch=self.bg_batch, fg_batch=self.bar_fg_batch
        )
        self.bars.append(bar)

    def add_progressbar(
        self, x, y, duration, w=64, h=10, title=None,
        c="blue", bgc="dblue", tc="black"
    ):
        b = ProgressBar(
            self.window, x=x, y=y, w=w, h=h, c=c, bgc=bgc, tc=tc,
            duration=duration,
            fg_batch=self.fg_batch, title=title
        )
        self.progressbars.append(b)

    def add_stats(self, owner, x, y, width, height):
        self.stats = Stats(
            self.window, owner, x=x, y=y, w=width, h=height,
            bg_batch=self.bg_batch, fg_batch=self.fg_batch,
        )

    def add_combat_text(self, text, x, y, **kwargs):
        ct = FloatingCombatText(
            self, text, x, y, batch=self.fg_batch, **kwargs
        )
        self.combat_text.append(ct)

    def update_bar(self, bartype, value, maxvalue):
        for b in self.bars:
            if b.type == bartype:
                b.update(value, maxvalue)

    def update_stats(self):
        if self.stats and self.window.debug:
            self.stats.update()

    def check(self, x, y, press=True, dry=False):
        if dry:
            for b in self.bars:
                if b.check(x, y):
                    return True
            for b in self.buttons:
                if b.check(x, y):
                    return True
            if self.stats:
                if self.stats.check(x, y):
                    return True
        else:
            for b in self.bars:
                if b.check(x, y):
                    return True
            for b in self.buttons:
                if press:
                    if b.check(x, y):
                        b.press()
                        return True
                else:
                    if b.pressed:
                        if b.check(x, y):
#.........这里部分代码省略.........
开发者ID:NiclasEriksen,项目名称:rpg_procgen,代码行数:103,代码来源:ui.py

示例15: Area

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import draw [as 别名]
class Area(object):

    def __init__(self, world, name, bounds):
        self.world = world
        self.name = name
        self.lpos = None
        self.oldlpos = None
        self.label = Label(name, font_name=FONTNAME, font_size=AREA_LABEL_HEIGHT,
                           italic=True, color=(76,76,128,255), x=0, y=0)
        self.center = Vec2d((bounds[0] + bounds[2])/2, (bounds[1] + bounds[3])/2)
        self.cbounds = (bounds[0] + self.label.content_width, 
                        bounds[1] + AREA_LABEL_HEIGHT,
                        bounds[2] - self.label.content_width, 
                        bounds[3] - AREA_LABEL_HEIGHT)
        self.candidates = None
        self.neighbors = None
        # Cache
        self.alcf = None
        self.alrf = None
        self.ap = None
        

    def dist_to_center(self, x):
        centroid = Vec2d(x[0] + (self.label.content_width / 2), 
                         x[1] + (AREA_LABEL_HEIGHT / 2))
        return centroid.get_distance(self.center)

    def move_label(self):
        # backup
        self.oldlpos = self.lpos
        # generate new random positions
        self.candidates = []
        for t in range(CANDIDATEBOUND):
            self.candidates.append((r.randint(self.cbounds[0], self.cbounds[2]),  
                                    r.randint(self.cbounds[1], self.cbounds[3])))
        # sort candidates by distance to center, increasing
        valued_candidates = map((lambda x: (self.dist_to_center(x), x)), self.candidates)
        valued_candidates.sort()
        # choose the best candidate
        self.lpos = valued_candidates[0][1]

    def undo_move_label(self):
        self.lpos = self.oldlpos
        # dirty cache
        self.alcf = None
        self.alrf = None
        self.ap = None

    def get_char_point(self): return self.lpos + Vec2d(0, AREA_LABEL_HEIGHT/2)
    def get_char_vec(self): return Vec2d(self.label.content_width, 0)

    def get_bounding_points(self):
        up = Vec2d(0, AREA_LABEL_HEIGHT)
        rt = Vec2d(self.label.content_width, 0)
        qa = self.lpos
        return qa, qa + rt, qa + up, qa + rt + up

    def get_bounding_corners(self):
        qa, qb, qc, qd = self.get_bounding_points()
        return qa, qd

    def get_bounding_points_padded(self):
        qa, qb, qc, qd = self.get_bounding_points()
        padding = 3
        upright = Vec2d(padding,padding)
        upleft = Vec2d(-padding,padding)
        return qa-upright, qb-upleft, qc+upleft, qd+upright

    def get_bounding_corners_padded(self):
        qa, qb, qc, qd = self.get_bounding_points_padded()
        return qa, qd

    def generate_neighbors(self):        
        self.chood = self.world.og.get_full_chood(self.lpos)
        self.rhood = self.world.og.get_full_rhood(self.lpos)

    def bootstrap(self):
        self.move_label()
        self.generate_neighbors()

    def draw(self):
        glLoadIdentity()
        glTranslatef(self.lpos[0], self.lpos[1], 0.0) 
        self.label.draw()

    ### AREA METRICS

    def get_AreaLabelCityFeature(self):
        if (self.alcf == None or self.world.current_object == self):        
            self.alcf = self.metric_AreaLabelCityFeature()
        return self.alcf
    def metric_AreaLabelCityFeature(self):
        # number of overlaps between area label and point-feature symbols
        # IDEA: use glyphs instead of bounding box
        count = 0
        pa, pb = self.get_bounding_corners()
        for c in self.chood:
            if (point_within(pa, pb, c.pos)):
                count = count + 1
        return count           
#.........这里部分代码省略.........
开发者ID:ajhalme,项目名称:maplabel,代码行数:103,代码来源:Maplabel.py


注:本文中的pyglet.text.Label.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。