unit mood_unit;  {a test bed for using controls for measuring items}interface	function use_slider (Dialog_id, slider_id, Item_id: integer): integer;  {show an elevator bar and return the value selected}	procedure use_multiple_sliders (Dialog_id, slider_id: integer; var results: mood_type);  {show an elevator bar and return the value selected}implementation	var		slider: integer;		tempnum: integer;		g_Dialog: DialogPtr;		data: array[1..number_sliders] of integer;		used: array[1..number_sliders] of boolean;	function use_slider; {(Dialog_id, slider_id, Item_id: integer):integer}  {show an elevator bar and return the value selected}		var			gSettings_Dialog, Dialog_Pointer: DialogPtr;			theEvent: eventRecord;			dummy: boolean;			itemtype, itemtype_count: integer;			itemRect, itemRect_count: Rect;			itemHandle, itemHandle_count: Handle;			itemString: str255;			tempnum: integer;			itemhit: integer;			Dialogdone: boolean;			value: string;			ContrlValue, Controlresult: integer;			thePoint: point;			WhichWindow: windowPtr;			where, CtrlMin, CtrlMax, which, range, left, right, desired: integer;			scale: real;	begin		Dialog_pointer := GetNewDialog(Dialog_id, nil, WindowPtr(-1));		showWindow(Dialog_pointer); {make this window the active window}		DialogDone := false;		CtrlMin := 0;		CtrlMax := 100;		while DialogDone = false do			begin				if getNextEvent(everyevent, theEvent) then   {we want to use controls, so therefore we need to not use a modeless dialog}					begin						if (isDialogEvent(theEvent)) then							dummy := DialogSelect(theevent, gSettings_Dialog, itemhit);						if itemHit = 1 then							dialogDone := true						else if ItemHit = slider_id then   {this is the slider control}							begin								where := FindDItem(gSettings_Dialog, thePoint);   {this should be the location, in local coordinates of the mouse}								ThePoint := theEvent.where; {this really is the point, in local coordinates!!}								GetDItem(gSettings_Dialog, ItemHit, itemtype, itemHandle, itemRect);  {find out where the bar is}								ContrlValue := GetCtlValue(ControlHandle(itemHandle));  {get the value of the handle}{Controlresult := FindControl(thepoint, gSettings_Dialog, controlHandle(itemHandle)); } {make the buttons work}{A kludge to make the button work -- we know we are in the right dialog, we know where the mouse is, now figure things out}								left := ItemRect.left + 20;								right := itemRect.right - 20;								range := right - left;								scale := range / (CtrlMax - CtrlMin);								desired := round((ThePoint.h - left) / range * (CtrlMax - CtrlMin));								if ThePoint.h < left then    {we are in the left arrow box}									ControlResult := 1								else if ThePoint.h > right then   {the right arrow box}									ControlResult := 2								else if (desired > ContrlValue - 2) and (desired < ContrlValue + 2) then									ControlResult := 5  {we are right there, just track the damn thing}								else if desired < ContrlValue - 3 then									ControlResult := 3   {to the left of the location}								else if desired > ContrlValue + 3 then									ControlResult := 4;   {to the right of the location}								case controlresult of									3, 4: 										ContrlValue := desired;									1:     {move right or down}										begin											if ContrlValue > CtrlMin then												ContrlValue := ContrlValue - 1;										end;									2:     {move right or down}										begin											if ContrlValue < CtrlMax then												ContrlValue := ContrlValue + 1;										end;									5: 										begin											Controlresult := FindControl(thepoint, gSettings_Dialog, controlHandle(itemHandle));											GetDItem(gSettings_Dialog, ItemHit, itemtype, itemHandle, itemRect);  {find out where the bar is}											ContrlValue := GetCtlValue(ControlHandle(itemHandle));  {get the value of the handle}										end;								end; {case}								GetDItem(gSettings_Dialog, ItemHit, itemtype, itemHandle, itemRect);  {find out where the bar is}								SetCtlValue(controlHandle(itemHandle), ContrlValue);								GetDItem(Dialog_pointer, item_id, itemtype_count, itemHandle_count, itemRect_count); {show the value in item_id}								NumtoString(ContrlValue, itemString);								SetIText(itemHandle_count, itemString);							end;  {else it is a slider}					end;  {while dialogdone}				begin				end;			end; {checking to see if a dialog event has occured}		use_slider := contrlvalue;		disposeWindow(Dialog_pointer);	end;	procedure use_multiple_sliders {(Dialog_id, slider_id: integer; var results: mood_type); } {show an elevator bar and return the value selected}		var			gSettings_Dialog, Dialog_Pointer: DialogPtr;			theEvent: eventRecord;			dummy: boolean;			itemtype, itemtype_count: integer;			itemRect, itemRect_count: Rect;			itemHandle, itemHandle_count: Handle;			itemString: str255;			tempnum: integer;			itemhit: integer;			Dialogdone: boolean;			value: string;			ContrlValue, Controlresult: integer;			thePoint: point;			WhichWindow: windowPtr;			where, CtrlMin, CtrlMax, which, range, left, right, desired: integer;			scale: real;			loop: integer;	begin		for loop := 1 to number_sliders do			used[loop] := false;		Dialog_pointer := GetNewDialog(Dialog_id, nil, WindowPtr(-1));		showWindow(Dialog_pointer); {make this window the active window}		DialogDone := false;		CtrlMin := 0;		CtrlMax := 100;		while DialogDone = false do			begin				if getNextEvent(everyevent, theEvent) then   {we want to use controls, so therefore we need to not use a modeless dialog}					begin						if (isDialogEvent(theEvent)) then							dummy := DialogSelect(theevent, Dialog_pointer, itemhit);						if itemHit = 1 then							dialogDone := true						else if (itemhit > 1) and (itemhit < 10) then  {this is the slider control}							begin								where := FindDItem(Dialog_pointer, thePoint);   {this should be the location, in local coordinates of the mouse}								ThePoint := theEvent.where; {this really is the point, in local coordinates!!}								GetDItem(Dialog_pointer, ItemHit, itemtype, itemHandle, itemRect);  {find out where the bar is}								ContrlValue := GetCtlValue(ControlHandle(itemHandle));  {get the value of the handle}{A kludge to make the button work -- we know we are in the right dialog, we know where the mouse is, now figure things out}								left := ItemRect.left + 10;								right := itemRect.right - 10;								range := right - left;								scale := range / (CtrlMax - CtrlMin);								desired := round((ThePoint.h - left) / range * (CtrlMax - CtrlMin));								if ThePoint.h < left then    {we are in the left arrow box}									ControlResult := 1								else if ThePoint.h > right then   {the right arrow box}									ControlResult := 2								else if (desired > ContrlValue - 1) and (desired < ContrlValue + 1) then									ControlResult := 5  {we are right there, just track the damn thing}								else if desired < ContrlValue then									ControlResult := 3   {to the left of the location}								else if desired > ContrlValue then									ControlResult := 4;   {to the right of the location}								case controlresult of									3, 4: 										ContrlValue := desired;									1:     {move right or down}										begin											if ContrlValue > CtrlMin then												ContrlValue := ContrlValue - 1;										end;									2:     {move right or down}										begin											if ContrlValue < CtrlMax then												ContrlValue := ContrlValue + 1;										end;									5: 										begin											Controlresult := FindControl(thepoint, gSettings_Dialog, controlHandle(itemHandle));											GetDItem(gSettings_Dialog, ItemHit, itemtype, itemHandle, itemRect);  {find out where the bar is}											ContrlValue := GetCtlValue(ControlHandle(itemHandle));  {get the value of the handle}										end;								end; {case}								GetDItem(Dialog_pointer, ItemHit, itemtype, itemHandle, itemRect);  {find out where the bar is}								SetCtlValue(controlHandle(itemHandle), ContrlValue);								data[itemhit - 1] := contrlValue;								used[itemhit - 1] := true;							end;  {else it is a slider}					end;  {while dialogdone}				begin				end;			end; {checking to see if a dialog event has occured}		hideWindow(Dialog_pointer);		for loop := 1 to number_sliders do			begin				results[loop] := data[loop];			end;	end;end.