import c4d
from ssp_utils_image import LoadImage
from ssp_utils_dialog import *
from ssp_ids import *


####################################################################################################
# Class DialogAbout ################################################################################
####################################################################################################
ID_BUTTON_WEB = 1000

W_TEXT = 200
H_BUTTON = 30


class DialogAbout(c4d.gui.GeDialog):
    _title = ''

    def __init__(self, title=PLUGIN_NAME):
        self._title = title
        c4d.gui.GeDialog.__init__(self)


    def CreateLayout(self):
        bmpLogo = LoadImage('logo')
        if bmpLogo is None:
            print('{0} ERROR: Failed to load logo'.format(PLUGIN_NAME))

        self.SetTitle(self._title)

        if self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=1): # Dialog main group
            self.GroupBorderSpace(7, 5, 7, 5)
            self.GroupSpace(0, 5)

            if self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=2): # About content group
                self.GroupSpace(20, 0)

                if self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_CENTER, cols=1): # Logo
                    CreateLayoutAddBitmap(self, bmpLogo)

                self.GroupEnd() # Logo

                if self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_CENTER, cols=1): # About Text
                    self.AddStaticText(0, c4d.BFH_SCALEFIT, initw=W_TEXT, name='{0}'.format(PLUGIN_NAME))
                    self.AddStaticText(0, c4d.BFH_SCALEFIT, initw=W_TEXT, name='Version {0}'.format(PLUGIN_VERSION))
                    self.AddStaticText(0, c4d.BFH_SCALEFIT, initw=W_TEXT, name='(c) 3DtoAll.')
                    self.AddStaticText(0, c4d.BFH_SCALEFIT, initw=W_TEXT, name='All rights reserved')
                    self.AddStaticText(0, c4d.BFH_SCALEFIT, initw=W_TEXT, name='3dtoall.com')

                self.GroupEnd() # About Text

            self.GroupEnd() # About content group

            self.AddSeparatorV(0, c4d.BFH_SCALEFIT)

            if self.GroupBegin(0, c4d.BFH_CENTER | c4d.BFV_BOTTOM, cols=2): # Dialog finish group
                self.GroupBorder(c4d.BORDER_WITH_TITLE_MONO)
                self.GroupBorderSpace(15, 0, 0, 10)

                self.AddButton(c4d.DLG_OK, c4d.BFH_CENTER, initw=75, inith=H_BUTTON, name='OK')
                self.AddButton(ID_BUTTON_WEB, c4d.BFH_CENTER, initw=140, inith=H_BUTTON, name='Visit Website...')

            self.GroupEnd() # Dialog finish group

        self.GroupEnd() # Dialog main group

        return True


    def Command(self, id, msg):
        if id == c4d.DLG_OK:
            self.Close()

        elif id == ID_BUTTON_WEB:
            c4d.storage.GeExecuteFile(URL_3DTOALL)

        return True
