Ejemplo n.º 1
0
def test_RRect_methods(rrect):
    assert isinstance(rrect.getType(), skia.RRect.Type)
    assert isinstance(rrect.type(), skia.RRect.Type)
    assert not rrect.isEmpty()
    assert not rrect.isRect()
    assert rrect.isOval()
    assert not rrect.isSimple()
    assert not rrect.isNinePatch()
    assert not rrect.isComplex()
    assert rrect.width() == 128
    assert rrect.height() == 128
    assert isinstance(rrect.getSimpleRadii(), skia.Point)
    rrect.setEmpty()
    assert rrect.isEmpty()
    rrect.setRect(skia.Rect.MakeWH(128, 128))
    assert rrect.isRect()
    rrect.setOval(skia.Rect.MakeWH(128, 128))
    assert rrect.isOval()
    rrect.setRectXY(skia.Rect.MakeWH(128, 128), 1, 1)
    rrect.setNinePatch(skia.Rect.MakeWH(128, 128), 1, 2, 3, 1)
    assert rrect.isNinePatch()
    # rrect.setRectRadii()
    assert isinstance(rrect.rect(), skia.Rect)
    # assert isinstance(rrect.radii(skia.RRect.Corner), skia.Point)
    assert isinstance(rrect.getBounds(), skia.Rect)
    rrect2 = skia.RRect()
    rrect.inset(0, 0, rrect2)
    rrect.inset(0, 0)
    rrect.outset(0, 0, rrect2)
    rrect.outset(0, 0)
    rrect.offset(0, 0)
    assert isinstance(rrect.makeOffset(0, 0), skia.RRect)
    assert rrect.contains(skia.Rect(10, 10, 20, 20))
    assert rrect.isValid()
    # rrect.writeToMemory()
    # rrect.readFromMemory()
    # rrect.transform()
    rrect.dump(True)
    rrect.dump()
    rrect.dumpHex()
