/*
    lsadl is a frontend/wrapper to the adl_sdk using gtk
    Copyright (C) 2011  Sterling Pickens

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LS_GTK_H
#define LS_GTK_H 1

#include <stdio.h>
#include <stdlib.h>
//#include <stdint.h>
#include <string.h>
#include <gtk/gtk.h>
#include <pango/pango.h>
#include <math.h>
#include "config.h"
#include "Globals.h"
#include "ls_pth.h"
#include "adl_api.h"

#define START_GPU 500
#define START_MEM 800
#define MIN_GPU 275
#define MIN_MEM 400
#define MAX_GPU 740
#define MAX_MEM 1100

#ifndef TRUE
#define TRUE 0
#endif
#ifndef FALSE
#define FALSE 1
#endif

extern int No_Exit;
extern const char *ADL_Func_Names[LSADL_FUNCS];
extern char ADL_Func_Enabled[LSADL_FUNCS];
extern char ADL_Func_Notes[LSADL_FUNCS];
struct ADLMemoryInfo lpADLMemoryInfo;
struct AdapterInfo *lpAdapterInfo;
extern int iNumberAdapters;
extern ADLTemperature iTemperature;
extern int iAdapterIndex;
//extern struct OverDrive5s od5;
//extern int PerfLevels;

struct GTK_Widgets{
	GtkWidget *main_win;
	GtkWidget *main_vbox;
	GtkWidget *main_menubar;
	GtkWidget *main_filemenu;
	GtkWidget *main_file;
	GtkWidget *main_results;
	GtkWidget *main_quit;
	GtkWidget *scrolled_win;
	GtkWidget *table;
	GtkWidget *fixed1;
	GtkWidget *table_labels[17];
	GtkWidget *load_b;
	GtkWidget *save_b;
	GtkWidget *unlock_box;
	GtkWidget *ca_labels[11];
	GtkWidget *combo_box;

	GtkWidget *notebook;
	GtkWidget *notebook_label1;
	GtkWidget *notebook_label2;
	GtkWidget *notebook_page1;
	GtkWidget *notebook_page2;
//	GtkWidget *graph_labels[4];
//	GtkWidget *graph_table;
//	GtkWidget *graph_perf;
//	GtkWidget *graph_usage;
//	GtkWidget *graph_fan;
//	GtkWidget *graph_temp;
	GtkWidget *graph;
	GtkWidget *graph_scroll;

//	GtkWidget *gpu_cur_label;
//	GtkWidget *mem_cur_label;
//	GtkWidget *temp_cur_label;

	//GtkWidget *events;
//	GtkWidget **apply_button;

//	GtkAdjustment **gpu_adj;
//	GtkAdjustment **mem_adj;
//	GtkAdjustment **vddc_adj;
//	GtkAdjustment **fan_adj;

//	GtkWidget **mem_button;
//	GtkWidget **gpu_button;
//	GtkWidget **vddc_button;
//	GtkWidget **fan_button;
};

struct PERF_Cur{
	int id;
	gdouble gpu;
	gdouble mem;
	gdouble vddc;
	gint powercontrol;
	gint fan;
    GtkWidget *gpu_b;
    GtkWidget *mem_b;
    GtkWidget *vddc_b;
	GtkWidget *powercontrol_b;
    GtkWidget *fan_b;
    GtkAdjustment *gpu_adj;
    GtkAdjustment *mem_adj;
    GtkAdjustment *vddc_adj;
	GtkAdjustment *powercontrol_adj;
    GtkAdjustment *fan_adj;
	GtkWidget *powercontrol_set_b;
	GtkWidget *powercontrol_reset_b;
	GtkWidget *fan_set_b;
	GtkWidget *fan_reset_b;
	GtkWidget *apply_b;
	GtkWidget *table_labels;
};

struct PERF_Ranges{
	gdouble mem_min;
	gdouble mem_max;
	gdouble mem_step;
	gdouble mem_cur;
	gdouble gpu_min;
	gdouble gpu_max;
	gdouble gpu_step;
	gdouble gpu_cur;
	gdouble vddc_min;
	gdouble vddc_max;
	gdouble vddc_step;
	gdouble vddc_cur;
	gint def_force3d;
	gint cur_force3d;
	gint pc_min;
	gint pc_max;
	gint pc_step;
	gint pc_cur;
	gint fan_min;
	gint fan_max;
	gint fan_step;
	gint fan_cur;
};




extern const char *ADL_Func_Names[LSADL_FUNCS];
extern char ADL_Func_Enabled[LSADL_FUNCS];
extern char ADL_Func_Notes[LSADL_FUNCS];

char Perf_Alloc(void);
char Perf_Dealloc(void);
void *Refresh_Func(void *empty);
void *GTK_Func(void *empty);

//callbacks
gboolean apply_cb(GtkWidget *widget, gpointer data);
gboolean set_fanspeed_cb(GtkWidget *widget, gpointer data);
gboolean reset_fanspeed_cb(GtkWidget *widget, gpointer data);
gboolean set_powercontrol_cb(GtkWidget *widget, gpointer data);
gboolean reset_powercontrol_cb(GtkWidget *widget, gpointer data);
gboolean exit_cb(GtkWidget *widget, gpointer data);
gboolean API_Funcs_Found_Popup_cb(GtkWidget *widget, gpointer data);
#ifndef USING_GTK_3
void on_expose_cairo(GtkWidget *widget, GdkEventExpose *event, gpointer data);
#else
void on_expose_cairo(GtkWidget *widget, CairoContext *cr, gpointer data);
#endif

#endif