##########################################################
# proTyres Display Mode Lib by Jens Roos (Wergilius at AC forum)
#
# 2.0.0 200528
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# For GNU General Public License see <http://www.gnu.org/licenses/>.
######################################################################

import ac
from lib.proTyres_def import *
from lib.proTyres_util import setDrawBarR

def changeModeTyre(appWindow,cfg,tyre):

  #set correct app size
  w=cfg.MainWidth
  h=oh=cfg.MainHeight
  c=0
  if cfg.DisplayMode[0]&COMPACT:
    w=cfg.MainCmpWidth
    oh=cfg.MainCmpHeight
    h=oh+int(15*cfg.Scale)
  if cfg.DisplayMode[0]&COMPACT+EXTEND==EXTEND:
    c=cfg.eolWidth
  elif cfg.DisplayMode[0]&COMPACT+EXTEND==COMPACT+EXTEND:
    c=cfg.eolWidth+int(cfg.SpacingBar/2)

  #adjust for nowear displaymode
  if cfg.DisplayMode[0]&EXTEND+NOWEAR==EXTEND+NOWEAR:
    nw=int(24*cfg.Scale)
    cfg.SpacingX=int(-16*cfg.Scale)
  else:
    cfg.SpacingX=int(8*cfg.Scale)
    nw=0

  ac.setSize(appWindow, w+c-nw, h)

  #size of outer border and reduction of width/height
  bs = cfg.BorderSize
  x = 0
  y = 0

  #tyre compound short label
  oh-=int((oh-(cfg.Height*2+cfg.SpacingY))/2)
  if cfg.DisplayMode[0]&NOWEAR or cfg.DisplayMode[0]&COMPACT+EXTEND==COMPACT+EXTEND:
    ac.setPosition(tyre.lblTyreCompound, x+w+c-nw-cfg.FontSpace-1, oh+1)
    ac.setFontAlignment(tyre.lblTyreCompound, "right")
  else:
    ac.setPosition(tyre.lblTyreCompound, (x+w-nw)/2, oh+1)
    ac.setFontAlignment(tyre.lblTyreCompound, "center")

  #config elements if button enabled     
  if not cfg.DisableButton&CONFIG:
    #config spinners
    if cfg.DisplayMode[0]&COMPACT:
      ac.setPosition(tyre.spinCfg[0], -cfg.FontSize*5,cfg.MainCmpHeight/2-cfg.SpacingY/2-cfg.Height/2-cfg.FontSize/2+bs-cfg.FontSize/2)
      ac.setPosition(tyre.spinCfg[1], -cfg.FontSize*5,cfg.MainCmpHeight/2+cfg.SpacingY/2+cfg.Height/2-cfg.FontSize/2+bs+cfg.FontSize/2)
      ac.setPosition(tyre.lblCfgInfo, -cfg.FontSize*5,cfg.MainCmpHeight/2-(cfg.FontSize*4.0)/2+bs)
    else:
      ac.setPosition(tyre.spinCfg[0], -cfg.FontSize*5,cfg.MainHeight/2-cfg.SpacingY/2-cfg.Height/2-cfg.FontSize/2+bs-cfg.FontSize/2)
      ac.setPosition(tyre.spinCfg[1], -cfg.FontSize*5,cfg.MainHeight/2+cfg.SpacingY/2+cfg.Height/2-cfg.FontSize/2+bs+cfg.FontSize/2)
      ac.setPosition(tyre.lblCfgInfo, -cfg.FontSize*5,cfg.MainHeight/2-(cfg.FontSize*4.0)/2+bs)
    ac.setVisible(tyre.spinCfg[0], 0)
    ac.setVisible(tyre.spinCfg[1], 0)
    ac.setVisible(tyre.lblCfgInfo, 0)

  #if eol is used
  if cfg.useEOL:
    #eol border
    if cfg.DisplayMode[0]&COMPACT:
      tyre.eolBorder.x = cfg.MainCmpWidth+cfg.SpacingBar-cfg.BorderSize-nw
      tyre.eolBorder.y = y+cfg.MainCmpHeight-int((cfg.MainCmpHeight-tyre.eolBorder.h)/2)
    else:
      tyre.eolBorder.x = cfg.MainWidth-nw
      tyre.eolBorder.y = y+cfg.MainHeight-int((cfg.MainHeight-tyre.eolBorder.h)/2)

    #eol
    tyre.eolBar.x = tyre.eolBorder.x+bs
    tyre.eolBar.y = tyre.eolBorder.y-bs

    #eol markers (y is changed from tyre, set dummy if needed)
    if not tyre.isValid:
      tyre.eolMarker.y = [tyre.eolBar.y-int(tyre.eolBar.h/4),tyre.eolBar.y-int(tyre.eolBar.h/4*2),tyre.eolBar.y-int(tyre.eolBar.h/4*3)]
    tyre.eolMarker.x = tyre.eolBar.x

    #eol laps, if not compact display mode
    if cfg.DisplayMode[0]&COMPACT+EXTEND+NOWEAR==EXTEND:
      #eol laps, if not compact display mode
      ac.setPosition(tyre.lblEolLaps, tyre.eolBorder.x+tyre.eolBorder.w-2, tyre.eolBorder.y+1)
      ac.setVisible(tyre.lblEolLaps, 1)          
    else:
      ac.setVisible(tyre.lblEolLaps, 0)          

    #eol info range labels
    #remember, pos is also set in function loadCompound for i 0-2 and changeEolHeight
    for i in range(0,5):
      if i<3:
        tyre.eolMarker.y[i] = tyre.eolBar.y-int(tyre.eolBar.h*((tyre.eol[tyre.eolIdx].Levels[i+1]-tyre.eol[tyre.eolIdx].Levels[0])/-tyre.eol[tyre.eolIdx].Levels[0]))
        ac.setPosition(tyre.lblEolInfo[i], tyre.eolBorder.x+tyre.eolBorder.w+cfg.FontSpace-1, tyre.eolMarker.y[i]-1-cfg.FontSize*1.5/2)
      elif i==3:
        ac.setPosition(tyre.lblEolInfo[i], tyre.eolBorder.x+tyre.eolBorder.w+cfg.FontSpace-1, 0)
      elif cfg.showEOLgain:
        if not cfg.DisplayMode[0]&COMPACT:
          ac.setPosition(tyre.lblEolInfo[i], tyre.eolBorder.x+tyre.eolBorder.w+cfg.FontSpace-1, cfg.MainHeight-cfg.FontSize*1.5)
        else:
          ac.setPosition(tyre.lblEolInfo[i], tyre.eolBorder.x+tyre.eolBorder.w+cfg.FontSpace-1, cfg.MainCmpHeight)
      ac.setVisible(tyre.lblEolInfo[i], 0)
      
    #set info labels position
    #if tyre.isValid:
    #  for i in range(0,3):
    #    ac.setPosition(tyre.lblEolInfo[i], tyre.eolBorder.x+tyre.eolBorder.w+cfg.FontSpace-1, tyre.eolMarker.y[i]-1-cfg.FontSize*1.5/2)

    #set the compound short label
    if cfg.DisplayMode[0]&COMPACT+EXTEND!=COMPACT+EXTEND or cfg.DisplayMode[0]&NOWEAR+EXTEND!=NOWEAR+EXTEND:
      ac.setText(tyre.lblTyreCompound, tyre.CompoundShort[0:4])

  #set size of pitboard if used
  if sum(cfg.PitBoard)>0:
    #save basic position of pitboard
    tyre.lblPitBoardLeft = w+c-nw
    #set postion of pitboard
    setsizePitBoard(cfg,tyre)
    