Ejemplo n.º 2
0
def test_Path_isRRect(path):
    assert isinstance(path.isRRect(skia.RRect()), bool)
    def draw(self, notes_playing):

        away_ratio = 0.33

        # If the note is black we leave a not filled spot on the bottom, this is the ratio of it
        away = (self.height * (away_ratio)) if self.is_black else 0

        # Based on the away, center, width, height etc, get the coords of this piano key
        coords = [
            self.center_x - (self.width / 2),
            self.resolution_height - self.height,
            self.center_x + (self.width / 2),
            self.resolution_height - away,
        ]

        white_or_back = "white" if self.is_white else "black"

        # Rectangle border
        key_rect = skia.RRect(skia.Rect(*coords),
            self.config["rounding"]["piano_keys"][white_or_back]["x"],
            self.config["rounding"]["piano_keys"][white_or_back]["y"]
        )

        # Is the note active
        self.active = self.note in notes_playing.keys()

        if self.config["piano_key_follows_note_color"]:
            if self.active:
                channel = notes_playing[self.note]
                color1 = self.colors[f"channel_{channel}"]["plain_1"]
                color2 = self.colors[f"channel_{channel}"]["plain_2"]
            else:
                color1 = self.color_idle_1
                color2 = self.color_idle_2

        else:
            # Get the color based on if the note is active or not
            color1 = self.color_active_1 if self.active else self.color_idle_1
            color2 = self.color_active_2 if self.active else self.color_idle_2
        
        # Make the skia Paint and
        key_paint = skia.Paint(
            AntiAlias = True,
            # Color = color1,
            Style = skia.Paint.kFill_Style,
            Shader = skia.GradientShader.MakeLinear(
                points = [(0.0, self.mmvskia_main.context.height), (self.mmvskia_main.context.width, self.mmvskia_main.context.height)],
                colors = [color1, color2]),
            StrokeWidth = 0,
        )

        # The border of the key
        key_border = skia.Paint(
            AntiAlias = True,
            Color = skia.Color4f(0, 0, 0, 1),
            Style = skia.Paint.kStroke_Style,
            StrokeWidth = 1,
        )

        # Make flat top
        if self.is_black:
            bleed = self.config["rounding"]["piano_keys"][white_or_back]["x"] / 8
            flat_top_key_rect = skia.Rect(coords[0], coords[1] - bleed, coords[2], (coords[3] - (coords[3] - coords[1]) / 4) - bleed)
            self.mmvskia_main.skia.canvas.drawRect(flat_top_key_rect, key_paint)

        # Draw the key (we'll draw on top of it later)
        self.mmvskia_main.skia.canvas.drawRRect(key_rect, key_paint)

        # Draw the 3d effect
        if (not self.active):

            # One fourth of the away ratio
            three_d_effect_away = away + (self.height * (away_ratio / 4))

            # The coordinates considering black key's away
            three_d_effect_coords = [
                self.center_x - (self.width / 2),
                self.resolution_height - three_d_effect_away,
                self.center_x + (self.width / 2),
                self.resolution_height - away,
            ]

            # The paint
            three_d_effect_paint = skia.Paint(
                AntiAlias = True,
                Color = self.color_3d_effect,
                Style = skia.Paint.kFill_Style,
                StrokeWidth = 0,
            )

            rect = skia.RRect(skia.Rect(*three_d_effect_coords), 8, 8)

            # Draw the rectangle
            self.mmvskia_main.skia.canvas.drawRRect(rect, three_d_effect_paint)

        # Draw the border
        if not self.is_black:
            self.mmvskia_main.skia.canvas.drawRRect(key_rect, key_border)
    def draw_note(self, velocity, start, end, channel, note, name):

        # Get the note colors for this channel, we receive a dict with "sharp" and "plain" keys
        note_colors = self.colors[f"channel_{channel}"]
        
        # Is a sharp key
        if "#" in name:
            width = self.semitone_width * 0.9
            color1 = note_colors["sharp_1"]
            color2 = note_colors.get("sharp_2", color1)

        # Plain key
        else:
            width = self.tone_width * 0.6
            color1 = note_colors["plain_1"]
            color2 = note_colors.get("plain_2", color1)

        # Make the skia Paint
        note_paint = skia.Paint(
            AntiAlias = True,
            Style = skia.Paint.kFill_Style,
            Shader = skia.GradientShader.MakeLinear(
                points = [(0.0, 0.0), (self.mmvskia_main.context.width, self.mmvskia_main.context.height)],
                colors = [color1, color2]
            ),
            StrokeWidth = 2,
        )

        # Border of the note
        note_border_paint = skia.Paint(
            AntiAlias = True,
            Style = skia.Paint.kStroke_Style,
            ImageFilter = skia.ImageFilters.DropShadowOnly(3, 3, 30, 30, note_colors["border_shadow"]),
            # MaskFilter=skia.MaskFilter.MakeBlur(skia.kNormal_BlurStyle, 2.0),
            # StrokeWidth = max(self.mmvskia_main.context.resolution_ratio_multiplier * 2, 1),
            StrokeWidth = 0,
        )
        
        # Horizontal we have it based on the tones and semitones we calculated previously
        # this is the CENTER of the note
        x = self.keys_centers[note]

        # The Y is a proportion of, if full seconds of midi content, it's the viewport height itself,
        # otherwise it's a proportion to the processing time according to a start value in seconds
        y = self.functions.proportion(
            self.config["seconds_of_midi_content"],
            self.viewport_height, #*2,
            self.mmvskia_main.context.current_time - start
        )

        # The height is just the proportion of, seconds of midi content is the maximum height
        # how much our key length (end - start) is according to that?
        height = self.functions.proportion(
            self.config["seconds_of_midi_content"],
            self.viewport_height,
            end - start
        ) 

        spacing = self.viewport_height / 512

        # Build the coordinates of the note
        # Note: We add and subtract half a width because X is the center
        # while we need to add from the viewport out heights on the Y
        coords = [
            x - (width / 2),
            y + (self.viewport_height) - height + spacing,
            x + (width / 2),
            y + (self.viewport_height) - spacing,
        ]

        # Rectangle border of the note
        # rect = skia.Rect(*coords)
        rect = skia.RRect(skia.Rect(*coords), 
            self.config["rounding"]["notes"]["x"],
            self.config["rounding"]["notes"]["y"]
        )
        
        # Draw the note and border
        self.mmvskia_main.skia.canvas.drawRRect(rect, note_paint)

        # Get paint, font
        if self.config["draw_note_name"]:
            paint = skia.Paint(AntiAlias = True, Color = skia.ColorBLACK, StrokeWidth = 43)

            height_size = self.font.getSpacing()
            text_size = self.font.measureText(name[:-1])

            self.mmvskia_main.skia.canvas.drawString(
                name[:-1],
                (x) - (text_size / 2),
                (y + (self.viewport_height) + spacing) - (height_size / 2),
                self.font, paint
            )
