library sdksample;

uses
  windows,graphics,gr32,dialogs,
  SysUtils;

// The init() function tells Samurize the names of the functions your source plugin provides.
// List them like so:
//	'Func1|Func2|...|FuncN'
// SOURCE PLUGINS ONLY
function init():PChar;stdcall;
begin
    Result:= 'helloworld';
end;


// getinfo() should return information about your plugin depending on the passed integer value.
// 0: Plugin name
// 1: Author name
// 2: Plugin version
// 3: Creation date
// 4: Last modified date
// 5: Website
// 6: Contact email address
//
// This information is displayed when the 'About' button is pressed in the config editor when your plugin
// is selected.
//
// This function is optional.
function getinfo(num:Integer):PChar; stdcall;
begin
    case num of
        0: Result := 'Sample Visualization plugin';
        1: Result := 'NeM';
        2: Result := '0.1';
        3: Result := '29/03/04';
        4: Result := '29/03/04';
        5: Result := 'http://www.samurize.com';
        6: Result := 'nem@samurize.com';
        else
            Result := '';
    end;
end;
	
	
// DLLType: Tells Samurize what type of plugin this is.
// because this dlltype() function is declared, Samurize will assume you are using the SDK v2.0;
// 	* All functions will be called with an additional first parameter, the meter's unique_id
//
// Omit the dlltype() function to use the old SDK (the uniqueID will be omitted)
//
// The value you should return is a summation of any or all of the following values:
// 1: Source plugin
// 2: Visual plugin
// ... (more to follow!)
function dlltype(): Integer;
begin
    // This plugin is a source and visual plugin, so we return 3 (1 + 2)
    result := 3;
end;
	

// dllstartup() is called every time Samurize creates a meter that uses this plugin.
// The 'hwnd' parameter is the window handle of the instance of Samurize that called this function.
// 'hwnd' will be 0 if called from the config editor.
// The 'dlltype' parameter indicates the plugin 'type' (1 for source plugins, 2 for visual plugins) being loaded.
// This function should return a unique integer ID that Samurize remembers and uses for other functions
// (this is so multiple instances of Samurize that use this do not conflict).
//
// Any memory allocation needed on a meter-by-meter basis should be done in this function.
//
// If your plugin is very simple and does not need to keep any global variables that may cause conflicts,
// just return 0 (or omit this function).
function dllstartup(hwnd : HWND; dlltype : Integer):Integer; stdcall;
begin
    // using the uptime is an ok (not perfect!) way of obtaining a unique ID
    result := gettickcount;
end;



// dllshutdown() is called every time a meter is destroyed by Samurize.
// The 'id' parameter is the uniqueID your plugin assigned to the meter (returned by dllstartup)
// This function should always return 0.
//
// Any memory releasing needed on a meter-by-meter basis should be done in this function.
//
// If your plugin does not need to free any memory, this function may be omitted.
function dllshutdown(id : Integer):Integer; stdcall;
begin
    //
    result := 0;
end;


// The getparam() function should return a list of the parameters that the passed function requires.
// Parameters are delimited by '|' characters. Note that there needs to be a final '|' after the last parameter.
// Appending '=' and then a value to the end of a parameter indicates the default value for that parameter.
// SOURCE PLUGINS ONLY
Function getparam(func: PChar):PChar;stdcall;
begin
    If func = 'helloworld' then
	Result := 'param1=1|param2=2|'
    else
	Result := '';
end;
    
// configure() is called when the user clicks on the "Plugin Settings" button in Samurize.
//
// You can display a popup dialog with global settings for your plugin (eg. a box prompting for
// your location for a weather plugin). These settings will be applied for all meters that use
// this source plugin.
//
// Note that it is your responsibility to save these settings to the registry/settings file/whatever - 
// they aren't stored by Samurize anywhere.
//
// SOURCE PLUGINS ONLY
function configure():Integer; stdcall;
begin
    ShowMessage('Place a configuration dialog here');
    Result := 0;
