It is currently December 15th, 2019, 11:40 am

Searching for a plugin.

Help with creating, editing & fixing problems with skins
dvo
Posts: 657
Joined: February 7th, 2016, 6:08 am

Re: Searching for a plugin.

dvo » March 20th, 2018, 9:23 pm

that's way to high for me... can't help you with this... :17flag
User avatar
kyriakos876
Posts: 915
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Searching for a plugin.

kyriakos876 » March 20th, 2018, 9:37 pm

After searching around, I don't think the plugin supports the check of a set place on my screen but only follows the mouse.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 3645
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Searching for a plugin.

eclectic-tech » March 20th, 2018, 10:02 pm

kyriakos876 wrote:After searching around, I don't think the plugin supports the check of a set place on my screen but only follows the mouse.
Auto-It has a function to do this...
Function Reference;;_WinAPI_GetPixel;;_WinAPI_GetPixel Retrieves the color value of the pixel at the specified coordinates #include <WinAPIGdi.au3> _WinAPI_GetPixel ( $hDC, $iX, $iY ) Parameters $hDC Handle to the device context. $iX The x-coordinate, in logical units, of the pixel to be examined. $iY The y-coordinate, in logical units, of the pixel to be examined. Return Value Success: The color of the pixel, in RGB. Failure: (-1).
Someone who is familiar with Auto-It may be able to provide more help, I am not that qualified in Auto-It coding... :p
User avatar
kyriakos876
Posts: 915
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Searching for a plugin.

kyriakos876 » March 20th, 2018, 10:15 pm

eclectic-tech wrote:Auto-It has a function to do this...
Function Reference;;_WinAPI_GetPixel;;_WinAPI_GetPixel Retrieves the color value of the pixel at the specified coordinates #include <WinAPIGdi.au3> _WinAPI_GetPixel ( $hDC, $iX, $iY ) Parameters $hDC Handle to the device context. $iX The x-coordinate, in logical units, of the pixel to be examined. $iY The y-coordinate, in logical units, of the pixel to be examined. Return Value Success: The color of the pixel, in RGB. Failure: (-1).
Someone who is familiar with Auto-It may be able to provide more help, I am not that qualified in Auto-It coding... :p
I'm no Auto-It expert either, but wouldn't that be checking only one time? I want it to check every (specific amount of time)
dvo
Posts: 657
Joined: February 7th, 2016, 6:08 am

Re: Searching for a plugin.

dvo » March 20th, 2018, 10:25 pm

User avatar
jsmorley
Developer
Posts: 19870
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Searching for a plugin.

jsmorley » March 20th, 2018, 10:38 pm

AutoIt, or any other external application, is not the way to go here. Running an entirely external application once a second is going to be tough on the CPU, have a constant "busy" cursor showing, and is just about the most inefficient way you can think of to do this.

This needs to be a plugin, in either C++ or C#
User avatar
kyriakos876
Posts: 915
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Searching for a plugin.

kyriakos876 » March 20th, 2018, 10:56 pm

jsmorley wrote:AutoIt, or any other external application, is not the way to go here. Running an entirely external application once a second is going to be tough on the CPU, have a constant "busy" cursor showing, and is just about the most inefficient way you can think of to do this.

This needs to be a plugin, in either C++ or C#
I was kinda hoping to avoid writing another plugin as I've done with so many things but I guess that's gonna be the case this time too... Anyway, thanks everyone for replying!
User avatar
jsmorley
Developer
Posts: 19870
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Searching for a plugin.

jsmorley » March 21st, 2018, 4:48 am

Here is a better 1.1.0 version of the plugin.
PluginPixelColor.zip
It is now used as a [Section Variable] anywhere in the skin. The measure itself no longer returns any value.

The syntax is:

[&MeasureName:PixelRGB(xVal,yVal)] : Returns the RGB color at the defined X and Y, as in 255,100,50
[&MeasureName:PixelRED(xVal,yVal)] : Returns the RED component of the color at the defined X and Y, as in 255
[&MeasureName:PixelGREEN(xVal,yVal)] : Returns the GREEN component of the color at the defined X and Y, as in 100
[&MeasureName:PixelBLUE(xVal,yVal)] : Returns the BLUE component of the color at the defined X and Y, as in 50

Note that as of this writing, you may not use (formulas) in the parameters to the function call(s). This may change in the future. You would have to calculate the number in a separate Calc measure, and then use the value in the parameter as a [&CalcMeasure] section variable.

[&PluginHostMeasure:PixelRGB([&CalcXMeasure],100)]

Skin:

Code: Select all

[Rainmeter]
Update=100
DynamicWindowSize=1
AccurateText=1

[MeasureColor]
Measure=Plugin
Plugin=PixelColor
Disabled=1

