Visiblement la Beta 1 a un prob avec un de mes codes qui fonctionne parfaitement avec les autres version de PB. Et comme il n'y a pas d'erreur explicite je seche
.
Code : Tout sélectionner
; +======================================================+
; | ROUTINE DE SELECTION DE COULEUR STYLE MSPAINT. |
; +------------------------------------------------------+
; | COPYRIGHT(C)2007-2012, ALL RIGHT RESERVED KOAKDESIGN |
; +--------------+---------------------------------------+
; | Program type | PUREBASIC 4.60 |
; +--------------+---------------------------------------+
; | VER & REV | 0.0.1 |
; +--------------+---------------------------------------+
; | Program name | main.pb |
; +======================================================+
; +======================================================+
; | Original Version: 0.0.1 RC0 |
; +--------------+---------------------------------------+
; | Created by | GallyHomeCorp |
; | Graphix by | GallyHomeCorp |
; +--------------+---------------------------------------+
; | Comments: | |
; +--------------+ |
; | |
; | |
; | |
; +======================================================+
; +======================================================+
; | Système d'Exploitation |
; +--------------+---------------------------------------+
; | Window | Oui |
; | Linux | Oui |
; | MacOS | Oui |
; +======================================================+
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
;- INITIALISATION DES DIRECTIVES COMPILEUR.
DisableASM
EnableExplicit
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
;- DECLARATION DES VARIABLES (GLOBALE).
;{ - ENUMERATION
Enumeration
#Window_main
EndEnumeration
Enumeration
#Canvas_0
#Canvas_1
#Text_0
#Text_1
#Text_2
#Text_3
#Text_4
#Text_5
#Text_6
#Text_7
#String_0
#String_1
#String_2
#String_3
#String_4
#String_5
#String_6
EndEnumeration
;}
;{ - CONSTANTE
#COLOR_SPECTRUM_SIZE_MAX = 255
;}
;{ - GLOBAL
Global bCH.a = 0
Global bCS.a = 0
Global bCL.a = 127
Global iImage.i
;}
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Procedure GetWindowBackgroundColor()
; ROUTINE DE RECHERCHE DE LA COULEUR de FOND.
ProcedureReturn GetSysColor_(#COLOR_3DFACE)
EndProcedure
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Procedure RGBToHLS(bCR.b, bCG.b, bCB.b, *lCH, *lCL, *lCS)
; ROUTINE DE CONSERTION DU RGB EN HLS.
Define fCH.f
Define fCS.f
Define fCL.f
Define lMin.l
Define lMax.l
Define lDif.l
Define lSum.l
Define lNmR.l
Define lNmG.l
Define lNmB.l
If bCR < bCG
If bCR < bCB
lMin = bCR
Else
lMin = bCB
EndIf
Else
If bCG < bCB
lMin = bCG
Else
lMin = bCB
EndIf
EndIf
If bCR > bCG
If bCR > bCG
lMax = bCR
Else
lMax = bCB
EndIf
Else
If bCG > bCB
lMax = bCG
Else
lMax = bCB
EndIf
EndIf
lDif = lMax - lMin
lSum = lMax + lMin
fCL = lSum / 510
If lMax = lMin
fCH = 0
fCS = 0
Else
lNmR = (lMax - bCR) / lDif
lNmG = (lMax - bCG) / lDif
lNmB = (lMax - bCB) / lDif
If fCL <= 0.5
fCS = lDif / lSum
Else
fCS = lDif / (510 - lSum)
EndIf
If bCR = lMax
fCH = 60 * (6 + lNmB - lNmG)
EndIf
If bCG = lMax
fCH = 60 * (4 + lNmR - lNmB)
EndIf
If bCB = lMax
fCH = 60 * (2 + lNmG - lNmR)
EndIf
EndIf
If fCH = 360
fCH = 0
EndIf
fCH = (fCH / 360 * #COLOR_SPECTRUM_SIZE_MAX)
fCL = fCL * #COLOR_SPECTRUM_SIZE_MAX
fCS = fCS * #COLOR_SPECTRUM_SIZE_MAX
PokeL(*lCH, Int(fCH))
PokeL(*lCL, Int(fCL))
PokeL(*lCS, Int(fCS))
EndProcedure
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Procedure.l CONVERTRM(fM1.f, fM2.f, fCH.f)
; ROUTINE DE CALCUL DE LA COMPOSENTE DE COULEUR.
If fCH > 360
fCH - 360
EndIf
If fCH < 0
fCH + 360
EndIf
If fCH < 60
fM1 = fM1 + (fM2 - fM1) * fCH / 60
Else
If fCH < 180
fM1 = fM2
Else
If fCH < 240
fM1 = fM1 + (fM2 - fM1) * (240 - fCH) / 60
EndIf
EndIf
EndIf
ProcedureReturn fM1 * #COLOR_SPECTRUM_SIZE_MAX
EndProcedure
Procedure HLSToRGB(fCH.f, fCL.f, fCS.f, *bCR, *bCG, *bCB)
; ROUTINE DE CONSERTION DU HLS EN RGB.
Define fM1.f
Define fM2.f
fCH = fCH * 360 / #COLOR_SPECTRUM_SIZE_MAX
fCL = fCL / #COLOR_SPECTRUM_SIZE_MAX
fCS = fCS / #COLOR_SPECTRUM_SIZE_MAX
If fCS = 0
PokeL(*bCR, fCL * 255)
PokeL(*bCG, fCL * 255)
PokeL(*bCB, fCL * 255)
Else
If fCL <= 0.5
fM2 = fCL + fCL * fCS
Else
fM2 = fCL + fCS - fCL * fCS
EndIf
fM1 = 2 * fCL - fM2
PokeL(*bCR, CONVERTRM(fM1, fM2, fCH + 120))
PokeL(*bCG, CONVERTRM(fM1, fM2, fCH))
PokeL(*bCB, CONVERTRM(fM1, fM2, fCH - 120))
EndIf
EndProcedure
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Procedure setDrawCross(lX.l, lY.l)
; ROUTINE DE TRACAGE DE LA CROIX DU SPECTRE.
If lX < #COLOR_SPECTRUM_SIZE_MAX
lX + 1
EndIf
If lY < #COLOR_SPECTRUM_SIZE_MAX
lY + 1
EndIf
Box(lX - 1, lY - 9, 3, 5, $000000)
Box(lX - 1, lY + 5, 3, 5, $000000)
Box(lX - 9, lY - 1, 5, 3, $000000)
Box(lX + 5, lY - 1, 5, 3, $000000)
EndProcedure
Procedure setGenerateSpectre()
; ROUTINE DE PRECALCUL DU SPECTRE DE COULEUR.
Define lH.l
Define lS.l
Define bCR.l
Define bCG.l
Define bCB.l
iImage = CreateImage(#PB_Any, #COLOR_SPECTRUM_SIZE_MAX + 2, #COLOR_SPECTRUM_SIZE_MAX + 2)
If iImage <> 0
If StartDrawing(ImageOutput(iImage))
Box(0, 0, #COLOR_SPECTRUM_SIZE_MAX + 2, #COLOR_SPECTRUM_SIZE_MAX + 2, $000000)
For lS = 1 To #COLOR_SPECTRUM_SIZE_MAX
For lH = 1 To #COLOR_SPECTRUM_SIZE_MAX
HLSToRGB(lH, #COLOR_SPECTRUM_SIZE_MAX / 2, lS, @bCR, @bCG, @bCB)
Plot(lH, ( #COLOR_SPECTRUM_SIZE_MAX - lS) + 1, RGB(bCR, bCG, bCB))
Next lH
Next lS
StopDrawing()
EndIf
EndIf
EndProcedure
Procedure setDrawSpectre()
; ROUTINE D'AFFICHAGE DU SPECTRE ET CROIX.
Define lH.l
Define lS.l
Define bCR.l
Define bCG.l
Define bCB.l
If StartDrawing(CanvasOutput(#Canvas_0))
If iImage <> 0
DrawAlphaImage(ImageID(iImage), 0, 0)
EndIf
setDrawCross(bCH, #COLOR_SPECTRUM_SIZE_MAX - bCS)
HLSToRGB(bCH, bCL, bCS, @bCR, @bCG, @bCB)
SetGadgetColor(#Text_0, #PB_Gadget_BackColor, RGB(bCR, bCG, bCB))
StopDrawing()
EndIf
EndProcedure
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Procedure setDrawArrow(lX.l, lY.l)
; ROUTINE DE TRACAGE DE LA BARRE DE PROGRESSION.
Define x1.l
Define y1.l
Define x2.l
Define y2.l
Define xm.l
If lY =< 5
lY = 5
EndIf
If lY => #COLOR_SPECTRUM_SIZE_MAX - 5
lY = #COLOR_SPECTRUM_SIZE_MAX - 5
EndIf
Line(lX, lY, 5, -5, $000000)
Line(lX, lY, 5, 5 , $000000)
LineXY(lX + 5, lY - 5, lX + 5, lY + 5 , $000000)
FillArea(lX + 2, lY, 0, 0)
EndProcedure
Procedure setDrawLum()
; ROUTINE DE TRACAGE DE LA BARRE LUMIERE.
Define i.l
Define bCR.l
Define bCG.l
Define bCB.l
If StartDrawing(CanvasOutput(#Canvas_1))
Box(0, 0, #COLOR_SPECTRUM_SIZE_MAX + 2, #COLOR_SPECTRUM_SIZE_MAX + 2, GetWindowBackgroundColor())
Box(0, 0, 20, #COLOR_SPECTRUM_SIZE_MAX + 2, $000000)
For i = 1 To #COLOR_SPECTRUM_SIZE_MAX
HLSToRGB(bCH, i, bCS, @bCR, @bCG, @bCB)
LineXY(1,( #COLOR_SPECTRUM_SIZE_MAX - i) + 1, 18,( #COLOR_SPECTRUM_SIZE_MAX - i) + 1, RGB(bCR, bCG, bCB))
Next i
setDrawArrow(22, #COLOR_SPECTRUM_SIZE_MAX - bCL)
HLSToRGB(bCH, bCL, bCS, @bCR, @bCG, @bCB)
SetGadgetColor(#Text_0, #PB_Gadget_BackColor, RGB(bCR, bCG, bCB))
StopDrawing()
EndIf
EndProcedure
Procedure DrawHSLText()
; ROUTINE D'AFFICHAGE DES INFOS HSL.
SetGadgetText(#String_0, Str(bCH))
SetGadgetText(#String_1, Str(bCS))
SetGadgetText(#String_2, Str(bCL))
EndProcedure
Procedure DrawRGBText()
; ROUTINE D'AFFICHAGE DES INFOS RGB.
Define bCR.l
Define bCG.l
Define bCB.l
HLSToRGB(bCH, bCL, bCS, @bCR, @bCG, @bCB)
SetGadgetText(#String_3, Str(bCR))
SetGadgetText(#String_4, Str(bCG))
SetGadgetText(#String_5, Str(bCB))
SetGadgetText(#String_6, "#" + RSet(Hex(bCR), 2, "0") + RSet(Hex(bCG), 2, "0") + RSet(Hex(bCB), 2, "0"))
EndProcedure
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Define event.l
Define evenp.l
Define eveng.l
Define lMosX.l
Define lMosY.l
Define lMosP.l
Define Retour_H.b
Define Retour_S.b
Define Retour_L.b
Define Retour_R.b
Define Retour_G.b
Define Retour_B.b
Define hWnd.l = OpenWindow(#Window_main, 0, 0, #COLOR_SPECTRUM_SIZE_MAX + 46, #COLOR_SPECTRUM_SIZE_MAX + 110, "Spectre de couleurs", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If hWnd <> 0
SmartWindowRefresh(#Window_main, 1)
CanvasGadget(#Canvas_0, 5, 5, #COLOR_SPECTRUM_SIZE_MAX + 2, #COLOR_SPECTRUM_SIZE_MAX + 2)
CanvasGadget(#Canvas_1, 270, 5, 28, #COLOR_SPECTRUM_SIZE_MAX + 2)
TextGadget(#Text_0, 5, 270, 100, 64, #NULL$, #PB_Text_Border)
TextGadget(#Text_1, 122, 274, 40, 20, "Teinte", #PB_Text_Right)
TextGadget(#Text_2, 122, 295, 40, 20, "Satur", #PB_Text_Right)
TextGadget(#Text_3, 122, 316, 40, 20, "Lum", #PB_Text_Right)
StringGadget(#String_0, 170, 270, 33, 20, "")
StringGadget(#String_1, 170, 291, 33, 20, "")
StringGadget(#String_2, 170, 312, 33, 20, "")
TextGadget(#Text_4, 210, 274, 40, 20, "Rouge", #PB_Text_Right)
TextGadget(#Text_5, 210, 295, 40, 20, "Vert", #PB_Text_Right)
TextGadget(#Text_6, 210, 316, 40, 20, "Bleu", #PB_Text_Right)
StringGadget(#String_3, 258, 270, 33, 20, "")
StringGadget(#String_4, 258, 291, 33, 20, "")
StringGadget(#String_5, 258, 312, 33, 20, "")
TextGadget(#Text_7, 140, 344, 80, 20, "Couleur Web", #PB_Text_Right)
StringGadget(#String_6, 231, 340, 63, 20, "")
setGenerateSpectre()
setDrawSpectre()
setDrawLum()
DrawHSLText()
DrawRGBText()
Retour_H = Val(GetGadgetText(#String_0))
Retour_S = Val(GetGadgetText(#String_1))
Retour_L = Val(GetGadgetText(#String_2))
Retour_R = Val(GetGadgetText(#String_3))
Retour_G = Val(GetGadgetText(#String_4))
Retour_B = Val(GetGadgetText(#String_5))
Repeat
event = WaitWindowEvent(20)
evenp = EventType()
eveng = EventGadget()
If event = #PB_Event_Gadget
Select eveng
Case #Canvas_0
If evenp = #PB_EventType_LeftButtonDown Or (evenp = #PB_EventType_MouseMove And GetGadgetAttribute(#Canvas_0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
lMosX.l = GetGadgetAttribute(#Canvas_0, #PB_Canvas_MouseX)
lMosY.l = GetGadgetAttribute(#Canvas_0, #PB_Canvas_MouseY)
If lMosX < 0
lMosX = 0
Else
If lMosX > #COLOR_SPECTRUM_SIZE_MAX
lMosX = #COLOR_SPECTRUM_SIZE_MAX
EndIf
EndIf
If lMosY < 0
lMosY = 0
Else
If lMosY > #COLOR_SPECTRUM_SIZE_MAX
lMosY = #COLOR_SPECTRUM_SIZE_MAX
EndIf
EndIf
bCH = lMosX
bCS = #COLOR_SPECTRUM_SIZE_MAX - lMosY
setDrawSpectre()
setDrawLum()
DrawHSLText()
DrawRGBText()
Retour_H = Val(GetGadgetText(#String_0))
Retour_S = Val(GetGadgetText(#String_1))
Retour_L = Val(GetGadgetText(#String_2))
Retour_R = Val(GetGadgetText(#String_3))
Retour_G = Val(GetGadgetText(#String_4))
Retour_B = Val(GetGadgetText(#String_5))
EndIf
Case #Canvas_1
If evenp = #PB_EventType_LeftButtonDown Or (evenp = #PB_EventType_MouseMove And GetGadgetAttribute(#Canvas_1, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
lMosY.l = GetGadgetAttribute(#Canvas_1, #PB_Canvas_MouseY)
If lMosY < 0
lMosY = 0
Else
If lMosY > #COLOR_SPECTRUM_SIZE_MAX
lMosY = #COLOR_SPECTRUM_SIZE_MAX
EndIf
EndIf
bCL = #COLOR_SPECTRUM_SIZE_MAX - lMosY
setDrawLum()
DrawHSLText()
DrawRGBText()
Retour_H = Val(GetGadgetText(#String_0))
Retour_S = Val(GetGadgetText(#String_1))
Retour_L = Val(GetGadgetText(#String_2))
Retour_R = Val(GetGadgetText(#String_3))
Retour_G = Val(GetGadgetText(#String_4))
Retour_B = Val(GetGadgetText(#String_5))
EndIf
Case #String_0
If evenp = #PB_EventType_Change
Retour_H = Val(GetGadgetText(#String_0))
If Retour_H < 0
Retour_H = 0
ElseIf Retour_H > 255
Retour_H = 255
EndIf
bCH = Retour_H
setDrawSpectre()
setDrawLum()
DrawRGBText()
;ElseIf evenp = #PB_EventType_LostFocus
; SetGadgetText(#String_0, Str(Retour_H))
EndIf
Case #String_1
If evenp = #PB_EventType_Change
Retour_S = Val(GetGadgetText(#String_1))
If Retour_S < 0
Retour_S = 0
ElseIf Retour_S > 255
Retour_S = 255
EndIf
bCS = Retour_S
setDrawSpectre()
setDrawLum()
DrawRGBText()
;ElseIf evenp = #PB_EventType_LostFocus
; SetGadgetText(#String_1, Str(Retour_S))
EndIf
Case #String_2
If evenp = #PB_EventType_Change
Retour_H = Val(GetGadgetText(#String_2))
If Retour_H < 0
Retour_H = 0
ElseIf Retour_H > 255
Retour_H = 255
EndIf
bCL = Retour_H
setDrawSpectre()
setDrawLum()
DrawRGBText()
;ElseIf evenp = #PB_EventType_LostFocus
; SetGadgetText(#String_2, Str(Retour_L))
EndIf
Case #String_3
If evenp = #PB_EventType_Change
;Debug GetGadgetText(#String_3)
Retour_R = Val(GetGadgetText(#String_3))
If Retour_R < 0
Retour_R = 0
ElseIf Retour_R > 255
Retour_R = 255
EndIf
RGBToHLS(Retour_R, Retour_G, Retour_B, @bCH, @bCL, @bCS)
setDrawSpectre()
setDrawLum()
DrawHSLText()
;ElseIf evenp = #PB_EventType_LostFocus
; SetGadgetText(#String_3, Str(Retour_R))
EndIf
Case #String_4
If evenp = #PB_EventType_Change
Retour_G = Val(GetGadgetText(#String_4))
If Retour_G < 0
Retour_G = 0
ElseIf Retour_G > 255
Retour_G = 255
EndIf
RGBToHLS(Retour_R, Retour_G, Retour_B, @bCH, @bCL, @bCS)
setDrawSpectre()
setDrawLum()
DrawHSLText()
;ElseIf evenp = #PB_EventType_LostFocus
; SetGadgetText(#String_4, Str(Retour_G))
EndIf
Case #String_5
If evenp = #PB_EventType_Change
Retour_B = Val(GetGadgetText(#String_5))
If Retour_B < 0
Retour_B = 0
ElseIf Retour_B > 255
Retour_B = 255
EndIf
RGBToHLS(Retour_R, Retour_G, Retour_B, @bCH, @bCL, @bCS)
setDrawSpectre()
setDrawLum()
DrawHSLText()
;ElseIf evenp = #PB_EventType_LostFocus
; SetGadgetText(#String_5, Str(Retour_B))
EndIf
EndSelect
EndIf
Until event = #PB_Event_CloseWindow
FreeImage(iImage)
EndIf
End
A vous de faire aussi un test voir si cela ne vent pas de ma machine.