Page 1 of 1

Help for Pickcolor

PostPosted: Fri Dec 05, 2014 12:52 pm
by Silvio.Falconi
I made a small Pickcolor
But I not Know how return the color Rgb


it create a box with 48 colors
and with FLATBTN we can click on each color and it must return the rgb color of a colors array but there is something not run well

we can create it also with xbrowse...


Code: Select all  Expand view


#include "fivewin.ch"
#include "constant.ch"


Function test()
   Local oDlgColor
   Local nBottom   := 12
   Local nRight    := 8

   Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
   Local nHeight := nBottom * DLG_CHARPIX_H


   local aColors := { rgb( 255, 127, 127), rgb( 255, 255, 127), rgb( 127, 255, 127),;
                   rgb(   0, 255, 127), rgb( 127, 255, 255), rgb(   0, 127, 255),;
                   rgb( 255, 127, 191), rgb( 255, 127, 255), rgb( 255,   0,   0),;
                   rgb( 255, 255,   0), rgb( 127, 255,   0), rgb(   0, 255,  63),;
                   rgb(   0, 255, 255), rgb(   0, 127, 191), rgb( 127, 127, 191),;
                   rgb( 255,   0, 255), rgb( 127,  63,  63), rgb( 255, 127,  63),;
                   rgb(   0, 255,   0), rgb(   0, 127, 127), rgb(   0,  63, 127),;
                   rgb( 127, 127, 255), rgb( 127,   0,  63), rgb( 255,   0, 127),;
                   rgb( 127,   0,   0), rgb( 255, 127,   0), rgb(   0, 127,   0),;
                   rgb(   0, 127,  63), rgb(   0,   0, 255), rgb(   0,   0, 159),;
                   rgb( 127,   0, 127), rgb( 127,   0, 255), rgb(  63,   0,   0),;
                   rgb( 127,  63,   0), rgb(   0,  63,   0), rgb(   0,  63,  63),;
                   rgb(   0,   0, 127), rgb(   0,   0,  63), rgb(  63,   0,  63),;
                   rgb(  63,   0, 127), rgb(   0,   0,   0), rgb( 127, 127,   0),;
                   rgb( 127, 127,  63), rgb( 127, 127, 127), rgb(  63, 127, 127),;
                   rgb( 191, 191, 191), rgb(  63,   0,  63), rgb( 255, 255, 255) }

   Local aGetcolor[48]

   Local nTop:= 1
   Local nCol:= 1

   DEFINE DIALOG oDlg        ;
   TITLE "Color Pick"   ;
   SIZE nWidth, nHeight  TRANSPARENT PIXEL



   k=0
   For n=1 to 48


         bAction :=  ColorReturn(n,aColors)

      @ ntop,ncol FLATBTN  aGetcolor[n] PROMPT "X"  OF oDlg SIZE 8,8  COLOR aColors[n],aColors[n]  ACTION bAction

         k+=1
          nCol+= 10

        If k = 8
           nCol:= 1
           k:=0
           nTop:= nTop+10
        endif



        next


   ACTIVATE DIALOG oDlg
   RETURN NIL


  function ColorReturn(ncolor,aColors)
   return { || msginfo(  aColors[nColor]) }

Re: Help for Pickcolor

PostPosted: Fri Dec 05, 2014 4:36 pm
by ukoenig
Silvio,

Like You can see, I'm working on a new release with some more options,
a new better screen-design and much more.
Still I have to find a solution for transparent controls, to be displayed on DIAGONAL - gradient.
viewtopic.php?f=3&t=29680

The tool includes 5 different ways , to pick a color :
1. from xbrowse
2. from a colored Image
3. from a list of colored buttons ( the solution, You are looking for )
4. from a painted gradient color lighten
5. from a painted gradient color darken

Code: Select all  Expand view

// The BLUE Button from sample

REDEFINE BTNBMP oBMP[29] OF oDlg ID 229 ;
ACTION RGB_UPD1( oDlg, nRGB( 0, 0, 255 ) ) // the BLUE button-color !!!
oBMP[29]:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
        { { 1, nRGB( 0, 0, 255 ), nRGB( 0, 0, 255 ) }, ;
        { 1, nRGB( 0, 0, 255 ), nRGB( 0, 0, 255 ) } }, ;
        { { 0.50, 16761992, 16777215 }, ;
        { 0.50, 16777215, 16761992 } } ) }

// -------------

FUNCTION RGB_UPD1( oDlg, nColor )
LOCAL nBlue, nGreen, nRed

nRed := nRGBRed( nColor )
nGreen := nRGBGreen( nColor )
nBlue := nRGBBlue( nColor )