end;

    
// The one source plugin function defined for this plugin
// Note that because we are using the SDK 2.0, we add an extra
// integer value to the start of the parameter list.
function HelloWorld(id:integer; param1:pchar; param2:pchar): PChar; stdcall; export;
begin
    result := Pchar('Hello World!%bThe id of this meter is '+inttostr(id)+'.%bparam1='+param1+', param2='+param2);
end;


    


// repaint() is called every time Samurize refreshes its display.
// The parameters are:
//	h: 	the device context (HDC) for the bitmap you should draw on
//	id: 	the uniqueID assigned to the meter that is calling this function
//		(assigned by the dllstartup() function)
//	value: 	the value of the meter in string form (eg. '20', 'Some text')
//	width:	the width of the bitmap
//	height:	the height of the bitmap
//
// The bitmap you are drawing on is a 32-bit bitmap with alpha channel. Thus if you use GDI
// functions to draw, the alpha will be 0 and you will see nothing. You can either use
// GDI+ (supports transparency) or a custom library such as the graphics32 library for Delphi
// (this plugin uses the graphics32 library).
//
// VISUAL PLUGINS ONLY
Function repaint(h:hDC; id:Integer; Value:PChar; width,height:integer):Integer;stdcall;
var
    bmp : TBitmap32;
    val : extended;
begin

    // create a temporary bitmap to draw to
    bmp := TBitmap32.Create;

    // convert value to a usable floating point number
    val := strtofloat(value);

    // set bitmap size
    bmp.SetSize(width,height);

    // create a white background
    bmp.clear(gr32.clTrWhite32);

    // draw a vertical line kinda like a progressbar
    bmp.LineF(val/100*width,0,val/100*width,height, gr32.clGreen32);

    // draw the temporary bitmap to the passed DC
    bmp.DrawTo(h, 0,0);

    // free the temporary bitmap
    bmp.Free;

    result := 0;
end;

// vis_configure() is called when the user clicks on the "Configure..." button in Samurize.
// 'id' is the meter's unique id returned to Samurize by the dllstartup() function - this is the
// meter that is being configured.
//
// You can display some kind of popup window that allows users to specify various display settings
// for this visual plugin. Note that you need to store the settings for each meter individually for
// saving later on.
//
// This function is optional - if it is not provided, you will not be able to specify settings
// on a meter-by-meter basis.
//
// VISUAL PLUGINS ONLY
function vis_configure(id : Integer):Integer; stdcall;
begin
    //
    result := 0;
end;

// load_settings() is called when the config is loaded from file in the config editor
// or the clients. Your plugin should load its settings from the given section of the
// specified config file.
//
//	id:		the unique ID assigned to the meter by the dllstartup() function
//	inifile:	the full path to the config file
//	section:	the section of the config file where the values are listed
//
// VISUAL PLUGINS ONLY
function load_settings(id:Integer; inifile:PChar; section:PChar):Integer; stdcall;
begin
    //
    result := 0;
end;

// save_settings() is called when the config is being saved by the config editor.
// Your plugin should save its settings to the given section of the specified config file.
//	id:		the unique ID assigned to the meter by the dllstartup() function
//	inifile:	the full path to the config file
//	section:	the section of the config file where the values should be saved
//
// VISUAL PLUGINS ONLY
function save_settings(id:Integer; inifile:PChar; section:PChar):Integer; stdcall;
begin
    //
    result := 0;
end;


exports dllstartup name 'dllstartup';
exports dllshutdown name 'dllshutdown';
exports helloworld name 'helloworld';
exports vis_configure name 'vis_configure';
exports configure name 'configure';
exports load_settings name 'load_settings';
exports save_settings name 'save_settings';
exports getinfo name 'getinfo';
exports Repaint name 'repaint';
exports Init name 'init';
exports DLLType name 'dlltype';
exports getparam name 'getparam';
begin

end.


