locked
color palette RRS feed

  • Question

  • Is there an way of open and use a color palette in small basic?, I have tried  LDDialogs.color() but that is to unstable, it freezes and not giving any color output.
    Tuesday, June 2, 2020 5:44 PM

Answers

  • Smurfnastic,

    I uploaded a new version of your program (Bkc126-1). With this change you can make the background whatever color you want.

    In this program remember that the added "Clear" routine colors the graphicswindow by filling a rectangle that is the size of the window with the current color of the backgroundwindow. So, "Clear" effectively hides everything. In the program I have commented out most of the graphicswindow.backgroundcolor commands and am just letting the "Clear" function do it's job.

    Also, if you have buttons showing or not showing on the screen you can use Controls.HideControl or Controls.Show Control functions to set the screen to what you want.

    I think the program now does what you want it to do. Good luck with your programming!


    JR

    Thursday, June 4, 2020 6:44 PM
    Answerer

All replies

  • Smurfnastic, Here's a link to an article that explains colors and it gives some different programs that you can use for colors in small basic. https://social.technet.microsoft.com/wiki/contents/articles/23227.small-basic-color.aspx Also, I have not had any issues with LDDialogs.colour(). So, if you could provide your program that we could look at maybe we could discover what is occuring.

    JR

    Tuesday, June 2, 2020 6:11 PM
    Answerer
  • I'll basically just added a buttton:

     Elseif lastbutton = selColor Then
       Bgc = LDDialogs.Colour() 

    Is there more i need to do?

    controls.ButtonClicked = OnButton ' Kontrolerar knapptryckningarna.
    curDir = Program.Directory 'läser av plats för programet
    isMute = Controls.GetButtonCaption(Mutebutton) 'läser av mute knappen om den är mutad eller omutad och sparara värdet.
    animate = "FALSE" ' Styr animationerna på/av
    dif = lastbutton ' Kontrollerar musikvalen ocxh spara dessa värden.
    delay = 35 'Styr deleyen på animnation i ms
    sid = 30 ' Fönsterstorlek

    'Nedankod raderas om textbox i settingmenu tas bort!
    'Controls.TextTyped = textTyped
    'Sub textTyped
    'lastTypedBox = Controls.LastTypedTextBox
    'If lastTypedBox = txtTid Then
    'tid = Controls.GetTextBoxText(txtTid)
    'EndIf
    'EndSub

    Sub Setup
      int=math.Floor(sid/10) 'int = lenght of interval
      GraphicsWindow.Height = 12*(sid+int)+int
      GraphicsWindow.Width = 22*(sid+int)+int
      ' tid1 = tid
    EndSub

    Sub OnButton  'Vad som händer när man trycker på en knappen
      lastbutton = Controls.LastClickedButton
     
      If lastbutton = Exitbutton Then
        Program.End()
        
      ElseIf lastbutton = Startbutton Then 'Slumpar fram låt att spela
        num = Math.GetRandomNumber(4)
        If num = 1 Then
          dif = curDir+"\dif.mp3"
        ElseIf num = 2 Then
          dif = curDir+"\gul.mp3"
        ElseIf num = 3 Then
          dif = curDir+"\Vinnare.mp3"
        ElseIf num = 4 Then
          dif = curDir+"\smguld2019.mp3"
        EndIf
        
        GraphicsWindow.Clear()
        animate = "TRUE"
        Controls.SetButtonCaption(Mutebutton, "Muta")
        createPlayMenu()       
        
        'Rutiner för Knappar
      ElseIf lastbutton = Mutebutton And isMute = "Muta" Then
        Sound.Pause(dif)
        Controls.SetButtonCaption(Mutebutton, "Omuta")
        lastButton = ""
        
      Elseif lastbutton = Mutebutton And isMute = "Omuta" then
        Sound.play(dif)
        Controls.SetButtonCaption(Mutebutton, "Muta")
        lastButton = Startbutton
        
      Elseif lastbutton = musicBut Then
        createMusicMenu()
        
      Elseif lastbutton = menubutton Then
        animate = "FALSE"
        createMainMenu()
        
      elseif lastbutton = settingMenu Then
        createSettingsMenu()
        
      Elseif lastbutton = Aboutbutton Then
        createAboutMenu()  
        
      Elseif lastbutton = selColor Then
       Bgc = LDDialogs.Colour()  
        
      ElseIf lastbutton = dif1 Then
        dif = curDir+"\dif.mp3"
        animate = "TRUE"
        Controls.SetButtonCaption(Mutebutton, "Muta")
        createPlayMenu()
        
      ElseIf lastbutton = dif2 Then
        dif = curDir+"\gul.mp3"
        animate = "TRUE"
        Controls.SetButtonCaption(Mutebutton, "Muta")
        createPlayMenu()
        
      ElseIf lastbutton = dif3 Then
        dif = curDir+"\Vinnare.mp3"
        animate = "TRUE"
        Controls.SetButtonCaption(Mutebutton, "Muta")
        createPlayMenu()
        
      ElseIf lastbutton = dif4 Then
        dif = curDir+"\smguld2019.mp3"
        animate = "TRUE"
        Controls.SetButtonCaption(Mutebutton, "Muta")
        createPlayMenu()  
      EndIf
    EndSub

    Sub createMainMenu 'Startförnstret
      Sound.Stop(dif)
      GraphicsWindow.Clear()
      GraphicsWindow.BrushColor = "black"
      GraphicsWindow.BackgroundColor = "Bgc"
      GraphicsWindow.Title = "Djurgården For Ever!"
      Startbutton = Controls.AddButton("Starta" 40, 50)
      Exitbutton = Controls.AddButton("Avsluta" 230, 50)
      musicBut = Controls.AddButton("Välj Musik" 120, 50)
      settingMenu = Controls.AddButton("Inställningar" 113, 10)
      Aboutbutton = Controls.AddButton("Om" 135,100)
      GraphicsWindow.BrushColor = Bgc
      GraphicsWindow.FillRectangle(40, 80, 245, 60)
    EndSub

    Sub createMusicMenu 'Musikväljarmenyn
      GraphicsWindow.Clear()
      GraphicsWindow.BrushColor = "black"
      GraphicsWindow.BackgroundColor = "Bgc"
      GraphicsWindow.Title = "Musikbiblioteket"
      dif1 = Controls.AddButton("Sjung För Gamla Djurgården" 40, 50)
      dif2 = Controls.AddButton("Gul Röd Blå" 40, 80)
      dif3 = Controls.AddButton("Vi Är Vinnare" 40, 110)
      dif4 = Controls.AddButton("Smguld 2019" 40, 140)
    EndSub

    Sub createSettingsMenu 'Inställningsfönster
      GraphicsWindow.Clear()
      GraphicsWindow.BrushColor = "black"
      GraphicsWindow.BackgroundColor = "White"
      GraphicsWindow.Title = "Inställningar"
      GraphicsWindow.DrawText(20,50 "Välj önskad bakgrundsfärg")
      menubutton = Controls.AddButton("Vidar Till Huvudmenyn" 100, 10)
      selColor = Controls.AddButton("Bakgrundsfärg" 100, 100)
     
      'Ska eventuellt adderas till kod eller raders?
      'Beror på om jag får ordning på tidsstyrningen.
      'txtTid = Controls.AddTextBox(300,100)
      'Controls.SetTextBoxText(txtTid, tid1)
      'Controls.SetSize(txtTid, 30, 23)            
    EndSub

    Sub createAboutMenu 'Informationsfösnter
      GraphicsWindow.Clear()
      GraphicsWindow.BackgroundColor = "Bgc"
      GraphicsWindow.Title = "Inställningar"
      GraphicsWindow.BrushColor = "Gold"
      GraphicsWindow.DrawText(20,20 "")
      GraphicsWindow.DrawText(20,40 "")
      GraphicsWindow.DrawText(20,60 "")
      GraphicsWindow.DrawText(20,80, "Source of code")  
     EndSub

    Sub createPlayMenu 'Spelfönster
      Sound.play(dif)
      GraphicsWindow.BrushColor = "black"
      GraphicsWindow.BackgroundColor = "Bgc"
      GraphicsWindow.Title = "Djurgården For Ever!"
      GraphicsWindow.BrushColor = "YELLOW"
      GraphicsWindow.DrawText(119,56"DJU")
      GraphicsWindow.BrushColor = "RED"
      GraphicsWindow.DrawText(143,56"RGÅR")
      GraphicsWindow.BrushColor = "BLUE"
      GraphicsWindow.DrawText(177,56"DEN")
      GraphicsWindow.BrushColor = ""
      Exitbutton = Controls.AddButton("Avsluta" 230, 50)
      Mutebutton = Controls.AddButton("Muta" 40, 50)
      Menubutton = Controls.AddButton("Tillbaka till menyn" 100, 10)
     
      While animate = "TRUE"
        isMute = Controls.GetButtonCaption(Mutebutton)
        If animate = "TRUE" Then
          GraphicsWindow.BrushColor = "Blue"
          GraphicsWindow.FillRectangle(40, 80, 245, 60)
          Program.Delay(delay)
          GraphicsWindow.BrushColor = "Red"
          GraphicsWindow.FillRectangle(40, 80, 245, 60)
          Program.Delay(delay)
          GraphicsWindow.BrushColor = "Yellow"
          GraphicsWindow.FillRectangle(40, 80, 245, 60)
          Program.Delay(delay)
        EndIf
      EndWhile
    EndSub

    Setup()
    createSettingsMenu()  



    Tuesday, June 2, 2020 7:25 PM
  • u mustn't call any ld dialog from event sub,it leads to unresponsive situations.

    instead run a main infinite loop and call lddialogs from there

    example:

    graphicswindow.mousedown=mmm
    
    Sub mmm
      cols="true"
    EndSub
    
    While 1=1 'main loop'
      
      if cols then
        cols="false"
        cc=lddialogs.Colour()
        graphicswindow.backgroundcolor=cc
      EndIf
      
    EndWhile



    • Edited by Tryhest Tuesday, June 2, 2020 8:03 PM
    • Proposed as answer by Nonki Takahashi Wednesday, June 17, 2020 1:04 PM
    Tuesday, June 2, 2020 7:59 PM
  • OK, i done it like this, but now i can click anywhere and the the palette comes up, i tried  put the while loop in diffrent places of the code, but then the starting page just went blank on start untill i pushed a mousebutton. any tips?.

    graphicswindow.mousedown=mmm

    'ADDED NEW SUB

    Sub mmm
      cols="true"
    EndSub

    'BUTTON NEW CODE

    Elseif lastbutton = selColor Then
        mmm()

    'ADDED CODE  TO SUB

    Sub createSettingsMenu 'Inställningsfönster
      GraphicsWindow.Clear()
      GraphicsWindow.BrushColor = "black"
      GraphicsWindow.BackgroundColor = Bgc
      GraphicsWindow.Title = "Inställningar"
      GraphicsWindow.DrawText(20,50 "Välj önskad bakgrundsfärg")
      menubutton = Controls.AddButton("Vidar Till Huvudmenyn" 100, 10)
      selColor = Controls.AddButton("Bakgrundsfärg" 100, 100)

    While 1=1 'main loop'
        
        if cols then
          cols="false"
          Bgc=lddialogs.Colour()
          graphicswindow.backgroundcolor=Bgc
        EndIf
      EndWhile
    EndSub

    Wednesday, June 3, 2020 8:17 AM
  • Smurfnastic,

    I took your program and rearranged it. (BKC126). You can import it and have a look. It's definitely not perfect, but I wanted you to review it and maybe it will help. I'll keep working on it as I have time, but here is some of the things that I did and why.

    1. I added a "Clear" subroutine rather than using the graphicswindow.clear function. Here's the title that details the reason to not use this function. Just do a search for it and it should come up.

    i need help with graphics window (small basic)


    The last part of the article was written by LitDev and explains what happens really well. I

    2. One of the things that was happening is because of the "Clear" function is each time you went into each of the subroutines you were generating new buttons. So, I moved all of the buttons to the Initialization routine. Then you can use Controls.HideControl(XXX) and Controls.ShowControl(XXX) functions as needed.


    3. I created a main routine that program will be running in.

    4. Your only using one event handler. It shows at the end of Initialization.

    5. All of the Subroutines are now grouped together.

    6. I converted most of the wording from Swedish to English. I was having a hard time figuring out the wording.

    7. I did incorporate 'Tryhest' suggestion and that seems to work well.

    Let me know if you have any questions. There are things that aren't working the way that I am sure that you want. I think they are items that you can do better than me because you know how you want it to work.

    JR

    Wednesday, June 3, 2020 9:45 PM
    Answerer
  • I do appreciate the help, but i can still not change the backgroundcolor and some other stuff, but something new for me to work with. it's like Bgc isnt set to the color i choose. but big thank you for the help, and please let me know if you do some more work on it! :)

    Smurfnastic

    Thursday, June 4, 2020 4:29 PM
  • Smurfnastic,

    I uploaded a new version of your program (Bkc126-1). With this change you can make the background whatever color you want.

    In this program remember that the added "Clear" routine colors the graphicswindow by filling a rectangle that is the size of the window with the current color of the backgroundwindow. So, "Clear" effectively hides everything. In the program I have commented out most of the graphicswindow.backgroundcolor commands and am just letting the "Clear" function do it's job.

    Also, if you have buttons showing or not showing on the screen you can use Controls.HideControl or Controls.Show Control functions to set the screen to what you want.

    I think the program now does what you want it to do. Good luck with your programming!


    JR

    Thursday, June 4, 2020 6:44 PM
    Answerer