# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Create a tool that shows all kind of different borders in FBLayout
#
# Topic: FBLayout, FBBorderStyle

from pyfbsdk import *
from pyfbsdk_additions import *

regionStyles = {
    "No Border" : FBBorderStyle.kFBNoBorder,
    "Standard" : FBBorderStyle.kFBStandardBorder,
    "Emboss" : FBBorderStyle.kFBEmbossBorder,
    "EmbossEdgeSmooth" : FBBorderStyle.kFBEmbossEdgeSmoothBorder,
    "EmbossSmooth" : FBBorderStyle.kFBEmbossSmoothBorder,
    "EmbossSmoothEdge" : FBBorderStyle.kFBEmbossSmoothEdgeBorder,
    "Highlight" : FBBorderStyle.kFBHighlightBorder,
    "Picking" : FBBorderStyle.kFBPickingBorder,
    "Standard (again)" : FBBorderStyle.kFBStandardBorder,
    "StandardEdgeSmooth" : FBBorderStyle.kFBStandardEdgeSmoothBorder,
    "StandardSmooth" : FBBorderStyle.kFBStandardSmoothBorder,
    "StandardSmoothEdge" : FBBorderStyle.kFBStandardSmoothEdgeBorder
    }

def OnInset(control,event):
    for name, style in regionStyles.iteritems():
        regionLyt.SetBorder(name,style,True, control.State,2,2,90,0)

# Button creation
def PopulateLayout(mainLyt):
    x = FBAddRegionParam(10, FBAttachType.kFBAttachLeft, "")
    y = FBAddRegionParam(10, FBAttachType.kFBAttachTop, "")
    w = FBAddRegionParam(120,FBAttachType.kFBAttachNone,"")
    h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
    cb = FBButton()
    cb.Style = FBButtonStyle.kFBCheckbox
    cb.Caption = "Inset"
    cb.OnClick.Add(OnInset)

    # Create a check box that will turn on/off Inset
    mainLyt.AddRegion("Inset", "Inset",x,y,w,h)
    mainLyt.SetControl("Inset",cb)

    global regionLyt
    regionLyt = mainLyt

    regionNames = regionStyles.keys()

    yAttach = FBAttachType.kFBAttachBottom
    yAttachTo = "Inset"
    for i in range(3):
        xAttach = FBAttachType.kFBAttachLeft
        xAttachTo = ""
        for j in range(4):
            x = FBAddRegionParam(10, xAttach, xAttachTo)
            y = FBAddRegionParam(10, yAttach, yAttachTo)
            w = FBAddRegionParam(120,FBAttachType.kFBAttachNone,"")
            h = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")

            regionName = regionNames[i * 4 + j]

            mainLyt.AddRegion(regionName,regionName, x, y, w, h)
            mainLyt.SetBorder(regionName,regionStyles[regionName],True, False,2,2,90,0)

            xAttach = FBAttachType.kFBAttachRight
            xAttachTo = regionName

        yAttach = FBAttachType.kFBAttachBottom
        yAttachTo = regionName

def CreateTool():
    # Tool creation will serve as the hub for all other controls
    t = CreateUniqueTool("Regions")
    t.StartSizeX = 600
    t.StartSizeY = 400
    PopulateLayout(t)
    ShowTool(t)


CreateTool()