;{ константы ID
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#Image_0
#Image_1
#Image_50
#TrackBar_0
#Button_0
#Button_1
#Text_0
#Text_1
#Text_3
#Text_4
#CheckBox_0
#CheckBox_1
#CheckBox_2
EndEnumeration
;- Fonts
Global FontID1
FontID1 = LoadFont(1, "Arial", 16)
Global FontID2
FontID2 = LoadFont(2, "Arial", 12)
;}
Procedure Simulate_GadgetEvent(Gadget, EventType)
Protected wp=Gadget+EventType<<(SizeOf(Word)*8)
Protected lp=GadgetID(Gadget)
;get parent window
Protected win=GetParent_(GadgetID(Gadget))
While GetParent_(win) : win=GetParent_(win) : Wend
;send message to window
PostMessage_(win, #WM_COMMAND, wp, lp)
EndProcedure
Procedure Im_CallBack(hwnd, msg, wParam, lParam)
*PointOldImFunc=GetWindowLong_(hWnd,#GWL_USERDATA)
If msg=#WM_LBUTTONDOWN
Simulate_GadgetEvent(GetDlgCtrlID_(hwnd), #PB_EventType_LeftClick)
EndIf
ProcedureReturn CallWindowProc_(*PointOldImFunc,hwnd, msg, wParam, lParam)
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Window_0, 392, 181, 840, 600, "Цвето_восприятие", #PB_Window_SystemMenu | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Window_0))
CreateImage(#Image_50, 840, 320)
ImageGadget(#Image_50, 0, 0, 840, 320, Image0, #PB_Image_Border)
TrackBarGadget(#TrackBar_0, 40, 500, 170, 40, 0, 10, #PB_TrackBar_Ticks)
;DisableGadget(#Image_50,1)
CreateImage(#Image_0, 400, 300)
ImageGadget(#Image_0, 10, 10, 400, 300, Image0);, #PB_Image_Border)
SetParent_(GadgetID(#Image_0), GadgetID(#Image_50))
*Func=GetWindowLong_(GadgetID(#Image_0), #GWL_WNDPROC)
SetWindowLong_(GadgetID(#Image_0),#GWL_USERDATA, *Func)
SetWindowLong_(GadgetID(#Image_0), #GWL_WNDPROC, @Im_CallBack())
CreateImage(#Image_1, 400, 300)
;ImageGadget(#Image_1, 430, 10, 400, 300, Image1, #PB_Image_Border)
ButtonGadget(#Button_0, 30, 420, 190, 70, "Случайный цвет")
SetGadgetFont(#Button_0, FontID1)
ButtonGadget(#Button_1, 560, 420, 190, 70, "Подобрать цвет")
SetGadgetFont(#Button_1, FontID1)
TextGadget(#Text_0, 7, 340, 420, 40, "Сгенерированный цвет:")
SetGadgetFont(#Text_0, FontID1)
TextGadget(#Text_1, 440, 340, 420, 40, "Выбраный цвет:")
SetGadgetFont(#Text_1, FontID1)
TextGadget(#Text_3, 320, 380, 390, 40, "Пипетка: ")
SetGadgetFont(#Text_3, FontID1)
TextGadget(#Text_4, 40, 540, 390, 40, "Шаг изменения: 0 ")
SetGadgetFont(#Text_4, FontID1)
CheckBoxGadget(#CheckBox_0, 260, 430, 60, 30, "Red")
SetGadgetFont(#CheckBox_0, FontID2)
CheckBoxGadget(#CheckBox_1, 260, 470, 70, 40, "Green")
SetGadgetFont(#CheckBox_1, FontID2)
CheckBoxGadget(#CheckBox_2, 260, 510, 70, 40, "Blue")
SetGadgetFont(#CheckBox_2, FontID2)
EndIf
HideWindow(#Window_0, 1)
EndIf
EndProcedure
Procedure Zalivka_Box (ID, R,G,B)
If IsImage(ID) ; Существует ли рисунок с таким ID
W = ImageWidth(ID)
H = ImageHeight(ID)
If StartDrawing(ImageOutput(ID))
Box(0, 0, W,H, RGB(R, G, B))
StopDrawing()
SetGadgetState(ID, ImageID(ID))
EndIf
EndIf
EndProcedure
Open_Window_0()
HideWindow(#Window_0, 0)
;{Основной цикл
Repeat
Event = WaitWindowEvent()
EventType = EventType()
Gadget = EventGadget()
If Event=#PB_Event_Gadget
If Gadget=#TrackBar_0
Result = GetGadgetState(#TrackBar_0)
SetGadgetText(#Text_4,"Шаг изменения: "+Str(Result))
ElseIf Gadget=#Button_0
If GetGadgetState(#CheckBox_0)=1
a=Random(255)
While a+Result>255
a=Random(255)
Wend
EndIf
If GetGadgetState(#CheckBox_1)=1
b=Random(255)
While b+Result>255
b=Random(255)
Wend
EndIf
If GetGadgetState(#CheckBox_2)=1
c=Random(255)
While c+Result>255
c=Random(255)
Wend
EndIf
Zalivka_Box (#Image_50, a,b,c)
;SmartWindowRefresh(#Window_0, 1) ;Уменьшает мерцание окна
Zalivka_Box (#Image_0, a+Result,b+Result,c+Result)
;SmartWindowRefresh(#Window_0, 1)
SetGadgetText(#Text_0,"Сгенерированный цвет: RGB("+Str(a)+":"+Str(b)+":"+Str(c)+")")
If IsGadget(#Image_1)
Zalivka_Box (#Image_1, Red(color),Green(color),Blue(color))
;SmartWindowRefresh(#Window_0, 1)
EndIf
ElseIf Gadget=#Button_1
color=ColorRequester()
If color> -1
If IsGadget(#Image_1)=0
ImageGadget(#Image_1, 430, 10, 400, 300, Image1, #PB_Image_Border)
SetParent_(GadgetID(#Image_1), GadgetID(#Image_50))
*Func=GetWindowLong_(GadgetID(#Image_1), #GWL_WNDPROC)
SetWindowLong_(GadgetID(#Image_1),#GWL_USERDATA, *Func)
SetWindowLong_(GadgetID(#Image_1), #GWL_WNDPROC, @Im_CallBack())
EndIf
Zalivka_Box (#Image_1, Red(color),Green(color),Blue(color))
SetGadgetText(#Text_1,"Выбраный цвет: RGB("+Str(Red(color))+":"+Str(Green(color))+":"+Str(Blue(color))+")")
EndIf
ElseIf Gadget=#Image_0 Or Gadget=#Image_1 ; <= Здесь вроде условие на однинарный клик мышки...???
StartDrawing(ImageOutput(Gadget))
Cvet = Point(5, 5)
SetGadgetText(#Text_3,"Пипетка: RGB("+Str(Red(Cvet))+":"+Str(Green(Cvet))+":"+Str(Blue(Cvet))+")")
StopDrawing()
If Gadget=#Image_1
If EventType=#PB_EventType_LeftDoubleClick
SetWindowLong_(GadgetID(#Image_1), #GWL_WNDPROC, GetWindowLong_(GadgetID(#Image_1),#GWL_USERDATA))
FreeGadget(#Image_1)
EndIf
EndIf
EndIf
EndIf
Until Event=#PB_Event_CloseWindow
;}
End