It is currently Sat Dec 14, 2019 9:33 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Better ColorRequester()
PostPosted: Mon May 08, 2017 8:58 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 842
Location: Cuernavaca, Mexico
The PB ColorRequester() only opens the basic color screen, and does not remember the users choices.

Hopefully this will be a bit better...

Once compiled, use it in your programs with RunProgram() :)

Code:
;==================================================================
;
; Author:     blueb   
; Date:       May 8, 2017
; Explain:    Create a new ColorRequester that saves User Colors (between calls)
;         
; Saved as:  FullColorRequester.pb
;=========================================================

EnableExplicit
; --------------------------------------------------------------------------
; Goal - write a 'Unique' preference file in the temporary directory that
; stays in the temporary directory even when user switches to other programs.
; It will keep the special colors the user last adjusted.
; --------------------------------------------------------------------------
Declare InitPrefs()
Declare ExitPrefs()

Structure COLORREF
  RGB.l[16]
EndStructure

; Structure CHOOSECOLOR ; see PB toolbox
;      lStructSize.l
;      hwndOwner.i
;      hInstance.i
;      rgbResult.l
;      *lpCustColors
;      Flags.l
;      lCustData.i
;      *lpfnHook
;      *lpTemplateName
; EndStructure

Define CHOOSECOLOR.CHOOSECOLOR

Define COLORREF.COLORREF
Global prefOpen.i, SelectedClipResult.s

; needed for preferences file.
Global.i  COLORREF1, COLORREF2, COLORREF3, COLORREF4, COLORREF5, COLORREF6, COLORREF7, COLORREF8, COLORREF9
Global.i  COLORREF10, COLORREF11, COLORREF12, COLORREF13, COLORREF14, COLORREF15, COLORREF16

InitPrefs()

; place saved colors inside requester()
COLORREF\RGB[0] = COLORREF1
COLORREF\RGB[1] = COLORREF2
COLORREF\RGB[2] = COLORREF3
COLORREF\RGB[3] = COLORREF4
COLORREF\RGB[4] = COLORREF5
COLORREF\RGB[5] = COLORREF6
COLORREF\RGB[6] = COLORREF7
COLORREF\RGB[7] = COLORREF8
COLORREF\RGB[8] = COLORREF9
COLORREF\RGB[9] = COLORREF10
COLORREF\RGB[10] = COLORREF11
COLORREF\RGB[11] = COLORREF12
COLORREF\RGB[12] = COLORREF13
COLORREF\RGB[13] = COLORREF14
COLORREF\RGB[14] = COLORREF15
COLORREF\RGB[15] = COLORREF16

