Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pilas/interfaz/selector.py
blob: 3d15663a3a9e84f0e4898b90a7a6c04ee01aa761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- encoding: utf-8 -*-
# pilas engine - a video game framework.
#
# copyright 2010 - hugo ruscitti
# license: lgplv3 (see http://www.gnu.org/licenses/lgpl.html)
#
# website - http://www.pilas-engine.com.ar
#
# Deslizador creado por Pablo Garrido

import pilas

class Selector(pilas.actores.Actor):
    
    def __init__(self, texto, x=0, y=0, ancho=200):
        pilas.actores.Actor.__init__(self, x=x, y=y)
        
        self.texto = texto
        self._cargar_lienzo(ancho)
        self._cargar_imagenes()
        self.funcion_de_respuesta = None

        self.deseleccionar()
        pilas.eventos.click_de_mouse.conectar(self.detection_click_mouse)

    def _cargar_imagenes(self):
        self.imagen_selector = pilas.imagenes.cargar("interfaz/selector.png")
        self.imagen_selector_seleccionado = pilas.imagenes.cargar("interfaz/selector_seleccionado.png")

    def _cargar_lienzo(self, ancho):
        self.imagen = pilas.imagenes.cargar_superficie(ancho, 29)
        
    def pintar_texto(self):
        self.imagen.texto(self.texto, 35, 20)
        
    def deseleccionar(self):
        self.seleccionado = False
        self.imagen.limpiar()
        self.imagen.pintar_imagen(self.imagen_selector)
        self.pintar_texto()
        self.centro = ("centro", "centro")
        
    def seleccionar(self):
        self.seleccionado = True
        self.imagen.limpiar()
        self.imagen.pintar_imagen(self.imagen_selector_seleccionado)
        self.pintar_texto()
        self.centro = ("centro", "centro")
                
    def detection_click_mouse(self, click):
        if self.colisiona_con_un_punto(click.x, click.y):
            self.alternar_seleccion()
                
    def alternar_seleccion(self):
        if self.seleccionado:
            self.deseleccionar()
        else:
            self.seleccionar()

        if self.funcion_de_respuesta:
            self.funcion_de_respuesta(self.seleccionado)

    def definir_accion(self, funcion):
        self.funcion_de_respuesta = funcion