Ejemplo n.º 5
0
def test_Canvas_drawDRRect(canvas):
    canvas.drawDRRect(skia.RRect(), skia.RRect(), skia.Paint())
Ejemplo n.º 6
0
def test_RRect_ne(rrect):
    assert rrect != skia.RRect()
Ejemplo n.º 7
0
def test_RRect_transform(rrect):
    dst = skia.RRect()
    assert rrect.transform(skia.Matrix.I(), dst)
Ejemplo n.º 8
0
def test_RRect_outset(rrect):
    rrect.outset(0, 0, skia.RRect())
Ejemplo n.º 9
0
def test_RRect_inset(rrect):
    rrect.inset(0, 0, skia.RRect())
    rrect.inset(0, 0)
Ejemplo n.º 10
0
def test_RRect_init(args):
    assert isinstance(skia.RRect(*args), skia.RRect)
Ejemplo n.º 11
0
def test_Rect_eq(rect):
    assert rect == skia.Rect(0, 0, 240, 120)


def test_Rect_ne(rect):
    assert rect != skia.Rect.MakeEmpty()


@pytest.fixture
def rrect(rect):
    return skia.RRect.MakeOval(rect)


@pytest.mark.parametrize('args', [
    tuple(),
    (skia.RRect(), ),
    (skia.Rect(10, 10), 1, 1),
])
def test_RRect_init(args):
    assert isinstance(skia.RRect(*args), skia.RRect)


def test_RRect_getType(rrect):
    assert isinstance(rrect.getType(), skia.RRect.Type)


def test_RRect_type(rrect):
    assert isinstance(rrect.type(), skia.RRect.Type)


def test_RRect_isEmpty(rrect):
Ejemplo n.º 12
0
def test_Path_RRect():
    assert isinstance(skia.Path.RRect(skia.RRect(skia.Rect(10, 10), 1, 1)),
                      skia.Path)
Ejemplo n.º 13
0
    (skia.Rect(100, 100), ),
])
def test_PathBuilder_addRect(path_builder, args):
    assert isinstance(path_builder.addRect(*args), skia.PathBuilder)


@pytest.mark.parametrize('args', [
    (skia.Rect(100, 100), skia.PathDirection.kCW, 0),
    (skia.Rect(100, 100), ),
])
def test_PathBuilder_addOval(path_builder, args):
    assert isinstance(path_builder.addOval(*args), skia.PathBuilder)


@pytest.mark.parametrize('args', [
    (skia.RRect(skia.Rect(100, 100), 2, 2), skia.PathDirection.kCW, 0),
    (skia.RRect(skia.Rect(100, 100), 2, 2), ),
])
def test_PathBuilder_addRRect(path_builder, args):
    assert isinstance(path_builder.addRRect(*args), skia.PathBuilder)


def test_PathBuilder_addCircle(path_builder):
    assert isinstance(path_builder.addCircle(5, 5, 5), skia.PathBuilder)


def test_PathBuilder_addPolygon(path_builder):
    assert isinstance(path_builder.addPolygon([(0, 0), (1, 1), (2, 2)], False),
                      skia.PathBuilder)