CHOOSECOLOR\LStructSize = SizeOf(CHOOSECOLOR)
CHOOSECOLOR\hwndOwner = 0;WindowID(#Window)
CHOOSECOLOR\rgbResult = 0 ; nothing selected
CHOOSECOLOR\lpCustColors = COLORREF
CHOOSECOLOR\flags = #CC_ANYCOLOR | #CC_FULLOPEN | #CC_RGBINIT

Procedure InitPrefs()
; ===================================
; Color Preference file - Storage information
;

prefOpen = OpenPreferences(GetTemporaryDirectory() + "GetUserColors.prefs") ; test and create if necessary

If prefOpen = 0 ; Does not exist... so create it.
     
   ; Default values - if "GetUserColors.prefs" is erased
 
          prefOpen = CreatePreferences(GetTemporaryDirectory() + "GetUserColors.prefs")
         
          WritePreferenceInteger("COLORREF1",  COLORREF1)  ; the first color
          WritePreferenceInteger("COLORREF2",  COLORREF2) 
          WritePreferenceInteger("COLORREF3",  COLORREF3) 
          WritePreferenceInteger("COLORREF4",  COLORREF4) 
          WritePreferenceInteger("COLORREF5",  COLORREF5) 
          WritePreferenceInteger("COLORREF6",  COLORREF6) 
          WritePreferenceInteger("COLORREF7",  COLORREF7) 
          WritePreferenceInteger("COLORREF8",  COLORREF8) 
          WritePreferenceInteger("COLORREF9",  COLORREF9) 
          WritePreferenceInteger("COLORREF10",  COLORREF10) 
          WritePreferenceInteger("COLORREF11",  COLORREF11) 
          WritePreferenceInteger("COLORREF12",  COLORREF12) 
          WritePreferenceInteger("COLORREF13",  COLORREF13) 
          WritePreferenceInteger("COLORREF14",  COLORREF14) 
          WritePreferenceInteger("COLORREF15",  COLORREF15) 
          WritePreferenceInteger("COLORREF16",  COLORREF16) 
    ClosePreferences()
   
Else ; it exists
          ; Retrieve the GetUserColors.prefs information
          COLORREF1 = ReadPreferenceInteger("COLORREF1", COLORREF1)
          COLORREF2 = ReadPreferenceInteger("COLORREF2", COLORREF2)
          COLORREF3 = ReadPreferenceInteger("COLORREF3", COLORREF3)
          COLORREF4 = ReadPreferenceInteger("COLORREF4", COLORREF4)
          COLORREF5 = ReadPreferenceInteger("COLORREF5", COLORREF5)
          COLORREF6 = ReadPreferenceInteger("COLORREF6", COLORREF6)
          COLORREF7 = ReadPreferenceInteger("COLORREF7", COLORREF7)
          COLORREF8 = ReadPreferenceInteger("COLORREF8", COLORREF8)
          COLORREF9 = ReadPreferenceInteger("COLORREF9", COLORREF9)     
          COLORREF10 = ReadPreferenceInteger("COLORREF10", COLORREF10)
          COLORREF11 = ReadPreferenceInteger("COLORREF11", COLORREF11)
          COLORREF12 = ReadPreferenceInteger("COLORREF12", COLORREF12)
          COLORREF13 = ReadPreferenceInteger("COLORREF13", COLORREF13)
          COLORREF14 = ReadPreferenceInteger("COLORREF14", COLORREF14)
          COLORREF15 = ReadPreferenceInteger("COLORREF15", COLORREF15)
          COLORREF16 = ReadPreferenceInteger("COLORREF16", COLORREF16)
  ClosePreferences()
   Debug COLORREF1
EndIf
 EndProcedure
 
Procedure ExitPrefs()
       
     PrefOpen = OpenPreferences(GetTemporaryDirectory() + "GetUserColors.prefs")
   
  If prefOpen
          WritePreferenceInteger("COLORREF1",  COLORREF1)  ; the first color
          WritePreferenceInteger("COLORREF2",  COLORREF2) 
          WritePreferenceInteger("COLORREF3",  COLORREF3) 
          WritePreferenceInteger("COLORREF4",  COLORREF4) 
          WritePreferenceInteger("COLORREF5",  COLORREF5) 
          WritePreferenceInteger("COLORREF6",  COLORREF6) 
          WritePreferenceInteger("COLORREF7",  COLORREF7) 
          WritePreferenceInteger("COLORREF8",  COLORREF8) 
          WritePreferenceInteger("COLORREF9",  COLORREF9) 
          WritePreferenceInteger("COLORREF10",  COLORREF10) 
          WritePreferenceInteger("COLORREF11",  COLORREF11) 
          WritePreferenceInteger("COLORREF12",  COLORREF12) 
          WritePreferenceInteger("COLORREF13",  COLORREF13) 
          WritePreferenceInteger("COLORREF14",  COLORREF14) 
          WritePreferenceInteger("COLORREF15",  COLORREF15) 
          WritePreferenceInteger("COLORREF16",  COLORREF16) 
       
   EndIf
   If prefOpen
          ClosePreferences()
   EndIf     
EndProcedure

;==================================================================
;------- Place CHOOSECOLOR Info into requester()
;==================================================================

If ChooseColor_(@CHOOSECOLOR)
     COLORREF1 =COLORREF\RGB[0]
     COLORREF2 =COLORREF\RGB[1]
     COLORREF3 =COLORREF\RGB[2]
     COLORREF4 =COLORREF\RGB[3]
     COLORREF5 =COLORREF\RGB[4]
     COLORREF6 =COLORREF\RGB[5]
     COLORREF7 =COLORREF\RGB[6]
     COLORREF8 =COLORREF\RGB[7]
     COLORREF9 =COLORREF\RGB[8]
     COLORREF10 =COLORREF\RGB[9]
     COLORREF11 =COLORREF\RGB[10]
     COLORREF12 =COLORREF\RGB[11]
     COLORREF13 =COLORREF\RGB[12]
     COLORREF14 =COLORREF\RGB[13]
     COLORREF15 =COLORREF\RGB[14]
     COLORREF16 =COLORREF\RGB[15]
     
  SelectedClipResult.s = Str(CHOOSECOLOR\rgbResult)
  SetClipboardText(SelectedClipResult.s)
 
  Debug "Color Selected: " + CHOOSECOLOR\rgbResult
 
Else
  Debug "No color was selected."
EndIf

ExitPrefs() ; save info

End


_________________
- It was too lonely at the top.

Current Machine: Win 10 Pro 64-bit, Dual Xeon E5-2670, 64 gigs ram, Geforce GTX 1660 Ti w/6 gigs ram


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Tue May 09, 2017 12:57 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5890
Location: Wales, UK
That is a thing of beauty! Thanks for sharing blueb.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Tue May 09, 2017 2:25 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 842
Location: Cuernavaca, Mexico
IdeasVacuum wrote:
That is a thing of beauty! Thanks for sharing blueb.


Glad it can be of use. :D

I got onto the idea when I was playing with SweetyVD and couldn't save colors.

I took a look to see what others had done and simply incorporated some of their ideas.

I think PureBasic should make something like this, instead of the regular requester.

_________________
- It was too lonely at the top.

Current Machine: Win 10 Pro 64-bit, Dual Xeon E5-2670, 64 gigs ram, Geforce GTX 1660 Ti w/6 gigs ram


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Tue May 09, 2017 8:02 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1109
Location: Berlin (Germany)
Thanks for sharing. Image

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Tue May 09, 2017 8:18 am 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
Nice

_________________
http://www.nachtoptik.de


Last edited by walbus on Thu May 11, 2017 12:40 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Tue May 09, 2017 2:43 pm 
Offline
User
User
User avatar

Joined: Sun Jan 08, 2017 10:27 pm
Posts: 95
Location: France
Very good and Useful, thanks for sharing :)

