#
#		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
from TestInput import TestInput

class TestView(TestInput, View):

    def draw(self, c):
        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()
        #c.initclip()
        self.draw_triangle(c, 50, 100, blue)
        f1 = system_font
        f2 = application_font
        f3 = Font("Times", 48, ['italic'])
        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):
        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()
    

class BigTestView(TestInput, View):

    def __init__(self, **kwds):
        View.__init__(self, **kwds)
        self.extent = (0, 0, 1000, 1000)
    
    def mac_dump_viewport(self):
        from Carbon.Qd import GetPort, GetRegionBounds, GetClip, NewRgn
        print "..._mac_origin =", self._mac_origin
        port = GetPort()
        rgn = NewRgn()
        port.GetPortVisibleRegion(rgn)
        print "...port vis rgn bounds =", GetRegionBounds(rgn)
        GetClip(rgn)
        print "...port clip rgn bounds =", GetRegionBounds(rgn)
        r = self.viewed_rect()
        print "...viewed_rect =", r
    
    def blue_update_rgn(self, c):
        c.forecolor = blue
        c.fill_rect(self.viewed_rect())

    def draw(self, c):
        viewed_rect = self.viewed_rect()
        c.forecolor = white
        c.fill_rect(viewed_rect)
        c.forecolor = red
        x = 10
        y = 10
        for i in xrange(0, 20):
            c.newpath()
            c.moveto(x + 20, y)
            c.rlineto(20, 30)
            c.rlineto(-40, 0)
            c.closepath()
            c.fill()
            x += 40
            y += 40