def setsizePitBoard(cfg,tyre):
    #default attributes
    i = 13.6
    o = 18
    #if not eol, use shorter pitboard
    if not cfg.useEOL:
      i=5.6
    #if extended pitboard information is availible (cfg.PitBoardExtra), index is higher than 2
    if cfg.PitBoardExtra:  #tyre.lblPitBoardIdx>2:
      #o+=8
      ac.setPosition(tyre.lblPitBoard[2], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2-cfg.FontSize*8, -(cfg.FontSpace+cfg.FontSize*7.2))
      ac.setPosition(tyre.lblPitBoard[3], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2-cfg.FontSize*8, -(cfg.FontSpace+cfg.FontSize*5.8))
      ac.setPosition(tyre.lblPitBoard[4], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2-cfg.FontSize*4, -(cfg.FontSpace+cfg.FontSize*5.8))
      ac.setPosition(tyre.lblPitBoard[5], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2-cfg.FontSize*8, -(cfg.FontSpace+cfg.FontSize*2.7))
      ac.setPosition(tyre.lblPitBoard[6], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2-cfg.FontSize*4, -(cfg.FontSpace+cfg.FontSize*2.7))
      ac.setPosition(tyre.lblPitBoard[7], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2-cfg.FontSize*8, -(cfg.FontSpace+cfg.FontSize*4.5))
      ac.setPosition(tyre.lblPitBoard[8], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2-cfg.FontSize*4, -(cfg.FontSpace+cfg.FontSize*4.5))
      ac.setPosition(tyre.lblPitBoard[9], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2-cfg.FontSize*8, -(cfg.FontSpace+cfg.FontSize*1.4))
      ac.setPosition(tyre.lblPitBoard[10], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2-cfg.FontSize*4, -(cfg.FontSpace+cfg.FontSize*1.4))
      
    #set position of std pitboard info
    ac.setPosition(tyre.lblPitBoard[0], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2, -(cfg.FontSpace+cfg.FontSize*i))
    ac.setPosition(tyre.lblPitBoard[1], (tyre.lblPitBoardLeft-cfg.FontSize*o)/2+cfg.FontSize*7, -(cfg.FontSpace+cfg.FontSize*i))

