|
|
@@ -3,16 +3,18 @@ import logging
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
-
|
|
|
class TouchTextManager():
|
|
|
- def __init__(self, size, base_size):
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def __init__(self,size,base_size):
|
|
|
self.size = size
|
|
|
self.base_size = base_size
|
|
|
self.touch_objects = {}
|
|
|
self.text_objects = {}
|
|
|
|
|
|
def add_object(self, key, text, pos, pos2, color):
|
|
|
- self.text_objects[key] = TextItem(text, pos, pos2, color, self.base_size)
|
|
|
+ self.text_objects[key] = TextItem(text, pos,pos2,color,self.base_size)
|
|
|
|
|
|
def get_object(self, key):
|
|
|
return self.text_objects[key]
|
|
|
@@ -20,11 +22,11 @@ class TouchTextManager():
|
|
|
def add_touch_object(self, key, text, pos, color):
|
|
|
self.touch_objects['key'] = TouchAndTextItem(text, pos, color, self.base_size)
|
|
|
|
|
|
- def get_touch_object(self, key):
|
|
|
+ def get_touch_object(self,key):
|
|
|
return self.touch_objects['key']
|
|
|
|
|
|
def add_progressbar(self, key, pos, pos2, max):
|
|
|
- self.touch_objects['key'] = Progressbar(pos, pos2, max)
|
|
|
+ self.touch_objects['key'] = Progressbar(pos,pos2,max)
|
|
|
|
|
|
def render(self, surface):
|
|
|
for key in self.text_objects:
|
|
|
@@ -35,19 +37,21 @@ class TouchTextManager():
|
|
|
|
|
|
|
|
|
class BaseItem():
|
|
|
- def __init__(self, pos, pos2):
|
|
|
+
|
|
|
+ def __init__(self,pos,pos2):
|
|
|
self.pos = pos
|
|
|
self.pos2 = pos2
|
|
|
- self.size = [0, 0]
|
|
|
+ self.size=[0,0]
|
|
|
self.size[0] = self.pos2[0] - self.pos[0]
|
|
|
self.size[1] = self.pos2[1] - self.pos[1]
|
|
|
- self.rect = pygame.Rect(0, 0, self.size[0], self.size[1])
|
|
|
+ self.rect = pygame.Rect(0,0,self.size[0],self.size[1])
|
|
|
|
|
|
|
|
|
class TextItem(BaseItem):
|
|
|
- def __init__(self, text, pos, pos2, color, text_size):
|
|
|
+
|
|
|
+ def __init__(self, text, pos,pos2, color,text_size):
|
|
|
if pos2 is not None:
|
|
|
- BaseItem.__init__(self, pos, pos2)
|
|
|
+ BaseItem.__init__(self,pos,pos2)
|
|
|
self.text_size = text_size
|
|
|
self.font = pygame.font.SysFont("arial", text_size)
|
|
|
self.text = text
|
|
|
@@ -66,7 +70,7 @@ class TextItem(BaseItem):
|
|
|
else:
|
|
|
self.fit_vertical = True
|
|
|
else:
|
|
|
- BaseItem.__init__(self, pos, (pos[0] + self.box.get_rect().width, pos[1] + self.box.get_rect().height))
|
|
|
+ BaseItem.__init__(self,pos,(pos[0]+self.box.get_rect().width,pos[1]+self.box.get_rect().height))
|
|
|
self.fit_horizontal = True
|
|
|
self.fit_vertical = True
|
|
|
|
|
|
@@ -89,49 +93,50 @@ class TextItem(BaseItem):
|
|
|
else:
|
|
|
self.step = self.step + 1
|
|
|
|
|
|
- def render(self, surface):
|
|
|
+ def render(self,surface):
|
|
|
if self.fit_horizontal:
|
|
|
self.box
|
|
|
else:
|
|
|
self.box = self.font.render(self.text, True, self.color)
|
|
|
- surface.blit(self.box, self.pos, area=self.rect)
|
|
|
+ surface.blit(self.box,self.pos,area=self.rect)
|
|
|
|
|
|
def set_text(self, text):
|
|
|
- self.__init__(text, self.pos, self.pos2, self.color, self.text_size)
|
|
|
-
|
|
|
+ self.__init__(text,self.pos,self.pos2,self.color,self.text_size)
|
|
|
|
|
|
class TouchObject(BaseItem):
|
|
|
- def __init__(self, pos, pos2):
|
|
|
- BaseItem.__init__(self, pos, pos2)
|
|
|
+
|
|
|
+ def __init__(self,pos,pos2):
|
|
|
+ BaseItem.__init__(self,pos,pos2)
|
|
|
self.active = False
|
|
|
self.background_box = pygame.Surface(self.size)
|
|
|
- self.background_box.fill((0, 128, 255))
|
|
|
+ self.background_box.fill((0,128,255))
|
|
|
|
|
|
- def render(self, surface):
|
|
|
+ def render(self,surface):
|
|
|
surface.blit(self.background_box, self.pos)
|
|
|
|
|
|
|
|
|
class TouchAndTextItem(TouchObject, TextItem):
|
|
|
- def __init__(self, text, pos, color, text_size):
|
|
|
- TextItem.__init__(self, text, pos, None, color, text_size)
|
|
|
- TouchObject.__init__(self, pos, self.pos2)
|
|
|
+
|
|
|
+ def __init__(self, text, pos, color,text_size):
|
|
|
+ TextItem.__init__(self,text, pos,None, color,text_size)
|
|
|
+ TouchObject.__init__(self,pos,self.pos2)
|
|
|
|
|
|
def update(self):
|
|
|
TextItem.update()
|
|
|
|
|
|
- def render(self, surface):
|
|
|
- TouchObject.render(self, surface)
|
|
|
- TextItem.render(self, surface)
|
|
|
-
|
|
|
+ def render(self,surface):
|
|
|
+ TouchObject.render(self,surface)
|
|
|
+ TextItem.render(self,surface)
|
|
|
|
|
|
class Progressbar(BaseItem):
|
|
|
+
|
|
|
def __init__(self, pos, pos2, max):
|
|
|
BaseItem.__init__(self, pos, pos2)
|
|
|
logger.error(pos2)
|
|
|
self.value = 0
|
|
|
self.max = max
|
|
|
- self.back_color = (0, 0, 0)
|
|
|
- self.main_color = (255, 255, 255)
|
|
|
+ self.back_color = (0,0,0)
|
|
|
+ self.main_color = (255,255,255)
|
|
|
self.surface = pygame.Surface(self.size)
|
|
|
self.surface.fill(self.back_color)
|
|
|
|
|
|
@@ -145,6 +150,6 @@ class Progressbar(BaseItem):
|
|
|
self.value = value
|
|
|
self.surface.fill(self.back_color)
|
|
|
pos_pixel = value * self.size[0] / self.max
|
|
|
- rect = pygame.Rect(0, 0, pos_pixel, self.size[1])
|
|
|
+ rect = pygame.Rect(0,0,pos_pixel,self.size[1])
|
|
|
self.surface.fill(self.main_color, rect)
|
|
|
|