import c4d


def CreateLayoutAddBitmap(dlg, bmp, id=0, button=False, toggle=False, border=c4d.BORDER_NONE, flags=c4d.BFH_CENTER|c4d.BFV_CENTER):
    bcOptions = c4d.BaseContainer()

    bcOptions.SetInt32(c4d.BITMAPBUTTON_IGNORE_BITMAP_WIDTH, False)
    bcOptions.SetInt32(c4d.BITMAPBUTTON_IGNORE_BITMAP_HEIGHT, False)
    bcOptions.SetBool(c4d.BITMAPBUTTON_BORDER, border)
    bcOptions.SetBool(c4d.BITMAPBUTTON_BUTTON, button)
    bcOptions.SetBool(c4d.BITMAPBUTTON_TOGGLE, toggle)
    bcOptions.SetString(c4d.BITMAPBUTTON_TOOLTIP, '')

    bitmapButton = dlg.AddCustomGui(id, c4d.CUSTOMGUI_BITMAPBUTTON, '', flags, 0, 0, bcOptions)
    bitmapButton.SetImage(bmp, True)

    return bitmapButton


def CreateLayoutAddBitmapButton(dlg, idButton, idIconState1=-1, idIconState2=-1, bmp1=None, bmp2=None,
                                tooltip='', button=True, toggle=True,
                                flags=c4d.BFH_CENTER|c4d.BFV_CENTER, inMenu=False, w=0, h=0, border=c4d.BORDER_NONE,
                                noHover=False):
    bc = c4d.BaseContainer()

    if inMenu:
        bc.SetInt32(c4d.BITMAPBUTTON_IGNORE_BITMAP_WIDTH, False)
        bc.SetInt32(c4d.BITMAPBUTTON_IGNORE_BITMAP_HEIGHT, True)
        w = 32
        h = 16

    else:
        bc.SetInt32(c4d.BITMAPBUTTON_IGNORE_BITMAP_WIDTH, False)
        bc.SetInt32(c4d.BITMAPBUTTON_IGNORE_BITMAP_HEIGHT, False)

    bc.SetInt32(c4d.BITMAPBUTTON_BORDER, border)
    bc.SetBool(c4d.BITMAPBUTTON_BUTTON, button)
    bc.SetBool(c4d.BITMAPBUTTON_TOGGLE, toggle)
    bc.SetString(c4d.BITMAPBUTTON_TOOLTIP, tooltip)

    if idIconState1 != -1:
        bc.SetInt32(c4d.BITMAPBUTTON_ICONID1, idIconState1)

    if idIconState2 != -1:
        bc.SetInt32(c4d.BITMAPBUTTON_ICONID2, idIconState2)

    if noHover and c4d.GetC4DVersion() // 1000 >= 22:
        bcOptions.SetBool(c4d.BITMAPBUTTON_DISABLE_FADING, True)


    bitmapButton = dlg.AddCustomGui(idButton, c4d.CUSTOMGUI_BITMAPBUTTON, '', flags, w, h, bc)

    if bmp1 is not None:
        bitmapButton.SetImage(bmp1, copybmp=True, secondstate=False)

    if bmp2 is not None:
        bitmapButton.SetImage(bmp2, copybmp=True, secondstate=True)

    return bitmapButton


def CreateLayoutAddGroupBar(dlg, title):
    bc = c4d.BaseContainer()

    bc.SetInt32(c4d.QUICKTAB_BAR, 1)
    bc.SetString(c4d.QUICKTAB_BARTITLE, title)

    return dlg.AddCustomGui(0, c4d.CUSTOMGUI_QUICKTAB, '', c4d.BFH_SCALEFIT | c4d.BFV_TOP, 0, 0, bc)


def CreateLayoutAddQuickTab(dlg, id, flags=c4d.BFH_SCALEFIT|c4d.BFV_TOP):
    bc = c4d.BaseContainer()

    bc.SetInt32(c4d.QUICKTAB_BAR, 0)
    bc.SetBool(c4d.QUICKTAB_NOMULTISELECT, True)
    bc.SetBool(c4d.QUICKTAB_SHOWSINGLE, True)

    return dlg.AddCustomGui(id, c4d.CUSTOMGUI_QUICKTAB, '', flags, 0, 0, bc)
