Example #1
0
	def __init__(self, rect, caplocation, text, fg, bg, visible):
		LCARSObject.__init__(self, rect, fg, bg, visible)
		
		self.textString = text
		
		if len(text) > 0:
			if (self.rect.h > self.rect.w):
				#Portrait format
				texty = self.rect.bottom - self.rect.w
				textx = self.rect.right - (self.rect.w / 10)
				textw = self.PointSizeFromBarWidth()
			else:
				#Landscape
				texty = self.rect.centery
				textx = self.rect.right - (self.rect.h/2)
				textw = self.PointSizeFromBarHeight()
				
			self.text = LCARSText((textx, texty), text, textw, TextAlign.XALIGN_RIGHT, self.bg, self.fg, True) # Swap fg/bg text colours
		else:
			self.text = None
			
		self.caps = []
		if (caplocation & CapLocation.CAP_TOP):
			self.caps.append({'rect':pygame.Rect(0, 0, self.rect.w, self.rect.w), 'loc':CapLocation.CAP_TOP})
		if (caplocation & CapLocation.CAP_LEFT):
			self.caps.append({'rect':pygame.Rect(0, 0, self.rect.h, self.rect.h), 'loc':CapLocation.CAP_LEFT})
		if (caplocation & CapLocation.CAP_RIGHT):
			self.caps.append({'rect':pygame.Rect(self.rect.w - self.rect.h, 0, self.rect.h, self.rect.h), 'loc':CapLocation.CAP_RIGHT})
		if (caplocation & CapLocation.CAP_BOTTOM):
			self.caps.append({'rect':pygame.Rect(0, self.rect.h - self.rect.w, self.rect.w, self.rect.w), 'loc':CapLocation.CAP_BOTTOM})
Example #2
0
    def __init__(self, width, height):

        self.ENDCAP = -1  #pylint: disable=C0103
        self.TEXT = -2  #pylint: disable=C0103
        self.SWEEP = -3  #pylint: disable=C0103

        capped_bar_length = width / 16
        sweep_end_y = height - Widths.BORDER
        sweep_height = sweep_end_y - Widths.BORDER

        self.objects = {
            self.ENDCAP:
            LCARSCappedBar(
                pygame.Rect(width - Widths.BORDER - capped_bar_length,
                            Widths.BORDER, capped_bar_length,
                            Widths.LARGE_BAR), CapLocation.CAP_RIGHT, '',
                Colours.FG, Colours.BG, True)
        }

        ## The title text is to the immediate left of the endcap
        text_right = self.objects[self.ENDCAP].l() - Widths.BORDER
        self.objects[self.TEXT] = LCARSText(
            (text_right, Widths.BORDER + Widths.LARGE_BAR / 2),
            "SNACKSPACE v1.0", 80, TextAlign.XALIGN_RIGHT, Colours.FG,
            Colours.BG, True)

        ## The sweep starts at the immediate left of the text
        sweep_end_x = self.objects[self.TEXT].l() - Widths.BORDER
        sweep_width = sweep_end_x - Widths.BORDER

        self.objects[self.SWEEP] = LCARSSweep(
            pygame.Rect(Widths.BORDER, Widths.BORDER, sweep_width,
                        sweep_height), 'TL', Widths.SMALL_BAR,
            Widths.LARGE_BAR, Colours.FG, Colours.BG, True)
Example #3
0
 def set_intro_text(self, text, color):
     """ The intro text is positioned centrally between the sweep and image """
     text_y_position = (self.border.inner_y() +
                        self.objects['titleimage'].t()) / 2
     self.objects['introtext'] = LCARSText(
         (self.width / 2, text_y_position), text, 36,
         TextAlign.XALIGN_CENTRE, color, Colours.BG, True)
Example #4
0
 def set_intro_text_2(self, text, color):
     """ The intro text is positioned between the image and the base """
     text_y_position = (self.objects['titleimage'].b() +
                        self.border.bottom()) / 2
     text_y_position = text_y_position - 30
     self.objects['introtext2'] = LCARSText(
         (self.width / 2, text_y_position), text, 36,
         TextAlign.XALIGN_CENTRE, color, Colours.BG, True)
