ich habe das Beispiel von XbpSpinButton() genommen und wollte mir
die Werte der 16 RGB Farben von Xbase++ anzeigen lassen. Nun gibt
er mir aber 27 Farben raus d.h. 11 Kombinationen sind nicht in Xbase++
enthalten (siehe code).
Nun wüsste ich gerne nach welcher "Formel" man die RGB Werte "aus-
rechnen" kann und ob man das selbe Prinzip auch auf 256 RBG Farben
dann erweitern kann.
gruss by OHR
Jimmy
Code: Alles auswählen
#include "Appevent.ch"
#include "Gra.ch"
PROCEDURE Main
LOCAL nEvent, mp1, mp2, oXbp
LOCAL oSpinRed, oSpinGreen, oSpinBlue, bCallback
LOCAL nRed := 0, nGreen := 0, nBlue := 0
LOCAL aEdit := {}
LOCAL oStatic
SetColor("N/W")
CLS
// Callback-Codeblock
bCallback := {|mp1, mp2, oXbp| nRed := oXbp:getData(), ;
RGB( nRed, nGreen, nBlue ) }
// SpinButton ohne :dataLink für Rot erzeugen,
oSpinRed := XbpSpinButton():new( ,, {100,200}, {100,40} )
oSpinRed:fastSpin := .T.
oSpinRed:create()
oSpinRed:setNumLimits( 0, 255 )
oSpinRed:endSpin := bCallback
oSpinRed:keyboard := bCallback
AADD(aEdit,oSpinRed)
// Callback-Codeblock
bCallback := {|mp1, mp2, oXbp| oXbp:getData(), ;
RGB( nRed, nGreen, nBlue ) }
// Spinbutton mit :dataLink für Grün erzeugen
oSpinGreen := XbpSpinButton():new( ,, {100,150}, {100,40} )
oSpinGreen:create()
oSpinGreen:setNumLimits( 0, 255 )
oSpinGreen:dataLink := {|x| IIf( x==NIL, nGreen, nGreen := x ) }
oSpinGreen:endSpin := bCallback
oSpinGreen:keyboard := bCallback
AADD(aEdit,oSpinGreen)
// Spinbutton mit :dataLink für Blau erzeugen
// (Master ist oSpinGreen)
oSpinBlue := XbpSpinButton():new( ,, {100,100}, {100,40} )
oSpinBlue:master := oSpinGreen
oSpinBlue:create()
oSpinBlue:setNumLimits( 0, 255 )
oSpinBlue:dataLink := {|x| IIf( x==NIL, nBlue, nBlue := x ) }
oSpinBlue:endSpin := bCallback
oSpinBlue:keyboard := bCallback
AADD(aEdit,oSpinBlue)
oStatic := XbpStatic():new( ,, {300, 50 }, {100,40} )
oStatic:caption := "0"
oStatic:create()
oStatic:Show()
AADD(aEdit,oStatic)
oXbp := XbpPushButton():new()
oXbp:caption := "RGB256"
oXbp:create( , , {100,50}, {100,40} )
oXbp:activate:= {|| DOIT(aEdit) }
// Event loop = Programmsteuerung
nEvent := 0
DO WHILE nEvent <> xbeP_Close
nEvent := AppEvent( @mp1, @mp2, @oXbp )
oXbp:HandleEvent( nEvent, mp1, mp2 )
ENDDO
RETURN
PROCEDURE RGB( nRed, nGreen, nBlue )
LOCAL oPS := SetAppWindow():presSpace() // Presentation-Space
LOCAL aAttr := Array(GRA_AA_COUNT) // Area-Attribute
LOCAL nMax := oPS:maxColorIndex() // Max. Colors
LOCAL aOldAttr, aOldRGB
aAttr[ GRA_AA_COLOR ] := nMax
aOldAttr := oPS:setAttrArea( aAttr )
aOldRGB := oPS:setColorIndex( nMax, {nRed,nGreen,nBlue} )
GraBox( oPS, {300,100}, {550,240}, GRA_FILL )
oPS:setAttrArea( aOldAttr )
oPS:setColorIndex( nMax, aOldRGB )
RETURN
PROCEDURE DOIT(aEdit)
LOCAL aRBG
LOCAL i
LOCAL iMax := 256
LOCAL nStep := 128
LOCAL RR,GG,BB
LOCAL nCount := 0
FOR BB = 0 TO iMax STEP nStep
FOR GG = 0 TO iMax STEP nStep
FOR RR = 0 TO iMax STEP nStep
* IF RR = ??? .OR. GG = ??? .OR. BB = ???
/*
diese Kombinationen sind nicht in Xbase++
0,128,0
0,128,255
0,255,128
128,0,255
128,128,255
128,255,128
128,255,0
128,255,255
255,0,128
255,128,0
255,255,128
*/
* ELSE
aEdit[1]:setdata(IF(RR=256,RR-1,RR))
aEdit[2]:setdata(IF(GG=256,GG-1,GG))
aEdit[3]:setdata(IF(BB=256,BB-1,BB))
nCount++
aEdit[4]:setcaption(STR(nCount))
RGB( IF(RR=256,RR-1,RR),;
IF(GG=256,GG-1,GG),;
IF(BB=256,BB-1,BB) )
SLEEP(100)
* ENDIF
NEXT
NEXT
NEXT
RETURN