#set positions for eol markers and labels
def changeEolHeight(cfg,tyre,info):
  tyre.eolLvlAdj[0] = tyre.eol[tyre.eolIdx].Levels[0]/tyre.eol[tyre.eolIdx].DynGain[1]
  for i in range(0,3):
    tyre.eolLvlAdj[i+1] = tyre.eol[tyre.eolIdx].Levels[i+1]/tyre.eol[tyre.eolIdx].DynGain[i*2+3]
    #make sure labels and markes do not go outside range even if crazy gain
    if tyre.eolLvlAdj[i+1]>tyre.eolLvlAdj[0]:
      tyre.eolLvlAdj[i+1]=tyre.eolLvlAdj[0] 
    tyre.eolMarker.y[i] = tyre.eolBar.y-int(tyre.eolBar.h*((tyre.eolLvlAdj[i+1]-tyre.eolLvlAdj[0])/-tyre.eolLvlAdj[0]))
    if info:
      ac.setPosition(tyre.lblEolInfo[i], tyre.eolBorder.x+tyre.eolBorder.w+cfg.FontSpace-1, tyre.eolMarker.y[i]-1-cfg.FontSize*1.5/2)

def changeModeIndicator(appWindow,x,y,cfg,tyreBox,eolx,eoly):

  tyreBox.posX = x                       #position, bottom left
  tyreBox.posY = y
  hAlign = tyreBox.hAlign                #position left of right
  vAlign = tyreBox.vAlign                #position top or bottom

  #setting up all labels and graphic element
  #cordinates is X,Y, x is going to the right, y is going down
  #indicator setup is based on bottom left corner and is built upwards to the right
  #the indictor can then be set LEFT or (default) RIGHT
  #tyre contact indicator and text is TOP or (default) BOTTOM
  #barmode indicators is default BOTTOM and optional CENTER based 

  #hAlign temp reading in center top or bottom
  if vAlign==TOP:
    o = -(cfg.Height+cfg.FontSize+cfg.FontSpace)-cfg.BorderSize*2-1
  else:
    o = 1

  if not cfg.DisplayMode[0]&COMPACT:
    #actual temp of core
    ac.setPosition(tyreBox.lblTempCore, x+(cfg.Width/2*hAlign), y+o)
    ac.setVisible(tyreBox.lblTempCore,1)
  else:
    ac.setVisible(tyreBox.lblTempCore,0)
    

  #hAlign pressure indication to outer of the box
  #if vAlign==BOTTOM and cfg.CenterBar:
  #  o = -cfg.FontSize-cfg.TyreIndicatorHeight
  #else:
  o = -(cfg.FontSize-cfg.AuxIndicatorHeight/2+2)
  #offset to center of bar
  #o += int((cfg.Height-cfg.TyreIndicatorHeight-cfg.FontSize*3-cfg.FontSpace*2)/2+2)

  #align text on left or right side
  if hAlign==RIGHT:
    to = cfg.FontSize*2+1
  else:
    to = 1

  if not cfg.DisplayMode[0]&COMPACT:
    if cfg.PressureLabel[0]==STANDARD:
      #actual pressure
      ac.setPosition(tyreBox.lblPressure, x+((cfg.Width+cfg.FontSpace+to)*hAlign), y-cfg.Height/2+o)
      ac.setVisible(tyreBox.lblPressure,1)
      #psi label indicator
      ac.setPosition(tyreBox.lblPressInfo, x+((cfg.Width+cfg.FontSpace+to)*hAlign), y-cfg.Height/2-cfg.FontSize-cfg.FontSpace+o)
      ac.setVisible(tyreBox.lblPressInfo,1)
      #difference from optimal pressure
      ac.setPosition(tyreBox.lblPressDiff, x+((cfg.Width+cfg.FontSpace+to)*hAlign), y-cfg.Height/2+cfg.FontSize+cfg.FontSpace+o)
    else:
      #difference from optimal pressure
      ac.setPosition(tyreBox.lblPressDiff, x+((cfg.Width+cfg.FontSpace+to)*hAlign), y-cfg.Height/2+o)
      ac.setVisible(tyreBox.lblPressure,0)
      ac.setVisible(tyreBox.lblPressInfo,0)
    ac.setVisible(tyreBox.lblPressDiff,1)
  else:
    ac.setVisible(tyreBox.lblPressure,0)
    ac.setVisible(tyreBox.lblPressDiff,0)
    ac.setVisible(tyreBox.lblPressInfo,0)

  #size of outer border and reduction of width/height
  bs = cfg.BorderSize
  
  #offset for left/right elements
  if hAlign==LEFT:
    o = -cfg.Width
    lo = cfg.TyreIndicatorWidth*2
    bo = cfg.Width-cfg.BarWidth
  else:
    o = 0
    lo = 0
    bo = 0
  #offset for top/bottom elements, optionally force IMO on top
  if vAlign==TOP or cfg.TopTyreMode:
    t = cfg.TyreIndicatorHeight
    ot = -cfg.Height+cfg.TyreIndicatorHeight
    if cfg.useRadius:
      ot += 1
    if not cfg.showTempBar:
      nt = -int((tyreBox.TempIn.h-tyreBox.TempBorder.h)/2)
    else:
      nt = -tyreBox.TempIn.h+tyreBox.TempBorder.h+bs
    if cfg.showNew:
      tb = -bs
    else:
      tb = -int((tyreBox.TempIn.h-tyreBox.TempBar.h)/2)
    #if centermode and forced IMO
    #if cfg.CenterBar and cfg.TopTyreMode and (vAlign==BOTTOM):
    #  ob = cfg.TyreIndicatorHeight
    #else:
    #  ob = 0
  else:
    t = -bs
    ot = 0
    if cfg.useRadius:
      ot -= 1
    if not cfg.showTempBar:
      nt = -tyreBox.TempIn.h+tyreBox.TempBorder.h+int((tyreBox.TempIn.h-tyreBox.TempBorder.h)/2)
    else:
      nt = -bs
    if cfg.showNew:
      tb = -tyreBox.TempIn.h+tyreBox.TempBar.h+bs
    else:
      tb = -int((tyreBox.TempIn.h-tyreBox.TempBar.h)/2)
    #if bottom and center mode
    #if cfg.CenterBar:
    #  ob = cfg.TyreIndicatorHeight
    #else:
    #  ob = 0
  ob = cfg.AuxIndicatorHeight/2
    
  #create indicator objects, colors will be overwritten if tyre is validated
  #border outline of indicator bars
  tyreBox.Border.x = tyreBox.posX+o
  tyreBox.Border.y = tyreBox.posY-ob

  #reset shape flags
  shapeC = RAD_RIGHT+RAD_LEFT+ALPHA_LEFT+ALPHA_RIGHT
  shapeI = 0
  if not cfg.useRadius:
    shapeM = ALPHA_TOP+ALPHA_BOTTOM
  else:
    shapeM = 0
  shapeO = 0
  shapeA = ALPHA_LEFT+ALPHA_RIGHT

  #set left/right radius for IMO
  if hAlign==LEFT:
    shapeI += RAD_RIGHT+ALPHA_RIGHT
    shapeO += RAD_LEFT+ALPHA_LEFT
  else:
    shapeI += RAD_LEFT+ALPHA_LEFT
    shapeO += RAD_RIGHT+ALPHA_RIGHT
    
  #set top/bottom radius for IMO and Core
  if (cfg.TopTyreMode and vAlign==BOTTOM) or vAlign==TOP:
    shapeI += RAD_TOP
    shapeO += RAD_TOP
    shapeC += RAD_BOTTOM
    if cfg.useRadius:
      shapeM = ALPHA_TOP
    else:
      shapeC += ALPHA_TOP
      shapeI += ALPHA_BOTTOM
      shapeO += ALPHA_BOTTOM
  else:
    shapeI += RAD_BOTTOM
    shapeO += RAD_BOTTOM
    shapeC += RAD_TOP
    if cfg.useRadius:
      shapeM = ALPHA_BOTTOM
    else:
      shapeC += ALPHA_BOTTOM
      shapeI += ALPHA_TOP
      shapeO += ALPHA_TOP
      
  #temp core
  tyreBox.TempCore.x = tyreBox.posX+cfg.BarWidth+cfg.SpacingBar+o
  tyreBox.TempCore.y = tyreBox.posY-cfg.Height+cfg.TyreIndicatorHeight-ot
  setDrawBarR(cfg,tyreBox.TempCore,cfg.useRadius,shapeC)

  #temp avg
  tyreBox.TempAvg.x = tyreBox.posX+cfg.BarWidth+cfg.SpacingBar+o
  tyreBox.TempAvg.y = tyreBox.posY-cfg.TyreIndicatorHeight-bs
  setDrawBarR(cfg,tyreBox.TempAvg,False,shapeA)

  #temp inner
  tyreBox.TempIn.x = tyreBox.posX+cfg.BarWidth+cfg.SpacingBar+o+lo
  tyreBox.TempIn.y = tyreBox.posY+ot
  setDrawBarR(cfg,tyreBox.TempIn,cfg.useRadius,shapeI)

  #temp middle
  tyreBox.TempMid.x = tyreBox.posX+cfg.BarWidth+cfg.TyreIndicatorWidth+cfg.SpacingBar+o
  tyreBox.TempMid.y = tyreBox.posY+ot
  setDrawBarR(cfg,tyreBox.TempMid,False,shapeM)

  #temp outer
  tyreBox.TempOut.x = tyreBox.posX+cfg.BarWidth+cfg.TyreIndicatorWidth*2+cfg.SpacingBar+o-lo
  tyreBox.TempOut.y = tyreBox.posY+ot
  setDrawBarR(cfg,tyreBox.TempOut,cfg.useRadius,shapeO)

  #border indicator for new tyre
  tyreBox.TempBorder.x = tyreBox.TempAvg.x+int((tyreBox.TempAvg.w-tyreBox.TempBorder.w)/2)
  tyreBox.TempBorder.y = tyreBox.TempIn.y+nt

  #temp optimal range bar
  tyreBox.TempBar.x = tyreBox.TempAvg.x
  tyreBox.TempBar.y = tyreBox.TempIn.y+tb
  tyreBox.TempBar.idx = tyreBox.TempBar.y #save as newtyre position
  
  #brake indicator for slip
  tyreBox.Brake.x = tyreBox.TempAvg.x+int((tyreBox.TempAvg.w-tyreBox.Brake.w)/2)
  tyreBox.Brake.y = tyreBox.TempAvg.y-int((tyreBox.TempAvg.h-tyreBox.Brake.h)/2)

  #wear
  tyreBox.Wear.x = tyreBox.posX+o+bo+bs
  tyreBox.Wear.y = tyreBox.Border.y-bs

  #wear markers
  tyreBox.WearMarker.x = tyreBox.Wear.x
  tyreBox.WearMarker.y = [tyreBox.Wear.y-int(tyreBox.Wear.h*(cfg.WearLevels[1]-cfg.WearLevels[0])/(cfg.WearLevels[3]-cfg.WearLevels[0])),
                          tyreBox.Wear.y-int(tyreBox.Wear.h*(cfg.WearLevels[2]-cfg.WearLevels[0])/(cfg.WearLevels[3]-cfg.WearLevels[0]))]

  #pressure
  tyreBox.Pressure.x = tyreBox.posX+cfg.Width-cfg.BarWidth+o-bo+bs
  tyreBox.Pressure.y = tyreBox.Border.y-bs

  #pressure optimal range marker
  tyreBox.PressureMarker.x = tyreBox.posX+cfg.Width-cfg.BarWidth+o-bo+bs

  #not auto, using fixed scale for markers and range
  #reminder, y pos and h is also set in setLabelValue when auto
  if cfg.PressureBar[0]!=AUTO:
    tyreBox.PressureStep = cfg.PressureBar[0]
  else:
    tyreBox.PressureStep = SCALE16    
  tyreBox.PressureMarker.h = int(round(cfg.IdealPressureRange/(tyreBox.PressureStep*4.0)*(cfg.Height-cfg.AuxIndicatorHeight-cfg.BorderSize*2)))
  tyreBox.PressureMarker.y = int(tyreBox.Pressure.y-tyreBox.Pressure.h/2+tyreBox.PressureMarker.h/2)

  #placement of the dirty bar
  if not cfg.DirtyBarTyre:
    if not cfg.DisplayMode[0]&NOWEAR:
      #dirty in wear bar
      tyreBox.Dirty.x = int(tyreBox.posX+(cfg.BarWidth-cfg.DirtyWidth)/2+o+bo)
      tyreBox.Dirty.y = tyreBox.Border.y-bs
      tyreBox.Dirty.h = tyreBox.Border.h-bs*2
    else:
      #dirty in eol bar
      tyreBox.Dirty.x = int(eolx+(cfg.BarWidth-cfg.DirtyWidth)/2)
      tyreBox.Dirty.y = eoly-bs
      tyreBox.Dirty.h = cfg.Height*2+cfg.SpacingY-bs*2
  else:
    #dirty in tyre box
    tyreBox.Dirty.x = int(tyreBox.posX+cfg.BarWidth+cfg.TyreIndicatorWidth/2+cfg.SpacingBar+o)
    tyreBox.Dirty.y = tyreBox.TempAvg.y