nValRGB := nColor // VAL - color
oValRGB:Refresh()

nResRGB := nColor
oResRGB:Refresh()

cWordRGB := "" // RGB - color
oWordRGB:Refresh()

// calculate and detect if BRIGHT color
// show the light and dark gradient
// ------------------------------------
nBrightGrd := nColor
oBrightGrd:Refresh()

nDarkGrd := nColor
oDarkGrd:Refresh()

nResBright := nBrightGrd
oResBright:Refresh()

nResDark := nDarkGrd
oResDark:Refresh()

cTextRGB := "nRGB( " + ALLTRIM(STR(nRed)) + ", " + ;
     ALLTRIM(STR(nGreen)) + ", " + ;
     ALLTRIM(STR(nBlue)) + " )"

nBrightRGB := INT( 0.299 * nRed ;
     + 0.587 * nGreen ;
     + 0.114 * nBlue )

IF nBrightRGB > 127.5
     oBrightRGB:Setcolor( 255, 16777215 )
ELSE
     oBrightRGB:Setcolor( 0, 16777215 )
ENDIF
oBrightRGB:Refresh()

// -------

oTextRGB:Refresh()

oSay4:Refresh()

RETURN NIL
 


Image

best regards
Uwe :lol:

Re: Help for Pickcolor

PostPosted: Sat Dec 06, 2014 6:35 am
by Antonio Linares
Uwe,

What a nice tools you build! :-)

Thank you

Re: Help for Pickcolor

PostPosted: Sat Dec 06, 2014 8:12 am
by Silvio.Falconi
Uwe,
you tool is very nice
I wish only make a small dialog pick color to insert on an application ( on get control) and no more
I need only the modify of return bach ncolor and no more

Re: Help for Pickcolor

PostPosted: Sat Dec 06, 2014 1:40 pm
by ukoenig
Silvio,

try this sample :
( Why using FLATBTN ??? )

Image

Code: Select all  Expand view

#include "fivewin.ch"
#include "constant.ch"

FUNCTION MAIN()
     MsgInfo( PICK_COLOR() )
RETURN NIL

// ------------------

FUNCTION PICK_COLOR()
Local oDlg, oBtn
Local nSeleccion :=1, n := 0, lExit :=.F.
Local nTop := 1
Local nCol := 1
Local nBottom := 12
Local nRight := 8
Local aButtons :={}, nColor
Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H

Local aColors := { rgb( 255, 127, 127), rgb( 255, 255, 127), rgb( 127, 255, 127),;
                   rgb(   0, 255, 127), rgb( 127, 255, 255), rgb(   0, 127, 255),;
                   rgb( 255, 127, 191), rgb( 255, 127, 255), rgb( 255,   0,   0),;
                   rgb( 255, 255,   0), rgb( 127, 255,   0), rgb(   0, 255,  63),;
                   rgb(   0, 255, 255), rgb(   0, 127, 191), rgb( 127, 127, 191),;
                   rgb( 255,   0, 255), rgb( 127,  63,  63), rgb( 255, 127,  63),;
                   rgb(   0, 255,   0), rgb(   0, 127, 127), rgb(   0,  63, 127),;
                   rgb( 127, 127, 255), rgb( 127,   0,  63), rgb( 255,   0, 127),;
                   rgb( 127,   0,   0), rgb( 255, 127,   0), rgb(   0, 127,   0),;
                   rgb(   0, 127,  63), rgb(   0,   0, 255), rgb(   0,   0, 159),;
                   rgb( 127,   0, 127), rgb( 127,   0, 255), rgb(  63,   0,   0),;
                   rgb( 127,  63,   0), rgb(   0,  63,   0), rgb(   0,  63,  63),;
                   rgb(   0,   0, 127), rgb(   0,   0,  63), rgb(  63,   0,  63),;
                   rgb(  63,   0, 127), rgb(   0,   0,   0), rgb( 127, 127,   0),;
                   rgb( 127, 127,  63), rgb( 127, 127, 127), rgb(  63, 127, 127),;
                   rgb( 191, 191, 191), rgb(  63,   0,  63), rgb( 255, 255, 255) }

Local aGetcolor[48]

DEFINE DIALOG oDlg        ;
TITLE "Color Pick"   ;
SIZE nWidth, nHeight  TRANSPARENT PIXEL

k := 0

