#
#		User-defined views used by test programs
#

from GUI import View, Color, Font
from GUI.StdFonts import system_font, application_font
from GUI.StdColors import black, red, green, blue, yellow, white

fancy_font = Font("Times", 48, ['italic'])

class TestDrawing(View):

    def draw(self, c, r):
        self.fill_rectangle(c, (0, 0, self.width, self.height), yellow)
        self.draw_triangle(c, 10, 40, red)
        c.gsave()
        c.rectclip((100, 0, 120, 50))
        self.draw_triangle(c, 100, 40, green)
        c.grestore()
        self.draw_triangle(c, 50, 100, blue)
        f1 = system_font
        f2 = application_font
        f3 = fancy_font
        self.draw_text(c, 150, 100, f1, "System Font")
        self.draw_text(c, 150, 120, f2, "Application Font")
        self.draw_text(c, 5, 180, f3, "Times Italic 48")

    def draw_text(self, c, x, y, f, s):
        w = f.width(s)
        #c.pensize = 1
        #c.newpath()
        #c.moveto(x - 5, y + 0.5)
        #c.rlineto(w + 10, 0)
        #c.stroke()
        c.fill_rect((x - 5, y, x + w + 5, y + 1))
        c.font = f
        c.moveto(x, y)
        c.show_text(s)

    def draw_triangle(self, c, x, y, hue):
        c.newpath()
        c.moveto(x, y)
        c.rlineto(40, 0)
        c.rlineto(-20, -30)
        c.closepath()
        c.forecolor = hue
        c.fill()
        c.pensize = 3
        c.forecolor = black
        c.stroke()

    def fill_rectangle(self, c, (l, t, r, b), hue):
        c.newpath()
        c.moveto(l, t)
        c.lineto(l, b)
        c.lineto(r, b)
        c.lineto(r, t)
        c.closepath()
        c.forecolor = hue
        c.fill()
    

