#include <libraries/mui.h> 
#include <clib/alib_protos.h>
#include <clib/muimaster_protos.h>
#include <pragma/muimaster_lib.h>
#include <clib/exec_protos.h>
#include <exec/types.h>
#include "vugui.h"

#include <stdio.h>

#define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))

extern Library *MUIMasterBase;

VuGUI::VuGUI(){
	if(MUIMasterBase=OpenLibrary("muimaster.library",0)){
		app = ApplicationObject,                                                                 
 	    	MUIA_Application_Title,                         "VuGUI",                         
        	MUIA_Application_Version,                       "$VER: OmegaInput 0.01 (15/01/2000)",    
        	MUIA_Application_Copyright,                     "©2000 T.Miles",
        	MUIA_Application_Author,                        "Tom Miles",                
        	MUIA_Application_Description,           			"Eye Candy Fever",                 
        	MUIA_Application_Base,                          "VU", 
        	MUIA_Application_UseCommodities,						FALSE,
        	MUIA_Application_UseRexx,								FALSE,                        
			SubWindow, wi_main = WindowObject,               
        		MUIA_Window_ID, MAKE_ID('M','A','I','N'),
        		MUIA_Window_Title,"VU Prefs",
        		WindowContents, VGroup,
        			Child, TextObject,
        				MUIA_Text_Contents, "Select Number of Bars",
        				End,
        			Child, sl_bars=SliderObject,
        				MUIA_Group_Horiz, TRUE,
        				MUIA_Slider_Min, 1,
        				MUIA_Slider_Max, 25,
        				End,
        			Child, HGroup,
        				Child, bt_save=SimpleButton("_Save"),
        				Child, bt_use=SimpleButton("_Use"),
        				Child, bt_load=SimpleButton("_Load"),
        			End,
        		End,
        	End,
      End;
		
		if (!app)
			printf("Error Creating gui\n");
		else{
			DoMethod((Object *)wi_main,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,ID_CANCEL);
			DoMethod((Object *)bt_use,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,ID_USE);
			DoMethod((Object *)bt_save,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,ID_SAVE);
			DoMethod((Object *)bt_load,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,ID_LOAD);
		}
	}
}

VuGUI::~VuGUI(){
	if (app)
		MUI_DisposeObject((Object *)app);
	if (MUIMasterBase)
		CloseLibrary(MUIMasterBase);
}	

void VuGUI::gui_OpenWin(){
	SetAttrs(wi_main, MUIA_Window_Open, TRUE);
}

void VuGUI::gui_CloseWin(){
	SetAttrs(wi_main, MUIA_Window_Open, FALSE);
}
	
ULONG VuGUI::gui_GetSliderValue(){
	ULONG val;
	
	GetAttr(MUIA_Slider_Level, sl_bars, &val);
	return val;
}	

void VuGUI::gui_SetSliderValue(UINT val){
	SetAttrs(sl_bars, MUIA_Slider_Level,val);
} 