FOR n := 1 to 48

     @ ntop,ncol FLATBTN  oBtn PROMPT "X"  OF oDlg SIZE 8,8  COLOR aColors[n],aColors[n]  

     AADD(aButtons, oBtn)
     aButtons[n]:Cargo := n
     aButtons[n]:bAction := {|self| nSeleccion:= ::cargo, ;
                 nColor := aColors[nSeleccion], lExit := .T., oDlg:end() }

     k+=1
     nCol+= 10

     If k = 8
          nCol := 1
          k :=0
          nTop := nTop+10
    Endif

NEXT n

ACTIVATE DIALOG oDlg VALID lExit

RETURN  nColor
 


best regards
Uwe :lol:

Re: Help for Pickcolor

PostPosted: Sat Dec 06, 2014 6:35 pm
by Antonio Linares
Uwe,

Very good! :-)

Could we paint a little square instead of the arrow for each color ?

I would like to include it in FWH :-)

Many thanks!

Re: Help for Pickcolor

PostPosted: Sat Dec 06, 2014 10:49 pm
by ukoenig
Some small changes :
changed buttonsize, defined a font and added cursor HAND as a test

Image

Code: Select all  Expand view

#include "fivewin.ch"
#include "constant.ch"

FUNCTION MAIN()
     MsgInfo( PICK_COLOR() )
RETURN NIL

// ------------------

FUNCTION PICK_COLOR()
Local oDlg, oBtn, oCrsSelect
Local nSeleccion :=1, n := 0, lExit :=.F.
Local nTop := 1
Local nCol := 1
Local nBottom := 10
Local nRight := 12
Local aButtons :={}, nColor
Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 195 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local c_path := cFilePath(GetModuleFileName( GetInstance() ) )

Local aColors := ;
     { rgb( 255, 127, 127), rgb( 255, 255, 127), rgb( 127, 255, 127),;
       rgb(   0, 255, 127),   rgb( 127, 255, 255), rgb(   0, 127, 255),;
       rgb( 255, 127, 191), rgb( 255, 127, 255), rgb( 255,   0,   0),;
       rgb( 255, 255,   0),   rgb( 127, 255,   0),  rgb(   0, 255,  63),;
       rgb(   0, 255, 255),   rgb(   0, 127, 191),  rgb( 127, 127, 191),;
       rgb( 255,   0, 255),   rgb( 127,  63,  63),  rgb( 255, 127,  63),;
       rgb(   0, 255,   0),    rgb(   0, 127, 127),   rgb(   0,  63, 127),;
       rgb( 127, 127, 255), rgb( 127,   0,  63),    rgb( 255,   0, 127),;
       rgb( 127,   0,   0),    rgb( 255, 127,   0), rgb(   0, 127,   0),;
       rgb(   0, 127,  63),   rgb(   0,   0, 255),   rgb(   0,   0, 159),;
       rgb( 127,   0, 127),  rgb( 127,   0, 255),  rgb(  63,   0,   0),;
       rgb( 127,  63,   0),   rgb(   0,  63,   0),    rgb(   0,  63,  63),;
       rgb(   0,   0, 127),    rgb(   0,   0,  63),    rgb(  63,   0,  63),;
       rgb(  63,   0, 127),   rgb(   0,   0,   0),     rgb( 127, 127,   0),;
       rgb( 127, 127,  63),  rgb( 127, 127, 127), rgb(  63, 127, 127),;
       rgb( 191, 191, 191), rgb(  63,   0,  63),     rgb( 255, 255, 255) }

Local aGetcolor[48]

DEFINE FONT oBtnFont NAME "Arial" SIZE 0, -16 BOLD
DEFINE CURSOR oCrsSelect HAND

DEFINE DIALOG oDlg        ;
TITLE "Color Pick"   ;
SIZE nWidth, nHeight  TRANSPARENT PIXEL

k := 0

FOR n := 1 to 48

     @ ntop,ncol FLATBTN  oBtn PROMPT "x"  OF oDlg SIZE 12, 12  COLOR aColors[n],aColors[n]  FONT oBtnFont
     oBtn:oCursor := oCrsSelect

     AADD(aButtons, oBtn)
     aButtons[n]:Cargo := n
     aButtons[n]:bAction := {|self| nSeleccion:= ::cargo, ;
                 nColor := aColors[nSeleccion], lExit := .T., oDlg:end() }

     k+=1
     nCol+= 12

     If k = 8
          nCol := 1
          k :=0
          nTop := nTop+12
    Endif

NEXT n

ACTIVATE DIALOG oDlg VALID lExit

oBtnFont:End()

RETURN  nColor
 


Another solution, to display both values :

Image

Code: Select all  Expand view

#include "fivewin.ch"
#include "constant.ch"