[MeterColor]
Meter=String
X=1
FontSize=11
FontWeight=400
FontColor=[&MeasureColor:PixelRGB([#CURRENTCONFIGX], [#CURRENTCONFIGY])]
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=[&MeasureColor:PixelRGB([#CURRENTCONFIGX], [#CURRENTCONFIGY])]
1.png
C++

Code: Select all

#include <string>
#include <stdio.h>
#include <Windows.h>
#include "../../API/RainmeterAPI.h"

WCHAR buffer[32];

enum Instance
{
	RGB,
	RED,
	GREEN,
	BLUE
};

struct Measure
{
	std::wstring returnedString;
	Instance type;
	void* rm;
	Measure() : type(RGB), rm() {};
	int xPos;
	int yPos;
};

PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
	Measure* measure = new Measure;
	*data = measure;
	measure->rm = rm;
}

PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
	Measure* measure = (Measure*)data;
}

PLUGIN_EXPORT double Update(void* data)
{
	Measure* measure = (Measure*)data;
	return 0.0;
}

//PLUGIN_EXPORT LPCWSTR GetString(void* data)
//{
//	Measure* measure = (Measure*)data;
//}

PLUGIN_EXPORT LPCWSTR PixelRGB(void* data, const int argc, const WCHAR* argv[])
{
	Measure* measure = (Measure*)data;

	if (argc == 2)
	{
		int xPos = _wtoi(argv[0]);
		int yPos = _wtoi(argv[1]);

		// Get the device context for the screen
		HDC hDC = GetDC(NULL);
		if (hDC == NULL) {
			RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error getting screen device handle");
			return nullptr;
		}

		// Retrieve the color at a position
		COLORREF color = GetPixel(hDC, xPos, yPos);
		if (color == CLR_INVALID) {
			RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error getting pixel color");
			return nullptr;
		}

		// Release the device context again
		ReleaseDC(GetDesktopWindow(), hDC);


		_snwprintf_s(buffer, _TRUNCATE, L"%i,%i,%i", GetRValue(color), GetGValue(color), GetBValue(color));

		return buffer;
	}

	//@TODO log error better
	RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error with arguments");
	return nullptr;
}
PLUGIN_EXPORT LPCWSTR PixelRed(void* data, const int argc, const WCHAR* argv[])
{
	Measure* measure = (Measure*)data;

	if (argc == 2)
	{
		int xPos = _wtoi(argv[0]);
		int yPos = _wtoi(argv[1]);

		// Get the device context for the screen
		HDC hDC = GetDC(NULL);
		if (hDC == NULL) {
			RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error getting screen device handle");
			return nullptr;
		}

		// Retrieve the color at a position
		COLORREF color = GetPixel(hDC, xPos, yPos);
		if (color == CLR_INVALID) {
			RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error getting pixel color");
			return nullptr;
		}

		// Release the device context again
		ReleaseDC(GetDesktopWindow(), hDC);


		_snwprintf_s(buffer, _TRUNCATE, L"%i", GetRValue(color));

		return buffer;
	}

	//@TODO log error better
	RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error with arguments");
	return nullptr;
}
PLUGIN_EXPORT LPCWSTR PixelGreen(void* data, const int argc, const WCHAR* argv[])
{
	Measure* measure = (Measure*)data;

	if (argc == 2)
	{
		int xPos = _wtoi(argv[0]);
		int yPos = _wtoi(argv[1]);

		// Get the device context for the screen
		HDC hDC = GetDC(NULL);
		if (hDC == NULL) {
			RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error getting screen device handle");
			return nullptr;
		}

		// Retrieve the color at a position
		COLORREF color = GetPixel(hDC, xPos, yPos);
		if (color == CLR_INVALID) {
			RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error getting pixel color");
			return nullptr;
		}

		// Release the device context again
		ReleaseDC(GetDesktopWindow(), hDC);


		_snwprintf_s(buffer, _TRUNCATE, L"%i", GetGValue(color));

		return buffer;
	}

	//@TODO log error better
	RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error with arguments");
	return nullptr;
}
PLUGIN_EXPORT LPCWSTR PixelBlue(void* data, const int argc, const WCHAR* argv[])
{
	Measure* measure = (Measure*)data;

	if (argc == 2)
	{
		int xPos = _wtoi(argv[0]);
		int yPos = _wtoi(argv[1]);

		// Get the device context for the screen
		HDC hDC = GetDC(NULL);
		if (hDC == NULL) {
			RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error getting screen device handle");
			return nullptr;
		}

		// Retrieve the color at a position
		COLORREF color = GetPixel(hDC, xPos, yPos);
		if (color == CLR_INVALID) {
			RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error getting pixel color");
			return nullptr;
		}

		// Release the device context again
		ReleaseDC(GetDesktopWindow(), hDC);


		_snwprintf_s(buffer, _TRUNCATE, L"%i", GetBValue(color));

		return buffer;
	}

	//@TODO log error better
	RmLogF(measure->rm, LOG_WARNING, L"CursorColor: Error with arguments");
	return nullptr;
}

PLUGIN_EXPORT void Finalize(void* data)
{
	Measure* measure = (Measure*)data;
	delete measure;
}
You do not have the required permissions to view the files attached to this post.
User avatar
kyriakos876
Posts: 915
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Searching for a plugin.

kyriakos876 » March 21st, 2018, 9:47 am

This is great. I appreciate you took the time to make it :D :D
Now if you see in the pictures, if a window is on top of the CPU/RAM/CPU Temp skins, they will move to the right side (usually there's nothing there unless I'm using full screen)
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 19870
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Searching for a plugin.

jsmorley » March 21st, 2018, 12:08 pm

Cool.

Yeah, this is a very specific, one-off kind of plugin, as it is so seldom that any given single pixel gives you much confidence about what the "color" of something is.

If we zoom in 3200% on this N that has a color of #4040FF, we can see how that visible color is actually constructed in the context of a complex shape like a font letter on a particular background color.
2.png
You do not have the required permissions to view the files attached to this post.