Without changing anything and to fully integrate it into SweetyVD, I changed the RunProgram() for a procedure
Code:
;==================================================================
;
; Author:     blueb
; Date:       May 8, 2017
; Explain:    Create a new ColorRequester that saves User Colors (between calls)
; Forum:      http://www.purebasic.fr/english/viewtopic.php?f=12&t=68450
; Saved as:   FullColorRequester.pb
;=========================================================

EnableExplicit
; --------------------------------------------------------------------------
; Goal - write a 'Unique' preference file in the temporary directory that
; stays in the temporary directory even when user switches to other programs.
; It will keep the special colors the user last adjusted.
; --------------------------------------------------------------------------
Declare InitColorPrefs()
Declare ExitColorPrefs()
Declare FullColorRequester()

Structure COLORREF
  RGB.l[16]
EndStructure

; Structure CHOOSECOLOR ; see PB toolbox
;      lStructSize.l
;      hwndOwner.i
;      hInstance.i
;      rgbResult.l
;      *lpCustColors
;      Flags.l
;      lCustData.i
;      *lpfnHook
;      *lpTemplateName
; EndStructure

; Needed for preferences file.
Global.i  COLORREF1, COLORREF2, COLORREF3, COLORREF4, COLORREF5, COLORREF6, COLORREF7, COLORREF8, COLORREF9
Global.i  COLORREF10, COLORREF11, COLORREF12, COLORREF13, COLORREF14, COLORREF15, COLORREF16

