コード例 #1
0
ファイル: skia_backend.py プロジェクト: BenKnisley/PyMapKit
    def cache_color(self, input_color, opacity=1):
        ## Two tuple types, 0-1 or 0-256
        if isinstance(input_color, tuple):
            if isinstance(input_color[0], float):
                rtrn_color = *input_color, opacity
                return skia.Color(*rtrn_color)
                R = int(input_color[3] * 255.0)
                G = int(input_color[5] * 255.0)
                B = int(input_color[7] * 255.0)
                A = int(opacity * 255)
                return skia.Color(R, G, B, A)

            elif isinstance(input_color[0], int):
                R = int(input_color[3])
                G = int(input_color[5])
                B = int(input_color[7])
                A = int(opacity * 255)
                return skia.Color(R, G, B, A)

        ## Two types of color strings: Html color names and hex
        if isinstance(input_color, str):
            ##
            if input_color.lower() in BaseBackend.color_names:
                input_color = BaseBackend.color_names[input_color.lower()]

            if '#' in input_color and len(input_color) == 7:
                ## Hex string color
                R = int(int(input_color[1:3], 16))
                G = int(int(input_color[3:5], 16))
                B = int(int(input_color[5:7], 16))
                A = int(opacity * 255)
                return skia.Color(R, G, B, A)
コード例 #2
0
	def _from_whatever(x) -> int:
		if isinstance(x, str):
			return Color._from_hex(x) if x.startswith('#') else Color._from_name(x)
		elif isinstance(x, (tuple, list)):
			if len(x) == 4:
				return skia.Color(*x)
			else:
				return skia.Color(*x, 255)
		else:
			return x
コード例 #3
0
def make_colour(hex_string, opacity):
    if hex_string.startswith('#'):
        if len(hex_string) == 4:
            rgb = tuple(2 * c for c in hex_string[1:])
        else:
            rgb = tuple(hex_string[n:n + 2] for n in range(1, 6, 2))
        colour = tuple(int(c, 16) for c in rgb)
        return skia.Color(*colour, int(255 * opacity))
    else:
        return skia.Color(0, 0, 0, 128)
コード例 #4
0
	def _from_hex(color_hex: str) -> int:
		color_hex = color_hex.lstrip('#')
		if len(color_hex) in (3, 4):
			color_hex = ''.join(c+c for c in color_hex)
		assert len(color_hex) in (6, 8), f"The length of color_hex must be 3, 4, 6 or 8, not {len(color_hex)}."

		channels = [int(color_hex[i:i+2], 16) for i in range(0, len(color_hex), 2)]
		if len(channels) == 3:
			channels.append(255)
		return skia.Color(*channels)
コード例 #5
0
def make_colour(colour_string, opacity=1.0):
    if colour_string.startswith('#'):
        colour = webcolors.hex_to_rgb(colour_string)
    elif colour_string.startswith('rgb('):
        rgb = colour_string[4:-1].split(',')
        if '%' in colour_string:
            colour = webcolors.rgb_percent_to_rgb(rgb)
        else:
            colour = [int(c) for c in rgb]
    else:
        colour = webcolors.html5_parse_legacy_color(colour_string)
    return skia.Color(*tuple(colour), int(255*opacity))
コード例 #6
0
 def render_gui():
     try:
         with skia_surface(window) as surface:
             with surface as canvas:
                 canvas.clear(skia.Color(0, 0, 0))
                 scroll = db['gui_status'].get('scroll_x')['value'], db['gui_status'].get('scroll_y')['value']
                 canvas.translate(*scroll)
                 for widget in db['widget'].rows:
                     blob = skia.TextBlob.MakeFromString(widget['text'], font)
                     canvas.save()
                     canvas.drawRect(skia.Rect(widget['x'], widget['y'], widget['x']+widget['width'], widget['y']+widget['height']),
                                     skia.Paint(AntiAlias=True, Style=skia.Paint.kFill_Style, Color=skia.ColorBLUE))
                     canvas.clipRect(skia.Rect(widget['x'], widget['y'], widget['x']+widget['width'], widget['y']+widget['height']))
                     canvas.drawTextBlob(blob, widget['x'], widget['y']+widget['height'], skia.Paint(AntiAlias=True, Color=skia.Color(255, 255, 255)))
                     canvas.restore()
             surface.flushAndSubmit()
             glfw.swap_buffers(window)
     except Exception as e:
         traceback.print_exc()
コード例 #7
0
def test_Color(args):
    assert isinstance(skia.Color(*args), int)
コード例 #8
0
                            cells[cur_cell].output = traceback.format_exc()

            with surface as canvas:
                # ensure cursor is visible
                target_scroll[1] = clamp(cursor.line * -line_height,
                                         (cursor.line + 2) * -line_height +
                                         HEIGHT, target_scroll[1])

                M = canvas.getTotalMatrix()
                if abs(target_scroll[1] - M.getTranslateY()) > 2:
                    canvas.translate(
                        0, (target_scroll[1] - M.getTranslateY()) * 0.2)
                elif abs(target_scroll[1] - M.getTranslateY()) > 1:  # snap
                    canvas.translate(0, target_scroll[1] - M.getTranslateY())

                canvas.clear(skia.Color(255, 255, 255))
                line = 1
                for c in cells:
                    if cursor._buf == c.input:
                        # draw cursor
                        canvas.drawRect(
                            skia.Rect.MakeXYWH(
                                cursor.column * col_width,
                                line_height * (line - 1) +
                                cursor.line * line_height + 4, 2, line_height),
                            input_paint)

                    # display input
                    for l in c.input.as_str().split('\n'):
                        canvas.drawString(l, 0, line_height * line, font,
                                          input_paint)