Example #5
0
 def set_intro_text_3(self, text, color):
     """ The intro text is positioned between the image and the base """
     text_y_position = self.objects['introtext2'].t() + 80
     self.objects['introtext3'] = LCARSText(
         (self.width / 2, text_y_position), text, 36,
         TextAlign.XALIGN_CENTRE, color, Colours.BG, True)
Example #6
0
	def setText(self, text):
		texty = self.rect.centery
		textx = self.rect.right - (self.rect.h/2)

		self.textString = text
		self.text = LCARSText((textx, texty), text, self.PointSizeFromBarHeight(), TextAlign.XALIGN_RIGHT, self.bg, self.fg, True) # Swap fg/bg text colours
Example #7
0
class LCARSCappedBar(LCARSObject):

	def __init__(self, rect, caplocation, text, fg, bg, visible):
		LCARSObject.__init__(self, rect, fg, bg, visible)
		
		self.textString = text
		
		if len(text) > 0:
			if (self.rect.h > self.rect.w):
				#Portrait format
				texty = self.rect.bottom - self.rect.w
				textx = self.rect.right - (self.rect.w / 10)
				textw = self.PointSizeFromBarWidth()
			else:
				#Landscape
				texty = self.rect.centery
				textx = self.rect.right - (self.rect.h/2)
				textw = self.PointSizeFromBarHeight()
				
			self.text = LCARSText((textx, texty), text, textw, TextAlign.XALIGN_RIGHT, self.bg, self.fg, True) # Swap fg/bg text colours
		else:
			self.text = None
			
		self.caps = []
		if (caplocation & CapLocation.CAP_TOP):
			self.caps.append({'rect':pygame.Rect(0, 0, self.rect.w, self.rect.w), 'loc':CapLocation.CAP_TOP})
		if (caplocation & CapLocation.CAP_LEFT):
			self.caps.append({'rect':pygame.Rect(0, 0, self.rect.h, self.rect.h), 'loc':CapLocation.CAP_LEFT})
		if (caplocation & CapLocation.CAP_RIGHT):
			self.caps.append({'rect':pygame.Rect(self.rect.w - self.rect.h, 0, self.rect.h, self.rect.h), 'loc':CapLocation.CAP_RIGHT})
		if (caplocation & CapLocation.CAP_BOTTOM):
			self.caps.append({'rect':pygame.Rect(0, self.rect.h - self.rect.w, self.rect.w, self.rect.w), 'loc':CapLocation.CAP_BOTTOM})
			
	def PointSizeFromBarHeight(self):
		pointSizeAt50px = 24
		return int((self.rect.h / 50) * pointSizeAt50px)

	def PointSizeFromBarWidth(self):
		pointSizeAt50px = 24
		return int((self.rect.w / 50) * pointSizeAt50px)

	def setText(self, text):
		texty = self.rect.centery
		textx = self.rect.right - (self.rect.h/2)

		self.textString = text
		self.text = LCARSText((textx, texty), text, self.PointSizeFromBarHeight(), TextAlign.XALIGN_RIGHT, self.bg, self.fg, True) # Swap fg/bg text colours

	def getText(self):
		return self.textString
	
	def setWidth(self, newWidth):
	
		self.rect.width = newWidth
		# Make sure that text is correctly located
		self.setText(self.textString)
		
	def draw(self, window):
		
		if (self.visible):
			# Draw on a separate surface before blitting
			surf = pygame.Surface(self.rect.size)
				
			#Define the rectangle inside the endcaps			
			irect = self.rect.copy()
			irect.left = 0
			irect.top = 0
			
			# Draw each endcap
			for capDict in self.caps:
				cap = capDict['rect']
				loc = capDict['loc']
				# Remove rectangle enclosing cap before drawing
				if loc == CapLocation.CAP_RIGHT:
					irect.w -= cap.w/2
				if loc == CapLocation.CAP_LEFT:
					irect.w -= cap.w/2
					irect.left += cap.w/2
				if loc == CapLocation.CAP_BOTTOM:
					irect.h -= cap.w/2
				if loc == CapLocation.CAP_TOP:
					irect.h -= cap.w/2
					irect.top += cap.w/2
				
				# pygame doesn't do filled arcs well, so draw full circle
				pygame.draw.ellipse(surf, self.fg, cap, 0)

			surf.fill(self.fg, irect)
			surf.set_colorkey(self.bg)
			
			window.blit(surf, self.rect)
			
			# Draw text (if any)
			if not (self.text is None):
				self.text.draw(window)