Procedure InitColorPrefs()   ;Color Preference file - Storage information
  If OpenPreferences(GetTemporaryDirectory() + "GetUserColors.prefs") = 0 ; Does not exist, "GetUserColors.prefs" is erased. So create it with Default values
    CreatePreferences(GetTemporaryDirectory() + "GetUserColors.prefs")
    WritePreferenceInteger("COLORREF1", COLORREF1)   ;The first color
    WritePreferenceInteger("COLORREF2", COLORREF2)
    WritePreferenceInteger("COLORREF3", COLORREF3)
    WritePreferenceInteger("COLORREF4", COLORREF4)
    WritePreferenceInteger("COLORREF5", COLORREF5)
    WritePreferenceInteger("COLORREF6", COLORREF6)
    WritePreferenceInteger("COLORREF7", COLORREF7)
    WritePreferenceInteger("COLORREF8", COLORREF8)
    WritePreferenceInteger("COLORREF9", COLORREF9)
    WritePreferenceInteger("COLORREF10", COLORREF10)
    WritePreferenceInteger("COLORREF11", COLORREF11)
    WritePreferenceInteger("COLORREF12", COLORREF12)
    WritePreferenceInteger("COLORREF13", COLORREF13)
    WritePreferenceInteger("COLORREF14", COLORREF14)
    WritePreferenceInteger("COLORREF15", COLORREF15)
    WritePreferenceInteger("COLORREF16", COLORREF16)
    ClosePreferences()
  Else   ;It exists, retrieve the GetUserColors.prefs information
    COLORREF1 = ReadPreferenceInteger("COLORREF1", COLORREF1)   ;The first user color
    COLORREF2 = ReadPreferenceInteger("COLORREF2", COLORREF2)
    COLORREF3 = ReadPreferenceInteger("COLORREF3", COLORREF3)
    COLORREF4 = ReadPreferenceInteger("COLORREF4", COLORREF4)
    COLORREF5 = ReadPreferenceInteger("COLORREF5", COLORREF5)
    COLORREF6 = ReadPreferenceInteger("COLORREF6", COLORREF6)
    COLORREF7 = ReadPreferenceInteger("COLORREF7", COLORREF7)
    COLORREF8 = ReadPreferenceInteger("COLORREF8", COLORREF8)
    COLORREF9 = ReadPreferenceInteger("COLORREF9", COLORREF9)
    COLORREF10 = ReadPreferenceInteger("COLORREF10", COLORREF10)
    COLORREF11 = ReadPreferenceInteger("COLORREF11", COLORREF11)
    COLORREF12 = ReadPreferenceInteger("COLORREF12", COLORREF12)
    COLORREF13 = ReadPreferenceInteger("COLORREF13", COLORREF13)
    COLORREF14 = ReadPreferenceInteger("COLORREF14", COLORREF14)
    COLORREF15 = ReadPreferenceInteger("COLORREF15", COLORREF15)
    COLORREF16 = ReadPreferenceInteger("COLORREF16", COLORREF16)
    ClosePreferences()
  EndIf
EndProcedure