FUNCTION MAIN()
Local nPos
Local aColors := ;
     { rgb( 255, 127, 127), rgb( 255, 255, 127), rgb( 127, 255, 127),;
       rgb(   0, 255, 127),    rgb( 127, 255, 255), rgb(   0, 127, 255),;
       rgb( 255, 127, 191), rgb( 255, 127, 255), rgb( 255,   0,   0),;
       rgb( 255, 255,   0),   rgb( 127, 255,   0),    rgb(   0, 255,  63),;
       rgb(   0, 255, 255),   rgb(   0, 127, 191),    rgb( 127, 127, 191),;
       rgb( 255,   0, 255),   rgb( 127,  63,  63),    rgb( 255, 127,  63),;
       rgb(   0, 255,   0),      rgb(   0, 127, 127),   rgb(   0,  63, 127),;
       rgb( 127, 127, 255), rgb( 127,   0,  63),     rgb( 255,   0, 127),;
       rgb( 127,   0,   0),      rgb( 255, 127,   0),    rgb(   0, 127,   0),;
       rgb(   0, 127,  63),     rgb(   0,   0, 255),      rgb(   0,   0, 159),;
       rgb( 127,   0, 127),    rgb( 127,   0, 255),   rgb(  63,   0,   0),;
       rgb( 127,  63,   0),     rgb(   0,  63,   0),       rgb(   0,  63,  63),;
       rgb(   0,   0, 127),      rgb(   0,   0,  63),       rgb(  63,   0,  63),;
       rgb(  63,   0, 127),     rgb(   0,   0,   0),         rgb( 127, 127,   0),;
       rgb( 127, 127,  63),   rgb( 127, 127, 127), rgb(  63, 127, 127),;
       rgb( 191, 191, 191), rgb(  63,   0,  63),       rgb( 255, 255, 255) }

     nPos := PICK_COLOR(aColors)

     nRed := nRGBRed( aColors[nPos] )
     nGreen := nRGBGreen( aColors[nPos] )
     nBlue := nRGBBlue( aColors[nPos] )
     cRGB := "nRGB( " + ALLTRIM(STR(nRed)) + ", " + ;
                       ALLTRIM(STR(nGreen)) + ", " + ;
                       ALLTRIM(STR(nBlue)) + " )"

     MsgAlert( LTRIM(STR(aColors[nPos])) + CRLF + cRGB, "Pick-color" )

RETURN NIL

// ------------------

FUNCTION PICK_COLOR(aColors)
Local oDlg, oBtn, oCrsSelect
Local nSeleccion :=1, n := 0, lExit :=.F.
Local nTop := 1
Local nCol := 1
Local nBottom := 10
Local nRight := 12
Local aButtons :={}, nColor
Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 195 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local c_path := cFilePath(GetModuleFileName( GetInstance() ) )
Local aGetcolor[48]

DEFINE FONT oBtnFont NAME "Arial" SIZE 0, -16 BOLD
DEFINE CURSOR oCrsSelect HAND

DEFINE DIALOG oDlg        ;
TITLE "Color Pick"   ;
SIZE nWidth, nHeight  TRANSPARENT PIXEL

k := 0

FOR n := 1 to 48

     @ ntop,ncol FLATBTN  oBtn PROMPT "x"  OF oDlg SIZE 12, 12  COLOR aColors[n],aColors[n]  FONT oBtnFont
     oBtn:oCursor := oCrsSelect

     AADD(aButtons, oBtn)
     aButtons[n]:Cargo := n
     aButtons[n]:bAction := {|self| nSeleccion:= ::cargo, ;
         lExit := .T., oDlg:end() }

     k+=1
     nCol+= 12

     If k = 8
          nCol := 1
          k :=0
          nTop := nTop+12
    Endif

NEXT n

ACTIVATE DIALOG oDlg VALID lExit

oBtnFont:End()

RETURN  nSeleccion
 


Is it possible, to create a cursor from a included source ?

Image

