'------------------------------Окно настроек-------------------------------------

Sub Obj.OptionWindow()
	OptionhWnd=OpenWindow("Настройки скриншота", 300, 200, 492, 350 ,WS_POPUP)
	WindowColor(a.OptionhWnd,&h7D828E):CenterWindow(OptionhWnd)
	SpinGadget(spinWidth, 26, 81, 70, 20, 1, 5000,SaveLoad.Width,,ES_CENTER)
	SpinGadget(spinHeight, 136, 81, 70, 20, 1, 5000,SaveLoad.height,,ES_CENTER)
	GroupGadget(GroupSize,10,20,230,170,"Размеры:")
	GroupGadget(GroupFormat,250,20,230,170,"Опции скриншота:")
	GroupGadget(GroupPATH,10,210,470,120,"Путь для сохранения:")
	ButtonGadget(ButtonOK, 335, 290, 60, 20, "Принять")
	ButtonGadget(ButtonChangePATH, 425, 241, 30, 25, "...")
	ButtonGadget(ButtonCancel, 100, 290, 60, 20, "Отмена")
	TextGadget(TextWidth, 35, 60, 70, 20, "Ширина")
	TextGadget(TextHeight, 145, 60, 70, 20, "Высота")
	StringGadget(StringGadgetPATH, 30, 241, 390, 25,SaveLoad.path,ES_AUTOHSCROLL,WS_EX_CLIENTEDGE)
	CheckBoxGadget(CheckBoxReal, 30, 130, 180, 50, "Реальный размер окон (регулировка размеров не действует)",3 Or BS_MULTILINE)
	CheckBoxGadget(CheckBoxReplace, 280, 130, 180, 50, "Перезаписывать сохраняемый файл скриншота каждый раз",3 Or BS_MULTILINE)
	OptionGadget(OptionJPEG, 275, 60, 55, 20, "JPEG")
	OptionGadget(OptionJPG, 343, 60, 55, 20, "JPG")
	OptionGadget(OptionTIFF, 411, 60, 55, 20, "TIFF")
	OptionGadget(OptionPNG, 260, 90, 55, 20, "PNG")
	OptionGadget(OptionBMP, 316, 90, 55, 20, "BMP")
	OptionGadget(OptionICO, 372, 90, 50, 20, "ICO")
	OptionGadget(OptionGIF, 423, 90, 55, 20, "GIF")
	SetGadgetState(CheckBoxReal,SaveLoad.real)
	SetGadgetState(CheckBoxReplace,SaveLoad.rewrite)
	For a As Integer=OptionJPEG To OPtionICO
		If formatimage(a)=SaveLoad.Format Then
			SetGadgetState(a,1)
		EndIf
	Next
	For a As Integer=spinWidth To OPtionICO
		SetGadgetColor(a,&h7D828E,&hffffff,1)
	Next
End Sub

'Функция, отвечающая за сохранение и загрузку настроек скриншота по умолчанию

Function Obj.SaveLoadOption(flag As bool,flagWindow As bool=1) As Integer
	If flag = 0 Then ' чтение
		If OpenFBini("U1.ini")<>-1 Then
			SaveLoad.path=ReadStringValueFBini("Option","path")
			SaveLoad.real=ReadByteValueFBini("Option","real")
			SaveLoad.rewrite=ReadByteValueFBini("Option","rewrite")
			SaveLoad.Width=ReadIntegerValueFBini("Option","width")
			SaveLoad.height=ReadIntegerValueFBini("Option","height")
			SaveLoad.Format=ReadStringValueFBini("Option","format")
			CloseFBini()
		Else
			SaveLoadOption(1,0)
		EndIf
	Else ' запись

		If flagWindow=1 Then '<- запущено ли окно с настройками?
			SaveLoad.path=GetGadgetText(StringGadgetPATH)
			SaveLoad.real=GetGadgetState(CheckBoxReal)
			SaveLoad.rewrite=GetGadgetState(CheckBoxReplace)
			SaveLoad.Width=GetGadgetState(spinWidth)
			SaveLoad.height=GetGadgetState(spinHeight)
			For a As Integer=OptionJPEG To OPtionICO
				If GetGadgetState(a)=1 Then
					SaveLoad.Format=formatimage(a)
				EndIf
			Next
		EndIf

		'------по умолчанию-------
		If SetCurentDir(SaveLoad.path)=0 Then
			SaveLoad.path=ExePath
		Else
			SetCurentDir(ExePath)
		EndIf
		If SaveLoad.Width=0 Then SaveLoad.Width=640
		If SaveLoad.height=0 Then SaveLoad.height=480
		If SaveLoad.Format="" Then SaveLoad.Format=".bmp"
		'----------------------------------

		If CreateFBini("U1.ini")<> -1 Then
			WriteGroupFBini("Option")
			WriteValueFBini("Option","path",SaveLoad.path)
			WriteValueFBini("Option","real",Cast(Byte,SaveLoad.real))
			WriteValueFBini("Option","rewrite",Cast(Byte,SaveLoad.rewrite))
			WriteValueFBini("Option","width",Cast(Integer,SaveLoad.Width))
			WriteValueFBini("Option","height",Cast(Integer,SaveLoad.height))
			WriteValueFBini("Option","format",SaveLoad.Format)
			CloseFBini()
			Return 1
		EndIf
	EndIf	
End Function