Procedure ExitColorPrefs()
  If OpenPreferences(GetTemporaryDirectory() + "GetUserColors.prefs")
    WritePreferenceInteger("COLORREF1", COLORREF1)   ;The first color
    WritePreferenceInteger("COLORREF2", COLORREF2)
    WritePreferenceInteger("COLORREF3", COLORREF3)
    WritePreferenceInteger("COLORREF4", COLORREF4)
    WritePreferenceInteger("COLORREF5", COLORREF5)
    WritePreferenceInteger("COLORREF6", COLORREF6)
    WritePreferenceInteger("COLORREF7", COLORREF7)
    WritePreferenceInteger("COLORREF8", COLORREF8)
    WritePreferenceInteger("COLORREF9", COLORREF9)
    WritePreferenceInteger("COLORREF10", COLORREF10)
    WritePreferenceInteger("COLORREF11", COLORREF11)
    WritePreferenceInteger("COLORREF12", COLORREF12)
    WritePreferenceInteger("COLORREF13", COLORREF13)
    WritePreferenceInteger("COLORREF14", COLORREF14)
    WritePreferenceInteger("COLORREF15", COLORREF15)
    WritePreferenceInteger("COLORREF16", COLORREF16)
    ClosePreferences()
   EndIf
EndProcedure

Procedure FullColorRequester()   ;Place CHOOSECOLOR Info into requester()
  Protected CHOOSECOLOR.CHOOSECOLOR, COLORREF.COLORREF
 
  InitColorPrefs()
  ;Place saved colors inside requester()
  COLORREF\RGB[0] = COLORREF1
  COLORREF\RGB[1] = COLORREF2
  COLORREF\RGB[2] = COLORREF3
  COLORREF\RGB[3] = COLORREF4
  COLORREF\RGB[4] = COLORREF5
  COLORREF\RGB[5] = COLORREF6
  COLORREF\RGB[6] = COLORREF7
  COLORREF\RGB[7] = COLORREF8
  COLORREF\RGB[8] = COLORREF9
  COLORREF\RGB[9] = COLORREF10
  COLORREF\RGB[10] = COLORREF11
  COLORREF\RGB[11] = COLORREF12
  COLORREF\RGB[12] = COLORREF13
  COLORREF\RGB[13] = COLORREF14
  COLORREF\RGB[14] = COLORREF15
  COLORREF\RGB[15] = COLORREF16
 
  CHOOSECOLOR\LStructSize = SizeOf(CHOOSECOLOR)
  CHOOSECOLOR\hwndOwner = 0   ;WindowID(#Window)
  CHOOSECOLOR\rgbResult = 0   ;Nothing selected
  CHOOSECOLOR\lpCustColors = COLORREF
  CHOOSECOLOR\flags = #CC_ANYCOLOR | #CC_FULLOPEN | #CC_RGBINIT
 
  If ChooseColor_(@CHOOSECOLOR)
     COLORREF1 =COLORREF\RGB[0]
     COLORREF2 =COLORREF\RGB[1]
     COLORREF3 =COLORREF\RGB[2]
     COLORREF4 =COLORREF\RGB[3]
     COLORREF5 =COLORREF\RGB[4]
     COLORREF6 =COLORREF\RGB[5]
     COLORREF7 =COLORREF\RGB[6]
     COLORREF8 =COLORREF\RGB[7]
     COLORREF9 =COLORREF\RGB[8]
     COLORREF10 =COLORREF\RGB[9]
     COLORREF11 =COLORREF\RGB[10]
     COLORREF12 =COLORREF\RGB[11]
     COLORREF13 =COLORREF\RGB[12]
     COLORREF14 =COLORREF\RGB[13]
     COLORREF15 =COLORREF\RGB[14]
     COLORREF16 =COLORREF\RGB[15]
    ExitColorPrefs()   ;Save info and Return Color Selected
    ProcedureReturn CHOOSECOLOR\rgbResult
  Else   ;No color was selected
    ExitColorPrefs()   ;Save info
    ProcedureReturn -1
  EndIf
EndProcedure

;Debug "Color Selected: " + FullColorRequester()

And It is inserted in SweetyVD with: If it suits you
Code:
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  XIncludeFile "FullColorRequester.pb"
CompilerEndIf

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  SelectedColor = FullColorRequester()
CompilerElse
  SelectedColor = ColorRequester()
CompilerEndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Tue May 09, 2017 4:24 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 842
Location: Cuernavaca, Mexico
Great.
Thanks Chris. :)