def changeModeApp(appMain,setup,cfg):

  #load background image for main app based on background and display mode
  b=setup.Background
  c=""
  e=""
  w=""
  u=""
  s=""
  #if cfg.MainBackground==PLAIN:
  #  b=setup.plainBackground
  if cfg.DisplayMode[0]&COMPACT:
    c="cmp"
  if cfg.DisplayMode[0]&EXTEND:
    e="ext"
  if cfg.DisplayMode[0]&NOWEAR:
    w="nw"
  if c!="" or e!="" or w!="":
    u="_"
  if cfg.Scale>1.5:
    s="20"
  elif cfg.Scale>1.0:
    s="15"
  #set background texture if used
  if cfg.MainBackground==STANDARD:
    ac.setBackgroundTexture(appMain.App, b+u+c+e+w+s+".png")

  #display mode button, if enabled
  if not cfg.DisableButton&DISPLAY:
    if cfg.DisplayMode[0]&COMPACT:
      ac.setPosition(appMain.bttnMode, 1, cfg.MainCmpHeight+2)
    else:
      #ac.setPosition(appMain.bttnMode, cfg.FontSpace, cfg.MainHeight-cfg.FontSize-cfg.FontSpace)
      ac.setPosition(appMain.bttnMode, 2, cfg.MainHeight+2)

  #config button if enabled and auto menu is not used     
  if not cfg.DisableButton&CONFIG and not cfg.configMenu&OPEN:
    x=0
    #check if display or config button is disabled
    if not cfg.DisableButton&DISPLAY:
      x+=1
    #config button
    if cfg.DisplayMode[0]&COMPACT:
      ac.setPosition(appMain.bttnCfg, 1+cfg.BttnSize*x+cfg.FontSpace*x, cfg.MainCmpHeight+2)
    else:
      #ac.setPosition(bttnCfg, cfg.FontSize*x+cfg.FontSpace*(x+1), cfg.MainHeight-cfg.FontSize-cfg.FontSpace)
      ac.setPosition(appMain.bttnCfg, 2+cfg.BttnSize*x+cfg.FontSpace*x, cfg.MainHeight+2)

  #info button, if enabled
  if not cfg.DisableButton&INFO and cfg.useEOL:
    #must be extend mode and pitboard can not be disabled and exklusve for pitboard only
    if cfg.DisplayMode[0]&EXTEND and (cfg.PitBoardOpen&INFO==INFO or cfg.PitBoard[0]!=0):
      x=0
      #check if display or config button is disabled
      if not cfg.DisableButton&DISPLAY:
        x+=1
      if not cfg.DisableButton&CONFIG and not cfg.configMenu&OPEN:
        x+=1
      #info button
      if cfg.DisplayMode[0]&COMPACT+EXTEND==COMPACT+EXTEND:
        ac.setPosition(appMain.bttnInfo, 1+cfg.BttnSize*x+cfg.FontSpace*x, cfg.MainCmpHeight+2)
      else:
        #ac.setPosition(appMain.bttnInfo, cfg.FontSize*x+cfg.FontSpace*(x+1), cfg.MainHeight-cfg.FontSize-cfg.FontSpace)
        ac.setPosition(appMain.bttnInfo, 2+cfg.BttnSize*x+cfg.FontSpace*x, cfg.MainHeight+2)
      ac.setVisible(appMain.bttnInfo,1)
    else:
      ac.setVisible(appMain.bttnInfo,0)
     
          

