P3NG3R

TextLineColorTest

Jun 15th, 2021 (edited)
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 15.43 KB | None | 0 0
  1. import ui
  2. import wndMgr
  3.  
  4. class TextLineColorTest(ui.BoardWithTitleBar):
  5.     WIDTH = 400
  6.     HEIGHT = 330
  7.     def __init__(self):
  8.         ui.BoardWithTitleBar.__init__(self)
  9.  
  10.         # wndMgr.SetOutlineFlag(1)
  11.         self.rainbauwFontSeed = 0.
  12.         self.rainbauwOutLineSeed = 0.
  13.         self.rainbauwSpeed = .3
  14.         self.rainbauwFont = False
  15.         self.rainbauwOutLine = False
  16.         self.colorFont = [0.0, 0.0, 0.0]
  17.         self.colorOutLine = [0.0, 0.0, 0.0, 0.0]
  18.         self.__LoadWindow()
  19.         self.__LoadGUI()
  20.  
  21.     def __del__(self):
  22.         ui.BoardWithTitleBar.__del__(self)
  23.  
  24.     def __LoadWindow(self):
  25.         self.max_pos_x = wndMgr.GetScreenWidth() - self.WIDTH
  26.         self.max_pos_y = wndMgr.GetScreenHeight() - self.HEIGHT
  27.         self.SetSize(self.WIDTH, self.HEIGHT)
  28.         self.SetCenterPosition()
  29.         self.AddFlag('movable')
  30.         self.SetTitleName(" ~ TextLineColorTest ~ ")
  31.         self.SetCloseEvent(self.Close)
  32.  
  33.     def ResetFontColorSliderBarR(self):
  34.         self.FontColorSliderBarR.SetSliderPos(0.)
  35.         apply(self.FontColorSliderBarR.eventChange, [])
  36.  
  37.     def SeekFontColorSliderBarR(self):
  38.         self.FontColorSliderBarR.SetSliderPos(float(self.FontColorSliderBarR.backGroundImage.GetMouseLocalPosition()[0])/float(self.FontColorSliderBarR.backGroundImage.GetWidth()))
  39.         apply(self.FontColorSliderBarR.eventChange, [])
  40.  
  41.     def OnChangeFontColorR(self):
  42.         pos = self.FontColorSliderBarR.GetSliderPos()
  43.         self.FontRLabel.SetText("Font Red: %d" % (0. + 255.*pos))
  44.         self.colorFont[0] = (255. * pos) / 255.
  45.         self.TextLine.SetFontColor(*self.colorFont)
  46.  
  47.     def ResetFontColorSliderBarG(self):
  48.         self.FontColorSliderBarG.SetSliderPos(0.)
  49.         apply(self.FontColorSliderBarG.eventChange, [])
  50.  
  51.     def SeekFontColorSliderBarG(self):
  52.         self.FontColorSliderBarG.SetSliderPos(float(self.FontColorSliderBarG.backGroundImage.GetMouseLocalPosition()[0])/float(self.FontColorSliderBarG.backGroundImage.GetWidth()))
  53.         apply(self.FontColorSliderBarG.eventChange, [])
  54.  
  55.     def OnChangeFontColorG(self):
  56.         pos = self.FontColorSliderBarG.GetSliderPos()
  57.         self.FontGLabel.SetText("Font Green: %d" % (0. + (255.*pos)))
  58.         self.colorFont[1] = (255. * pos)/ 255.
  59.         self.TextLine.SetFontColor(*self.colorFont)
  60.  
  61.     def ResetFontColorSliderBarB(self):
  62.         self.FontColorSliderBarB.SetSliderPos(0.)
  63.         apply(self.FontColorSliderBarB.eventChange, [])
  64.  
  65.     def SeekFontColorSliderBarB(self):
  66.         self.FontColorSliderBarB.SetSliderPos(float(self.FontColorSliderBarB.backGroundImage.GetMouseLocalPosition()[0])/float(self.FontColorSliderBarB.backGroundImage.GetWidth()))
  67.         apply(self.FontColorSliderBarB.eventChange, [])
  68.  
  69.     def OnChangeFontColorB(self):
  70.         pos = self.FontColorSliderBarB.GetSliderPos()
  71.         self.FontBLabel.SetText("Font Blue: %d" % (0. + (255.*pos)))
  72.         self.colorFont[2] = (255. * pos)/ 255.
  73.         self.TextLine.SetFontColor(*self.colorFont)
  74.  
  75.     def ResetOutLineColorSliderBarR(self):
  76.         self.OutLineColorSliderBarR.SetSliderPos(0.)
  77.         apply(self.OutLineColorSliderBarR.eventChange, [])
  78.  
  79.     def SeekOutLineColorSliderBarR(self):
  80.         self.OutLineColorSliderBarR.SetSliderPos(float(self.OutLineColorSliderBarR.backGroundImage.GetMouseLocalPosition()[0])/float(self.OutLineColorSliderBarR.backGroundImage.GetWidth()))
  81.         apply(self.OutLineColorSliderBarR.eventChange, [])
  82.  
  83.     def OnChangeOutLineColorR(self):
  84.         pos = self.OutLineColorSliderBarR.GetSliderPos()
  85.         self.OutLineRLabel.SetText("OutLine Red: %d" % (0. + (255.*pos)))
  86.         self.colorOutLine[0] = (255. * pos)/ 255.
  87.         self.TextLine.SetOutLineColor(*self.colorOutLine)
  88.  
  89.     def ResetOutLineColorSliderBarG(self):
  90.         self.OutLineColorSliderBarG.SetSliderPos(0.)
  91.         apply(self.OutLineColorSliderBarG.eventChange, [])
  92.  
  93.     def SeekOutLineColorSliderBarB(self):
  94.         self.OutLineColorSliderBarG.SetSliderPos(float(self.OutLineColorSliderBarG.backGroundImage.GetMouseLocalPosition()[0])/float(self.OutLineColorSliderBarG.backGroundImage.GetWidth()))
  95.         apply(self.OutLineColorSliderBarG.eventChange, [])
  96.  
  97.     def OnChangeOutLineColorG(self):
  98.         pos = self.OutLineColorSliderBarG.GetSliderPos()
  99.         self.OutLineGLabel.SetText("OutLine Green: %d" % (0. + (255.*pos)))
  100.         self.colorOutLine[1] = (255. * pos)/ 255.
  101.         self.TextLine.SetOutLineColor(*self.colorOutLine)
  102.  
  103.     def ResetOutLineColorSliderBarB(self):
  104.         self.OutLineColorSliderBarB.SetSliderPos(0.)
  105.         apply(self.OutLineColorSliderBarB.eventChange, [])
  106.  
  107.     def SeekOutLineColorSliderBarB(self):
  108.         self.OutLineColorSliderBarB.SetSliderPos(float(self.OutLineColorSliderBarB.backGroundImage.GetMouseLocalPosition()[0])/float(self.OutLineColorSliderBarB.backGroundImage.GetWidth()))
  109.         apply(self.OutLineColorSliderBarB.eventChange, [])
  110.  
  111.     def OnChangeOutLineColorB(self):
  112.         pos = self.OutLineColorSliderBarB.GetSliderPos()
  113.         self.OutLineBLabel.SetText("OutLine Blue: %d" % (0. + (255.*pos)))
  114.         self.colorOutLine[2] = (255. * pos)/ 255.
  115.         self.TextLine.SetOutLineColor(*self.colorOutLine)
  116.  
  117.     def ResetOutLineColorSliderBarA(self):
  118.         self.OutLineColorSliderBarA.SetSliderPos(0.)
  119.         apply(self.OutLineColorSliderBarA.eventChange, [])
  120.  
  121.     def SeekOutLineColorSliderBarA(self):
  122.         self.OutLineColorSliderBarA.SetSliderPos(float(self.OutLineColorSliderBarA.backGroundImage.GetMouseLocalPosition()[0])/float(self.OutLineColorSliderBarA.backGroundImage.GetWidth()))
  123.         apply(self.OutLineColorSliderBarA.eventChange, [])
  124.  
  125.     def OnChangeOutLineColorA(self):
  126.         pos = self.OutLineColorSliderBarA.GetSliderPos()
  127.         self.OutLineALabel.SetText("OutLine Alpha: %.2f" % (0. + (1.*pos)))
  128.         self.colorOutLine[3] = (1. * pos)/ 1.
  129.         self.TextLine.SetOutLineColor(*self.colorOutLine)
  130.  
  131.     def OnToggleDownRainBowFont(self):
  132.         self.rainbauwFont = True
  133.  
  134.     def OnToggleUpRainBowFont(self):
  135.         self.rainbauwFont = False
  136.         self.rainbauwFontSeed = 0.
  137.         self.ResetFontColorSliderBarR()
  138.         self.ResetFontColorSliderBarG()
  139.         self.ResetFontColorSliderBarB()
  140.  
  141.     def OnToggleDownRainBowOutLine(self):
  142.         self.rainbauwOutLine = True
  143.  
  144.     def OnToggleUpRainBowOutLine(self):
  145.         self.rainbauwOutLine = False
  146.         self.rainbauwOutLineSeed = 0.
  147.         self.ResetOutLineColorSliderBarR()
  148.         self.ResetOutLineColorSliderBarG()
  149.         self.ResetOutLineColorSliderBarB()
  150.         self.ResetOutLineColorSliderBarA()
  151.  
  152.     def __LoadGUI(self):
  153.         self.ModelView = ui.Window()
  154.         self.ModelView.SetParent(self)
  155.         self.ModelView.SetPosition(16, 29)
  156.         self.ModelView.SetSize(190, 300)
  157.         self.ModelView.Show()
  158.  
  159.         self.btnRainBowFont = ui.ToggleButton()
  160.         self.btnRainBowFont.SetParent(self.ModelView)
  161.         self.btnRainBowFont.SetPosition(16, 29)
  162.         self.btnRainBowFont.SetUpVisual("d:/ymir work/ui/public/small_button_01.sub")
  163.         self.btnRainBowFont.SetOverVisual("d:/ymir work/ui/public/small_button_02.sub")
  164.         self.btnRainBowFont.SetDownVisual("d:/ymir work/ui/public/small_button_03.sub")
  165.         self.btnRainBowFont.SetText("Font")
  166.         self.btnRainBowFont.SetToggleDownEvent(ui.__mem_func__(self.OnToggleDownRainBowFont))
  167.         self.btnRainBowFont.SetToggleUpEvent(ui.__mem_func__(self.OnToggleUpRainBowFont))
  168.         self.btnRainBowFont.Show()
  169.        
  170.         self.btnRainBowOutLine = ui.ToggleButton()
  171.         self.btnRainBowOutLine.SetParent(self.ModelView)
  172.         self.btnRainBowOutLine.SetPosition(102, 29)
  173.         self.btnRainBowOutLine.SetUpVisual("d:/ymir work/ui/public/small_button_01.sub")
  174.         self.btnRainBowOutLine.SetOverVisual("d:/ymir work/ui/public/small_button_02.sub")
  175.         self.btnRainBowOutLine.SetDownVisual("d:/ymir work/ui/public/small_button_03.sub")
  176.         self.btnRainBowOutLine.SetText("OutLine")
  177.         self.btnRainBowOutLine.SetToggleDownEvent(ui.__mem_func__(self.OnToggleDownRainBowOutLine))
  178.         self.btnRainBowOutLine.SetToggleUpEvent(ui.__mem_func__(self.OnToggleUpRainBowOutLine))
  179.         self.btnRainBowOutLine.Show()
  180.  
  181.         self.TextLine = ui.TextLine()
  182.         self.TextLine.SetParent(self.ModelView)
  183.         self.TextLine.SetPosition(0, 0)
  184.         self.TextLine.SetOutline(True)
  185.         self.TextLine.SetMultiLine()
  186.         self.TextLine.SetLineHeight(20)
  187.         self.TextLine.SetFontColor(*self.colorFont)
  188.         self.TextLine.SetOutLineColor(*self.colorOutLine)
  189.         self.TextLine.SetText("TEST TEXT COLOR\\nWHAT IS RAINBAUUUW")
  190.         self.TextLine.SetWindowHorizontalAlignCenter()
  191.         self.TextLine.SetWindowVerticalAlignCenter()
  192.         self.TextLine.SetHorizontalAlignCenter()
  193.         self.TextLine.SetVerticalAlignCenter()
  194.         self.TextLine.Show()
  195.  
  196.         self.FontRLabel = ui.TextLine()
  197.         self.FontRLabel.SetParent(self)
  198.         self.FontRLabel.SetText("Font Red: 0")
  199.         self.FontRLabel.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 0 * 20)
  200.         self.FontRLabel.Show()
  201.  
  202.         self.FontColorSliderBarR = ui.SliderBar()
  203.         self.FontColorSliderBarR.SetParent(self)
  204.         self.FontColorSliderBarR.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 1 * 20)
  205.         self.FontColorSliderBarR.SetSliderPos(0.)
  206.         self.FontColorSliderBarR.backGroundImage.OnMouseLeftButtonDown = self.SeekFontColorSliderBarR
  207.         self.FontColorSliderBarR.cursor.OnMouseRightButtonDown = self.ResetFontColorSliderBarR
  208.         self.FontColorSliderBarR.SetEvent(ui.__mem_func__(self.OnChangeFontColorR))
  209.         self.FontColorSliderBarR.Show()
  210.  
  211.         self.FontGLabel = ui.TextLine()
  212.         self.FontGLabel.SetParent(self)
  213.         self.FontGLabel.SetText("Font Green: 0")
  214.         self.FontGLabel.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 2 * 20)
  215.         self.FontGLabel.Show()
  216.  
  217.         self.FontColorSliderBarG = ui.SliderBar()
  218.         self.FontColorSliderBarG.SetParent(self)
  219.         self.FontColorSliderBarG.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 3 * 20)
  220.         self.FontColorSliderBarG.SetSliderPos(0.)
  221.         self.FontColorSliderBarG.backGroundImage.OnMouseLeftButtonDown = self.SeekFontColorSliderBarG
  222.         self.FontColorSliderBarG.cursor.OnMouseRightButtonDown = self.ResetFontColorSliderBarG
  223.         self.FontColorSliderBarG.SetEvent(ui.__mem_func__(self.OnChangeFontColorG))
  224.         self.FontColorSliderBarG.Show()
  225.  
  226.         self.FontBLabel = ui.TextLine()
  227.         self.FontBLabel.SetParent(self)
  228.         self.FontBLabel.SetText("Font Blue: 0")
  229.         self.FontBLabel.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 4 + 4 * 20)
  230.         self.FontBLabel.Show()
  231.  
  232.         self.FontColorSliderBarB = ui.SliderBar()
  233.         self.FontColorSliderBarB.SetParent(self)
  234.         self.FontColorSliderBarB.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 5 * 20)
  235.         self.FontColorSliderBarB.SetSliderPos(0.)
  236.         self.FontColorSliderBarB.backGroundImage.OnMouseLeftButtonDown = self.SeekFontColorSliderBarB
  237.         self.FontColorSliderBarB.cursor.OnMouseRightButtonDown = self.ResetFontColorSliderBarB
  238.         self.FontColorSliderBarB.SetEvent(ui.__mem_func__(self.OnChangeFontColorB))
  239.         self.FontColorSliderBarB.Show()
  240.  
  241.         self.OutLineRLabel = ui.TextLine()
  242.         self.OutLineRLabel.SetParent(self)
  243.         self.OutLineRLabel.SetText("OutLine Red: 0")
  244.         self.OutLineRLabel.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 6 * 20)
  245.         self.OutLineRLabel.Show()
  246.  
  247.         self.OutLineColorSliderBarR = ui.SliderBar()
  248.         self.OutLineColorSliderBarR.SetParent(self)
  249.         self.OutLineColorSliderBarR.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 7 * 20)
  250.         self.OutLineColorSliderBarR.SetSliderPos(0.)
  251.         self.OutLineColorSliderBarR.backGroundImage.OnMouseLeftButtonDown = self.SeekOutLineColorSliderBarR
  252.         self.OutLineColorSliderBarR.cursor.OnMouseRightButtonDown = self.ResetOutLineColorSliderBarR
  253.         self.OutLineColorSliderBarR.SetEvent(ui.__mem_func__(self.OnChangeOutLineColorR))
  254.         self.OutLineColorSliderBarR.Show()
  255.  
  256.         self.OutLineGLabel = ui.TextLine()
  257.         self.OutLineGLabel.SetParent(self)
  258.         self.OutLineGLabel.SetText("OutLine Green: 0")
  259.         self.OutLineGLabel.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 8 * 20)
  260.         self.OutLineGLabel.Show()
  261.  
  262.         self.OutLineColorSliderBarG = ui.SliderBar()
  263.         self.OutLineColorSliderBarG.SetParent(self)
  264.         self.OutLineColorSliderBarG.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 9 * 20)
  265.         self.OutLineColorSliderBarG.SetSliderPos(0.)
  266.         self.OutLineColorSliderBarG.backGroundImage.OnMouseLeftButtonDown = self.SeekOutLineColorSliderBarB
  267.         self.OutLineColorSliderBarG.cursor.OnMouseRightButtonDown = self.ResetOutLineColorSliderBarG
  268.         self.OutLineColorSliderBarG.SetEvent(ui.__mem_func__(self.OnChangeOutLineColorG))
  269.         self.OutLineColorSliderBarG.Show()
  270.  
  271.         self.OutLineBLabel = ui.TextLine()
  272.         self.OutLineBLabel.SetParent(self)
  273.         self.OutLineBLabel.SetText("OutLine Blue: 0")
  274.         self.OutLineBLabel.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 4 + 10 * 20)
  275.         self.OutLineBLabel.Show()
  276.  
  277.         self.OutLineColorSliderBarB = ui.SliderBar()
  278.         self.OutLineColorSliderBarB.SetParent(self)
  279.         self.OutLineColorSliderBarB.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 11 * 20)
  280.         self.OutLineColorSliderBarB.SetSliderPos(0.)
  281.         self.OutLineColorSliderBarB.backGroundImage.OnMouseLeftButtonDown = self.SeekOutLineColorSliderBarB
  282.         self.OutLineColorSliderBarB.cursor.OnMouseRightButtonDown = self.ResetOutLineColorSliderBarB
  283.         self.OutLineColorSliderBarB.SetEvent(ui.__mem_func__(self.OnChangeOutLineColorB))
  284.         self.OutLineColorSliderBarB.Show()
  285.  
  286.         self.OutLineALabel = ui.TextLine()
  287.         self.OutLineALabel.SetParent(self)
  288.         self.OutLineALabel.SetText("OutLine Alpha: 1.00")
  289.         self.OutLineALabel.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 4 + 12 * 20)
  290.         self.OutLineALabel.Show()
  291.  
  292.         self.OutLineColorSliderBarA = ui.SliderBar()
  293.         self.OutLineColorSliderBarA.SetParent(self)
  294.         self.OutLineColorSliderBarA.SetPosition(16 + self.ModelView.GetWidth() + 10, 29 + 3 + 13 * 20)
  295.         self.OutLineColorSliderBarA.SetSliderPos(1.)
  296.         self.OutLineColorSliderBarA.backGroundImage.OnMouseLeftButtonDown = self.SeekOutLineColorSliderBarA
  297.         self.OutLineColorSliderBarA.cursor.OnMouseRightButtonDown = self.ResetOutLineColorSliderBarA
  298.         self.OutLineColorSliderBarA.SetEvent(ui.__mem_func__(self.OnChangeOutLineColorA))
  299.         self.OutLineColorSliderBarA.Show()
  300.  
  301.     def Open(self):
  302.         ui.BoardWithTitleBar.Show(self)
  303.  
  304.     def Close(self):
  305.         # wndMgr.SetOutlineFlag(0)
  306.         self.Hide()
  307.         return 1
  308.  
  309.     def OnPressEscapeKey(self):
  310.         self.Close()
  311.         return 1
  312.  
  313.     def rgb(self, ratio, isoutline = False):
  314.         normalized = int(ratio * 256 * 6);
  315.         x = normalized % 256;
  316.  
  317.         red = grn = blu = alp = 0
  318.         state = normalized / 256
  319.         if state == 0: # red
  320.             red = 255
  321.             grn = x
  322.             blu = 0
  323.             alp = x if isoutline else 255
  324.         elif state == 1:
  325.             red = 255 - x
  326.             grn = 255
  327.             blu = 0
  328.             alp = 255 - x if isoutline else 255
  329.         elif state == 2:
  330.             red = 0
  331.             grn = 255
  332.             blu = x
  333.             alp = x if isoutline else 255
  334.         elif state == 3:
  335.             red = 0
  336.             grn = 255 - x
  337.             blu = 255
  338.             alp = 255 - x if isoutline else 255
  339.         elif state == 4:
  340.             red = x
  341.             grn = 0
  342.             blu = 255
  343.             alp = x if isoutline else 255
  344.         elif state == 5:
  345.             red = 255
  346.             grn = 0
  347.             blu = 255 - x
  348.             alp = 255 - x if isoutline else 255
  349.  
  350.         if isoutline:
  351.             self.OutLineColorSliderBarR.SetSliderPos(red/255.); self.OnChangeOutLineColorR()
  352.             self.OutLineColorSliderBarG.SetSliderPos(grn/255.); self.OnChangeOutLineColorG()
  353.             self.OutLineColorSliderBarB.SetSliderPos(blu/255.); self.OnChangeOutLineColorB()
  354.             self.OutLineColorSliderBarA.SetSliderPos(alp/255.); self.OnChangeOutLineColorA()
  355.         else:
  356.             self.FontColorSliderBarR.SetSliderPos(red/255.); self.OnChangeFontColorR()
  357.             self.FontColorSliderBarG.SetSliderPos(grn/255.); self.OnChangeFontColorG()
  358.             self.FontColorSliderBarB.SetSliderPos(blu/255.); self.OnChangeFontColorB()
  359.  
  360.         #return red + (grn << 8) + (blu << 16) + (alp << 24);
  361.  
  362.     def OnUpdate(self):
  363.         if self.rainbauwFont:
  364.             self.rgb(self.rainbauwFontSeed / 60, False)
  365.  
  366.             if self.rainbauwFontSeed < 60:
  367.                 self.rainbauwFontSeed += self.rainbauwSpeed
  368.             else:
  369.                 self.rainbauwFontSeed = 0.
  370.  
  371.         if self.rainbauwOutLine:
  372.             self.rgb(self.rainbauwOutLineSeed / 60, True)
  373.  
  374.             if self.rainbauwOutLineSeed < 60:
  375.                 self.rainbauwOutLineSeed += self.rainbauwSpeed
  376.             else:
  377.                 self.rainbauwOutLineSeed = 0.
  378.  
  379. a=TextLineColorTest()
  380. try:
  381.     a.Open()
  382. except:
  383.     a.Show()
  384.  
Add Comment
Please, Sign In to add comment