The ability to easily control colors is an important part of a Visual Designer... and SweetyVD is turning out to be among the best.

_________________
- It was too lonely at the top.

Current Machine: Win 10 Pro 64-bit, Dual Xeon E5-2670, 64 gigs ram, Geforce GTX 1660 Ti w/6 gigs ram


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Tue May 09, 2017 10:38 pm 
Online
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1689
Nice tip, I learned a few things about the Windows color chooser now.

But why would you use 16 global COLORREF variables, instead of a global array sized 16 ?!? :)

_________________
On GitHub: PB Includes - IDE Tools - Color Themes


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Tue May 09, 2017 11:06 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 842
Location: Cuernavaca, Mexico
kenmo wrote:
Nice tip, I learned a few things about the Windows color chooser now.

But why would you use 16 global COLORREF variables, instead of a global array sized 16 ?!? :)


In hindsight... absolutely. At first I was only going to save one or two parameters, then got carried away with finishing it.

I did this in about an hour, and now I'm open to anyone helping with improvements. :mrgreen:

_________________
- It was too lonely at the top.

Current Machine: Win 10 Pro 64-bit, Dual Xeon E5-2670, 64 gigs ram, Geforce GTX 1660 Ti w/6 gigs ram


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Wed May 10, 2017 5:35 am 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1715
Location: Uttoxeter, UK
Very nice.
Thank you for sharing.

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Thu May 11, 2017 12:33 am 
Offline
User
User
User avatar

Joined: Sun Jan 08, 2017 10:27 pm
Posts: 95
Location: France
I added the ColorRef array + the choice for the color window position (without a hook).
Can be usefull to get it closer to a color selector button.
Code:
;==================================================================
; Author:     blueb
; Date:       May 8, 2017
; Explain:    Create a new ColorRequester that saves User Colors (between calls)
; Forum:      http://www.purebasic.fr/english/viewtopic.php?f=12&t=68450
; Saved as:   FullColorRequester.pb
; Addition:   ChrisR: COLORREF array + choose color window position
;=========================================================

EnableExplicit
; --------------------------------------------------------------------------
; Goal - write a 'Unique' preference file in the temporary directory that
; stays in the temporary directory even when user switches to other programs.
; It will keep the special colors the user last adjusted.
; --------------------------------------------------------------------------
Declare InitColorPrefs()
Declare ExitColorPrefs()
Declare FullColorRequester(X = 0, Y = 0)

Structure COLORREF
  RGB.l[16]
EndStructure

; Structure CHOOSECOLOR ; see PB toolbox
;      lStructSize.l
;      hwndOwner.i
;      hInstance.i
;      rgbResult.l
;      *lpCustColors
;      Flags.l
;      lCustData.i
;      *lpfnHook
;      *lpTemplateName
; EndStructure

; Needed for preferences file.
Global.i Dim COLORPREF(15)

Procedure InitColorPrefs()   ;Color Preference file - Storage information
  Protected I.l
  If OpenPreferences(GetTemporaryDirectory() + "GetUserColors.prefs") = 0 ; Does not exist, "GetUserColors.prefs" is erased. So create it with Default values
    CreatePreferences(GetTemporaryDirectory() + "GetUserColors.prefs")
    For I = 0 To 15
      WritePreferenceInteger("COLORREF"+Str(I+1), COLORPREF(I))
    Next
    ClosePreferences()
  Else   ;It exists, retrieve the GetUserColors.prefs information
    For I = 0 To 15
      COLORPREF(I) = ReadPreferenceInteger("COLORREF"+Str(I+1), COLORPREF(I))
    Next
    ClosePreferences()
  EndIf
EndProcedure

Procedure ExitColorPrefs()
  Protected I.i
  If OpenPreferences(GetTemporaryDirectory() + "GetUserColors.prefs")
    For I = 0 To 15
      WritePreferenceInteger("COLORREF"+Str(I+1), COLORPREF(I))
    Next
    ClosePreferences()
   EndIf