DRAGBTN CURSOR
{
'00 00 02 00 01 00 20 20 00 00 1B 00 1B 00 30 01'
'00 00 16 00 00 00 28 00 00 00 20 00 00 00 40 00'
'00 00 01 00 01 00 00 00 00 00 00 02 00 00 00 00'
'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
'00 00 FF FF FF 00 00 00 00 00 00 00 00 0C 00 00'
'00 0C 00 00 00 18 00 00 00 18 05 55 51 34 02 AA'
'A4 B0 04 00 06 64 02 00 07 68 04 00 07 E0 02 00'
'07 FC 04 00 07 F8 02 00 07 F0 04 00 07 E4 02 00'
'07 C8 04 00 07 84 02 00 07 08 04 00 06 04 02 00'
'04 08 04 00 00 04 02 00 00 08 04 00 00 04 02 00'
'00 08 04 00 00 04 02 00 00 08 05 55 55 54 02 AA'
'AA A8 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
'00 00 00 00 00 00 FF FF FF F3 FF FF FF E1 FF FF'
'FF E1 FF FF FF C3 FF FF F7 C3 F8 00 00 03 F8 00'
'00 03 F9 FF F0 03 F9 FF F0 03 F9 FF F0 00 F9 FF'
'F0 01 F9 FF F0 03 F9 FF F0 03 F9 FF F0 03 F9 FF'
'F0 13 F9 FF F0 33 F9 FF F0 73 F9 FF F0 F3 F9 FF'
'F1 F3 F9 FF F3 F3 F9 FF FF F3 F9 FF FF F3 F9 FF'
'FF F3 F9 FF FF F3 F9 FF FF F3 F8 00 00 03 F8 00'
'00 03 FF FF FF FF FF FF FF FF FF FF FF FF FF FF'
'FF FF FF FF FF FF'
}


best regards
Uwe :?:

Re: Help for Pickcolor

PostPosted: Sun Dec 07, 2014 7:37 am
by Antonio Linares
Uwe,

Please review FWH\source\winapi\cursors.c where you can see how to create cursors from C source:

Code: Select all  Expand view
HB_FUNC( CURSORSTOP )
{
   if( ! hStop )
   {
      hStop = CreateCursor( GetInstance(), 6, 0, 32, 32, StopAnd, StopXor );
      RegisterResource( hStop, "CUR" );
   }

   SetCursor( hStop );
}


Besides that, in samples you have curtoc.prg that automatically generates the C definition from a given cursor, so it can be created from memory :-)

Re: Help for Pickcolor

PostPosted: Mon Dec 08, 2014 10:27 am
by ukoenig
I completed the sample :
( select dialog-color from color-picker )

1. a start-dialog with button-selection
2. saved a selected color to a INI

Image

Code: Select all  Expand view

#include "fivewin.ch"
#include "constant.ch"

STATIC c_path

FUNCTION MAIN()
Local oDlg, oBtn1, oBtn2, oBtn3, oBtnFont, oBmp1, oBmp2
Local oGet1, oGet2, nColorPos := 1, nRed, nGreen, nBlue, nCOLORVAL := 8355839
Local cRGB := "nRGB( 255, 127, 127 )"
Local aColors := ;
     { rgb( 255, 127, 127), rgb( 255, 255, 127), rgb( 127, 255, 127),;
       rgb(   0, 255, 127),    rgb( 127, 255, 255), rgb(   0, 127, 255),;
       rgb( 255, 127, 191), rgb( 255, 127, 255), rgb( 255,   0,   0),;
       rgb( 255, 255,   0),   rgb( 127, 255,   0),    rgb(   0, 255,  63),;
       rgb(   0, 255, 255),   rgb(   0, 127, 191),    rgb( 127, 127, 191),;
       rgb( 255,   0, 255),   rgb( 127,  63,  63),    rgb( 255, 127,  63),;
       rgb(   0, 255,   0),      rgb(   0, 127, 127),   rgb(   0,  63, 127),;
       rgb( 127, 127, 255), rgb( 127,   0,  63),     rgb( 255,   0, 127),;
       rgb( 127,   0,   0),      rgb( 255, 127,   0),    rgb(   0, 127,   0),;
       rgb(   0, 127,  63),     rgb(   0,   0, 255),      rgb(   0,   0, 159),;
       rgb( 127,   0, 127),    rgb( 127,   0, 255),   rgb(  63,   0,   0),;
       rgb( 127,  63,   0),     rgb(   0,  63,   0),       rgb(   0,  63,  63),;
       rgb(   0,   0, 127),      rgb(   0,   0,  63),       rgb(  63,   0,  63),;
       rgb(  63,   0, 127),     rgb(   0,   0,   0),         rgb( 127, 127,   0),;
       rgb( 127, 127,  63),   rgb( 127, 127, 127), rgb(  63, 127, 127),;
       rgb( 191, 191, 191), rgb(  63,   0,  63),       rgb( 255, 255, 255) }

c_path := cFilePath(GetModuleFileName( GetInstance() ) )

DEFINE FONT oBtnFont NAME "Arial" SIZE 0, -16 BOLD

nColorPos := GET_INI()

DEFINE DIALOG oDlg ;
TITLE "Change color"   ;
SIZE 500, 400  TRANSPARENT PIXEL

@ 150, 10 GET oGet1 VAR nCOLORVAL SIZE 85, 12 FONT oBtnFont PIXEL CENTERED

@ 170, 10 BUTTON oBtn1 PROMPT "&Numeric" SIZE 85, 18 FONT oBtnFont PIXEL OF oDlg ;
ACTION ( nColorPos := PICK_COLOR(aColors, nColorPos), ;
                  SAVE_INI(nColorPos), ;
                  nCOLORVAL := aColors[nColorPos], ;
                  oGet1:Refresh(), ;
                  nRed := nRGBRed( aColors[nColorPos] ), ;
                  nGreen := nRGBGreen( aColors[nColorPos] ), ;
                  nBlue := nRGBBlue( aColors[nColorPos] ), ;
                  cRGB := "nRGB( " + ALLTRIM(STR(nRed)) + ", " + ALLTRIM(STR(nGreen)) + ", " + ;
                          ALLTRIM(STR(nBlue)) + " )", oGet2:Refresh(), ;
                  D_BACKGRD( oDlg, aColors[nColorPos] ) )

@ 150, 100 GET oGet2 VAR cRGB SIZE 90, 12 FONT oBtnFont PIXEL CENTERED

@ 170, 100 BUTTON oBtn2 PROMPT "&RGB-string" SIZE 90, 18 FONT oBtnFont PIXEL OF oDlg ;
ACTION ( nColorPos := PICK_COLOR(aColors, nColorPos), ;
                  SAVE_INI(nColorPos), ;
                  nRed := nRGBRed( aColors[nColorPos] ), ;
                  nGreen := nRGBGreen( aColors[nColorPos] ), ;
                  nBlue := nRGBBlue( aColors[nColorPos] ), ;
                  cRGB := "nRGB( " + ALLTRIM(STR(nRed)) + ", " + ALLTRIM(STR(nGreen)) + ", " + ;
                          ALLTRIM(STR(nBlue)) + " )", oGet2:Refresh(), ;
                  nCOLORVAL := aColors[nColorPos], ;
                  oGet1:Refresh(), ;
                  D_BACKGRD( oDlg, aColors[nColorPos] ) )

@ 170, 200 BUTTON oBtn3 PROMPT "&Exit" SIZE 40, 18 FONT oBtnFont PIXEL OF oDlg ACTION oDlg:End()

ACTIVATE DIALOG oDlg CENTERED ;
ON INIT D_BACKGRD( oDlg, aColors[nColorPos] )

oBtnFont:End()

RETURN NIL

// --------  DIALOG - Background ---------------

FUNCTION D_BACKGRD( oDlg, nDColor )
Local oBrush

DEFINE BRUSH oBrush COLOR nDColor
oDlg:SetBrush( oBrush )
RELEASE BRUSH oBrush

RETURN( NIL )

// ------------------

FUNCTION PICK_COLOR(aColors, nColorPos)
Local oDlg1, oBtn, oCrsSelect
Local nSeleccion := nColorPos, n := 0, lExit :=.F.
Local nTop := 1
Local nCol := 1
Local nBottom := 10
Local nRight := 12
Local aButtons :={}, nColor
Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 195 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local aGetcolor[48]

DEFINE FONT oBtnFont NAME "Arial" SIZE 0, -16 BOLD

DEFINE CURSOR oCrsSelect DRAG

DEFINE DIALOG oDlg1 ;
TITLE "Color Pick"   ;
SIZE nWidth, nHeight  TRANSPARENT PIXEL

k := 0

FOR n := 1 to 48

     @ ntop,ncol FLATBTN  oBtn PROMPT "x"  OF oDlg1 SIZE 12, 12  COLOR aColors[n],aColors[n]  FONT oBtnFont
     oBtn:oCursor := oCrsSelect

     AADD(aButtons, oBtn)
     aButtons[n]:Cargo := n
     aButtons[n]:bAction := {|self| nSeleccion:= ::cargo, ;
         lExit := .T., oDlg1:end() }

     k+=1
     nCol+= 12

     If k = 8
          nCol := 1
          k :=0
          nTop := nTop+12
    Endif
 
NEXT n

ACTIVATE DIALOG oDlg1 CENTERED VALID lExit

RETURN  nSeleccion

// ---------  INI Write------------------------

FUNCTION SAVE_INI(nColorPos)
LOCAL cIniFile := c_path + "\COLOR.INI"

WritePProString( "Dialog", "Color-Pos", ALLTRIM(STR(nColorPos)),  cIniFile )

RETURN( NIL )

// ---------  INI Read ------------------------

FUNCTION GET_INI(nColorPos)
LOCAL oIni, cIniFile := c_path + "COLOR.INI"

IF !FILE ( c_path + "COLOR.ini" )
     SAVE_INI(nColorPos)
ELSE
     INI oIni FILE c_path + "COLOR.INI"
           nColorPos :=  Val(GetPvProfString( "Dialog","Color-Pos", "1" , cIniFile ) )
     ENDINI
ENDIF

RETURN( nColorPos )
 


I will include options, to load different color-sets
and getting tooltips on button-focus with colorinformations


Loading a different color-set

Image

Tooltips on button-focus with colorinformations

Image

Best regards
Uwe :lol:

Re: Help for Pickcolor

PostPosted: Mon Dec 08, 2014 10:49 pm
by ukoenig
New options :

1. 4 color-groups added
2. Dialogs are centered on screen
3. For NO color-selection, use the EXIT-button ( enabled )
4. Tooltips on button-focus
5. Copy values from get-fields
6. The selection is saved to a INI-file and shown at new start

Image

Pick a color or view a tooltip.

Image

Download

http://www.pflegeplus.com/DOWNLOADS/Colorpicker1.zip

Best regards
Uwe :lol:

Re: Help for Pickcolor

PostPosted: Tue Dec 09, 2014 8:37 am
by Silvio.Falconi
Uwe,
this week I had not Internet connection here and I not saw your messages...

On this week I made this Pickcolor more easy and simply

It can be used on a get ..bitmap..action simply

Image

on this dialog there is also the possibility to select the others colors ( choosecolor()) or we can inseret also metrocolors

it return back the number of color selected

the code
Code: Select all  Expand view
/*
    =================================================================================
    selcolors.prg - PopUp-colors                    (c) copyright: Falconi Silvio 2014
                                                                          info@eoeo.it
                                                                           www.eoeo.it
    ---------------------------------------------------------------------------------

    =================================================================================
*/



#include "fivewin.ch"
#include "ribbon.ch"
#include "constant.ch"

#define BTN_WIDTH  12
#define BTN_HEIGHT 12


#define OTHERS_COLORS "Altri colori"

static nClrReturn,oDlgPickColor




function Test()
   Local oDlg,oGet,nColor := 1

   DEFINE DIALOG oDlg  title "Test Pick color"

   @10,10 GET oGet VAR nColor  SIZE 100,10 PIXEL;
   BITMAP "C:\WORK\FWH\BITMAPS\16X16\colors.BMP"  ACTION (nColor:= Selcolor(30, 30, nColor,oGet) )
   ACTIVATE DIALOG oDlg

   RETU NIL







//--------------------------------------------------------------------------------//

Function Selcolor(nRow, nCol, nColor, oControl)
   Local nBottom   := 12
   Local nRight    := 27
   Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
   Local nHeight := nBottom * DLG_CHARPIX_H
   Local nMaxVal := 1
   Local oCursorBtn :=TCursor():New(,'HAND')
   local aColors := { rgb( 255, 127, 127), rgb( 255, 255, 127), rgb( 127, 255, 127),;
                   rgb(   0, 255, 127), rgb( 127, 255, 255), rgb(   0, 127, 255),;
                   rgb( 255, 127, 191), rgb( 255, 127, 255), rgb( 255,   0,   0),;
                   rgb( 255, 255,   0), rgb( 127, 255,   0), rgb(   0, 255,  63),;
                   rgb(   0, 255, 255), rgb(   0, 127, 191), rgb( 127, 127, 191),;
                   rgb( 255,   0, 255), rgb( 127,  63,  63), rgb( 255, 127,  63),;
                   rgb(   0, 255,   0), rgb(   0, 127, 127), rgb(   0,  63, 127),;
                   rgb( 127, 127, 255), rgb( 127,   0,  63), rgb( 255,   0, 127),;
                   rgb( 127,   0,   0), rgb( 255, 127,   0), rgb(   0, 127,   0),;
                   rgb(   0, 127,  63), rgb(   0,   0, 255), rgb(   0,   0, 159),;
                   rgb( 127,   0, 127), rgb( 127,   0, 255), rgb(  63,   0,   0),;
                   rgb( 127,  63,   0), rgb(   0,  63,   0), rgb(   0,  63,  63),;
                   rgb(   0,   0, 127), rgb(   0,   0,  63), rgb(  63,   0,  63),;
                   rgb(  63,   0, 127), rgb(   0,   0,   0), rgb( 127, 127,   0),;
                   rgb( 127, 127,  63), rgb( 127, 127, 127), rgb(  63, 127, 127),;
                   rgb( 191, 191, 191), rgb(  63,   0,  63), rgb( 255, 255, 255) }

   local aPoint := AdjustWnd( oControl, 271*2, 150*2 )
   nTotRow := 6
   nTotCol = 8
   aBtn = Array( nTotRow * nTotCol )
   aSay = Array( nTotRow * nTotCol)
   xRow:=1
   xCol:=10
   DEFINE DIALOG oDlgPickColor   STYLE nOr( WS_POPUP, DS_MODALFRAME ) ;
   TITLE i18n("Selezione colore")    ;
   SIZE nWidth, nHeight   PIXEL
   nClrReturn := nil
   xRow:=1
   xCol:=1
   npow=1
   For t=1 to nTotRow
      For k=1 to nTotCol
         nPos = nTotCol * ( t - 1 ) + k
         @  xRow, xCol FLATBTN aBtn[ nPos ] PROMPT alltrim(str(npow, 2)) ;
            SIZE BTN_WIDTH,BTN_HEIGHT  COLOR  aColors[ nPos],aColors[ nPos]

         xCol += BTN_WIDTH + 1
         aBtn[ nPos ]:oCursor:=oCursorBtn
           aBtn[ nPos ]:bAction = BtnAction( k, t, nTotCol, nTotRow, aBtn, aSay, nMaxVal,alltrim(str(npow, 2) ),aColors)
           aBtn[ nPos ]:cTooltip:= str(acolors[nPos])
           npow=npow+1
         next k
      xRow += BTN_HEIGHT +1
      xCol = 1
   next t

   @ 80,1 Button other Prompt OTHERS_COLORS  SIZE 50,8;
   PIXEL of oDlgPickColor action (nClrReturn:=choosecolor(nColor),oDlgPickColor:end( IDOK ) )
   ACTIVATE DIALOG oDlgPickColor ;
   ON PAINT oDlgPickColor:Move(aPoint[1], aPoint[2],,,.t.)
    IF oDlgPickColor:nresult == IDOK
      return nClrReturn
   endif
   RETURN NIL
//--------------------------------------------------------------------------------//
static  Function BtnAction( x, y, nTotCol, nTotRow, aBtn, aSay, nMaxVal,numero,aColors)
return { | oSelf | CheckStatus( oSelf, x, y, nTotCol, nTotRow, aBtn, aSay, nMaxVal,numero,aColors ) }

//--------------------------------------------------------------------------------//
static Function CheckStatus( oSelf, x, y, nTotCol, nTotRow, aBtn, aSay, nMaxVal,numero,acolors )
   local nCount := 0
   local j

         nClrReturn := acolors[VAL(numero)]


        oDlgPickColor:end( IDOK )

return  nClrReturn
//--------------------------------------------------------------------------------//
static Function AdjustWnd( oBtn, nWidth, nHeight )
   Local nMaxWidth, nMaxHeight
   Local aPoint

   aPoint := { oBtn:nTop + oBtn:nHeight(), oBtn:nLeft }
   clientToScreen( oBtn:oWnd:hWnd, @aPoint )

   nMaxWidth  := GetSysMetrics(0)
   nMaxHeight := GetSysMetrics(1)

   IF  aPoint[2] + nWidth > nMaxWidth
      aPoint[2] := nMaxWidth -  nWidth
   ENDIF

   IF  aPoint[1] + nHeight > nMaxHeight
      aPoint[1] := nMaxHeight - nHeight
   ENDIF
   Return aPoint
//--------------------------------------------------------------------------------//

//eof..






 

Re: Help for Pickcolor

PostPosted: Tue Dec 09, 2014 1:20 pm
by ukoenig
Silvio,

selecting from a GET :

1.
Load from INI and style selection.
included a get with the RGB-string

Adjusted dialog-color from selection.

Image

2.
NO color-selection, using EXIT


Image

3.
Extended tooltip


Image

4
Adjusted dialog for METRO-style


Image

5.
Adjusted dialog for DARK-style


Image

6.
Adjusted dialog for LIGHT-style


Image

7.
WINDOW-style


Image

best regards
Uwe :lol:

Re: Help for Pickcolor

PostPosted: Tue Dec 09, 2014 4:20 pm
by Silvio.Falconi
Perhaps erase the extern combo and insert it on dialog pick ..refreshing a colors array....

Re: Help for Pickcolor

PostPosted: Tue Dec 09, 2014 11:11 pm
by ukoenig
Silvio,

I moved the combo to to color-dialog. It works fine now.

Download

http://www.pflegeplus.com/DOWNLOADS/Colorpick2.zip

Image

Image

Image

Image

Image

Image

Image

best regards
Uwe :lol: