def test_MagnifierImageFilter_Make(): assert isinstance( skia.MagnifierImageFilter.Make(skia.Rect(100, 100), 1.), skia.ImageFilter)
def test_Matrix_MakeRectToRect(): assert isinstance( skia.Matrix.MakeRectToRect(skia.Rect(100, 100), skia.Rect(100, 100), skia.Matrix.kCenter_ScaleToFit), skia.Matrix)
@pytest.mark.parametrize('args', [ (1, 1, 1, 0, 0, 0), (skia.Point(1, 1), skia.Point(1, 0), skia.Point(0, 0)), ]) def test_Path_cubicTo(path, args): assert isinstance(path.cubicTo(*args), skia.Path) def test_Path_rCubicTo(path): assert isinstance(path.rCubicTo(1, 1, 1, 0, 0, 0), skia.Path) @pytest.mark.parametrize('args', [ (skia.Rect(100, 100), 0, 60, True), (50, 0, 0, 50, 50), (skia.Point(50, 0), skia.Point(0, 50), 50), (50, 50, 0, skia.Path.kSmall_ArcSize, skia.PathDirection.kCW, 0, 50), (skia.Point(50, 50), 0, skia.Path.kSmall_ArcSize, skia.PathDirection.kCW, skia.Point(0, 50)), ]) def test_Path_arcTo(path, args): assert isinstance(path.arcTo(*args), skia.Path) def test_Path_rArcTo(path): assert isinstance( path.rArcTo(50, 50, 0, skia.Path.kSmall_ArcSize, skia.PathDirection.kCW, 0, 50), skia.Path)
def test_Matrix_setRectToRect(matrix): assert isinstance( matrix.setRectToRect(skia.Rect(100, 100), skia.Rect(100, 100), skia.Matrix.kCenter_ScaleToFit), bool)
def test_Matrix_mapRectToQuad(matrix): assert isinstance(matrix.mapRectToQuad(skia.Rect(10, 10)), list)
def test_RRect_setOval(rrect): rrect.setOval(skia.Rect(128, 128)) assert rrect.isOval()
def test_RRect_setNinePatch(rrect): rrect.setNinePatch(skia.Rect(128, 128), 1, 2, 3, 1) assert rrect.isNinePatch()
def draw_note(self, velocity, start, end, channel, note, name): color_channels = { 0: { "plain": ImageColor.getcolor("#ffcc00", "RGB"), "sharp": ImageColor.getcolor("#ff9d00", "RGB"), }, 1: { "plain": ImageColor.getcolor("#00ff0d", "RGB"), "sharp": ImageColor.getcolor("#00a608", "RGB"), }, 2: { "plain": ImageColor.getcolor("#6600ff", "RGB"), "sharp": ImageColor.getcolor("#39008f", "RGB"), }, 3: { "plain": ImageColor.getcolor("#ff0000", "RGB"), "sharp": ImageColor.getcolor("#990000", "RGB"), }, 4: { "plain": ImageColor.getcolor("#00fffb", "RGB"), "sharp": ImageColor.getcolor("#00b5b2", "RGB"), }, 5: { "plain": ImageColor.getcolor("#ff006f", "RGB"), "sharp": ImageColor.getcolor("#a10046", "RGB"), }, 6: { "plain": ImageColor.getcolor("#aaff00", "RGB"), "sharp": ImageColor.getcolor("#75b000", "RGB"), }, 7: { "plain": ImageColor.getcolor("#e1ff00", "RGB"), "sharp": ImageColor.getcolor("#a9bf00", "RGB"), }, 8: { "plain": ImageColor.getcolor("#ff3300", "RGB"), "sharp": ImageColor.getcolor("#a82200", "RGB"), }, 9: { "plain": ImageColor.getcolor("#00ff91", "RGB"), "sharp": ImageColor.getcolor("#00b567", "RGB"), }, 10: { "plain": ImageColor.getcolor("#ff00aa", "RGB"), "sharp": ImageColor.getcolor("#c40083", "RGB"), }, 11: { "plain": ImageColor.getcolor("#c800ff", "RGB"), "sharp": ImageColor.getcolor("#8e00b5", "RGB"), }, 12: { "plain": ImageColor.getcolor("#00ff4c", "RGB"), "sharp": ImageColor.getcolor("#00c93c", "RGB"), }, 13: { "plain": ImageColor.getcolor("#ff8a8a", "RGB"), "sharp": ImageColor.getcolor("#bf6767", "RGB"), }, 14: { "plain": ImageColor.getcolor("#ffde7d", "RGB"), "sharp": ImageColor.getcolor("#c4aa5e", "RGB"), }, 15: { "plain": ImageColor.getcolor("#85ebff", "RGB"), "sharp": ImageColor.getcolor("#5ca7b5", "RGB"), }, 16: { "plain": ImageColor.getcolor("#ff7aa4", "RGB"), "sharp": ImageColor.getcolor("#bd5978", "RGB"), }, "default": { "plain": ImageColor.getcolor("#dddddd", "RGB"), "sharp": ImageColor.getcolor("#ffffff", "RGB"), }, } note_colors = color_channels.get(channel, color_channels["default"]) if "#" in name: width = self.semitone_width * 0.9 c = note_colors["sharp"] color = skia.Color4f(c[0] / 255, c[1] / 255, c[2] / 255, 1) else: width = self.tone_width * 0.6 c = note_colors["plain"] color = skia.Color4f(c[0] / 255, c[1] / 255, c[2] / 255, 1) # Make the skia Paint and paint = skia.Paint( AntiAlias=True, Color=color, Style=skia.Paint.kFill_Style, # Shader=skia.GradientShader.MakeLinear( # points=[(0.0, 0.0), (self.vectorial.context.width, self.vectorial.context.height)], # colors=[skia.Color4f(0, 0, 1, 1), skia.Color4f(0, 1, 0, 1)]), StrokeWidth=2, ) # c = ImageColor.getcolor("#d1ce1d", "RGB") c = (0, 0, 0) border = skia.Paint( AntiAlias=True, Color=skia.Color4f(c[0] / 255, c[1] / 255, c[2] / 255, 1), Style=skia.Paint.kStroke_Style, # ImageFilter=skia.ImageFilters.DropShadow(3, 3, 5, 5, skia.ColorBLUE), # MaskFilter=skia.MaskFilter.MakeBlur(skia.kNormal_BlurStyle, 2.0), StrokeWidth=max( self.vectorial.context.resolution_ratio_multiplier * 2, 1), ) x = self.keys_centers[note] y = self.functions.proportion( self.seconds_of_midi_content, self.viewport_height, #*2, self.vectorial.context.current_time - start) height = self.functions.proportion(self.seconds_of_midi_content, self.viewport_height, end - start) coords = [ x - (width / 2), y + (self.viewport_height) - height, x + (width / 2), y + (self.viewport_height), ] # Rectangle border rect = skia.Rect(*coords) # Draw the border self.skia.canvas.drawRect(rect, paint) self.skia.canvas.drawRect(rect, border)
def test_IRect_inset(irect): irect.inset(0, 0) def test_IRect_outset(irect): irect.outset(0, 0) def test_IRect_adjust(irect): irect.adjust(0, 0, 0, 0) @pytest.mark.parametrize('args', [ (20, 10), (skia.IRect(10, 10, 20, 20), ), (skia.Rect(10, 10, 20, 20), ), ]) def test_IRect_contains(irect, args): assert irect.contains(*args) @pytest.mark.parametrize('operand', [ skia.IRect(10, 10, 20, 20), skia.Rect(10, 10, 20, 20), ]) def test_IRect__contains(irect, operand): assert operand in irect def test_IRect__not_contains(irect): assert (60, 60) in skia.IRect(50, 50, 100, 100)
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.color_channels.get(channel, self.color_channels["default"]) # Is a sharp key if "#" in name: width = self.semitone_width * 0.9 color = skia.Color4f(*note_colors["sharp"], 1) # Plain key else: width = self.tone_width * 0.6 color = skia.Color4f(*note_colors["plain"], 1) # Make the skia Paint note_paint = skia.Paint( AntiAlias=True, Color=color, 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=[skia.Color4f(0, 0, 1, 1), skia.Color4f(0, 1, 0, 1)]), StrokeWidth=2, ) # Border of the note note_border_paint = skia.Paint( AntiAlias=True, Color=skia.Color4f(*note_colors["border"], 1), Style=skia.Paint.kStroke_Style, # ImageFilter=skia.ImageFilters.DropShadow(3, 3, 5, 5, skia.ColorBLUE), # MaskFilter=skia.MaskFilter.MakeBlur(skia.kNormal_BlurStyle, 2.0), StrokeWidth=max( self.mmvskia_main.context.resolution_ratio_multiplier * 2, 1), ) # 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) # 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, x + (width / 2), y + (self.viewport_height), ] # Rectangle border of the note rect = skia.Rect(*coords) # Draw the note and border self.mmvskia_main.skia.canvas.drawRect(rect, note_paint) self.mmvskia_main.skia.canvas.drawRect(rect, note_border_paint)
def test_PathEffect_computeFastBounds(patheffect): patheffect.computeFastBounds(skia.Rect(100, 100), skia.Rect(100, 100))
def picture(): recorder = skia.PictureRecorder() canvas = recorder.beginRecording(skia.Rect(100, 100)) canvas.clear(0xFFFFFFFF) canvas.drawLine(0, 0, 100, 100, skia.Paint()) return recorder.finishRecordingAsPicture()
def test_ImageFilter_computeFastBounds(imagefilter): assert isinstance( imagefilter.computeFastBounds(skia.Rect(100, 100)), skia.Rect)
def test_TileImageFilter_Make(): assert isinstance( skia.TileImageFilter.Make(skia.Rect(10, 10), skia.Rect(100, 100)), skia.ImageFilter)
def test_Rect_eq(rect): assert rect == skia.Rect(0, 0, 240, 120)
def rect(): return skia.Rect(0, 0, 240, 120)
def test_RRect_setRect(rrect): rrect.setRect(skia.Rect(128, 128)) assert rrect.isRect()
def test_Rect_init(args): assert isinstance(skia.Rect(*args), skia.Rect)
def test_RRect_setRectXY(rrect): rrect.setRectXY(skia.Rect(128, 128), 1, 1) assert rrect.isSimple()
def test_Rect_intersects(rect): rect.intersects(skia.Rect(20, 20))
def test_RRect_contains(rrect): assert rrect.contains(skia.Rect(120, 60, 122, 62))
def test_Rect_join(rect): rect.join(skia.Rect(10, 10, 20, 20))
def test_Matrix_mapRect(matrix): assert isinstance(matrix.mapRect(skia.Rect(10, 10)), skia.Rect)
def test_Rect_joinNonEmptyArg(rect): rect.joinNonEmptyArg(skia.Rect(10, 10, 20, 20))
def test_Matrix_mapRectScaleTranslate(matrix): assert isinstance(matrix.mapRectScaleTranslate(skia.Rect(10, 10)), skia.Rect)
def test_Rect_joinPossiblyEmptyRect(rect): rect.joinPossiblyEmptyRect(skia.Rect())
def test_Paint_getStrokeJoin(paint): assert isinstance(paint.getStrokeJoin(), skia.Paint.Join) def test_Paint_setStrokeJoin(paint): paint.setStrokeJoin(skia.Paint.kMiter_Join) @pytest.mark.parametrize('args', [ ( skia.Path(), skia.Path(), ), (skia.Path(), skia.Path(), skia.Rect(100, 100), 1), ]) def test_Paint_getFillPath(paint, args): assert isinstance(paint.getFillPath(*args), bool) def test_Paint_getShader(paint): assert isinstance(paint.getShader(), (skia.Shader, type(None))) def test_Paint_refShader(paint): assert isinstance(paint.refShader(), (skia.Shader, type(None))) def test_Paint_setShader(paint): paint.setShader(skia.Shaders.Empty())
def test_Rect_Intersects(rect): assert skia.Rect.Intersects(rect, skia.Rect(10, 10, 20, 20))
def test_Path_isOval(path): assert isinstance(path.isOval(skia.Rect()), bool)
def test_ImageFilters_Tile(): assert isinstance( skia.ImageFilters.Tile(skia.Rect(10, 10), skia.Rect(100, 100)), skia.ImageFilter)