EndProcedure

Procedure FullColorRequester(X = 0, Y = 0)   ;Place CHOOSECOLOR Info into requester()
  Protected CHOOSECOLOR.CHOOSECOLOR, COLORREF.COLORREF, hwnd.i, I.i
  hwnd = OpenWindow(#PB_Any, X, Y, 0, 0, "", #PB_Window_Invisible)
  InitColorPrefs()
  ;Place saved colors inside requester()
  For I = 0 To 15
    COLORREF\RGB[I] = COLORPREF(I)
  Next
 
  CHOOSECOLOR\LStructSize = SizeOf(CHOOSECOLOR)
  If IsWindow(hwnd)   ;Window Owner
    CHOOSECOLOR\hwndOwner = WindowID(hwnd)
  Else   ;No Owner
    CHOOSECOLOR\hwndOwner = 0
  EndIf
  CHOOSECOLOR\rgbResult = 0   ;Nothing selected
  CHOOSECOLOR\lpCustColors = COLORREF
  CHOOSECOLOR\flags = #CC_ANYCOLOR | #CC_RGBINIT   ;#CC_FULLOPEN to display the additional controls
 
  If ChooseColor_(@CHOOSECOLOR)
    For I = 0 To 15
      COLORPREF(I) = COLORREF\RGB[I]
    Next
    ExitColorPrefs()   ;Save info and Return Color Selected
    CloseWindow(hwnd)
    ProcedureReturn CHOOSECOLOR\rgbResult
  Else   ;No color was selected
    ExitColorPrefs()   ;Save info
    CloseWindow(hwnd)
    ProcedureReturn -1
  EndIf
EndProcedure

Define SelectedColor = FullColorRequester(100, 100)
If SelectedColor = -1
  Debug "Canceled by user"
Else
  Debug "Color Selected: " + SelectedColor
  Debug "Hex: " + "$" + RSet(Hex(Blue(SelectedColor)), 2, "0") + RSet(Hex(Green(SelectedColor)), 2, "0") + RSet(Hex(Red(SelectedColor)), 2, "0")   ;Hex value in BGR format
  Debug "RGB(" + Str(Red(SelectedColor)) + ", " + Str(Green(SelectedColor)) + ", " + Str(Blue(SelectedColor)) + ")"
EndIf


Edit: remove #CC_FULLOPEN to display the additional controls, by default
Once expanded, we can not go back to display it non-expanded.


Last edited by ChrisR on Thu May 11, 2017 9:41 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Thu May 11, 2017 12:44 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 842
Location: Cuernavaca, Mexico
Thanks Chris.. that's much cleaner! :)

_________________
- It was too lonely at the top.

Current Machine: Win 10 Pro 64-bit, Dual Xeon E5-2670, 64 gigs ram, Geforce GTX 1660 Ti w/6 gigs ram


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Thu May 11, 2017 2:19 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5890
Location: Wales, UK
Change RGB.l[16] to RGB.i[16] for x64

How can the requester window be initially displayed non-expanded?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Thu May 11, 2017 8:44 am 
Offline
User
User
User avatar

Joined: Sun Jan 08, 2017 10:27 pm
Posts: 95
Location: France
RGB.i[16] is changed in the code above :)

Remove #CC_FULLOPEN flag to display it non-expanded
CHOOSECOLOR\flags = #CC_ANYCOLOR | #CC_FULLOPEN | #CC_RGBINIT

ChooseColor function
CHOOSECOLOR structure


Top
 Profile  
Reply with quote  
 Post subject: Re: Better ColorRequester()
PostPosted: Thu May 11, 2017 9:23 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1093
IdeasVacuum wrote:
Change RGB.l[16] to RGB.i[16] for x64


Ähem... Why ?

The RGB Value is always Long. 32 Bit. Also on x64 machines...

_________________
PureBasic 5.71 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye