It is currently September 24th, 2021, 2:51 pm

Searching for a plugin.

Help with creating, editing & fixing problems with skins
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Searching for a plugin.

Post by kyriakos876 »

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)
User avatar
jsmorley
Developer
Posts: 22310
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Searching for a plugin.

Post by jsmorley »

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: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Searching for a plugin.

Post by kyriakos876 »

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: 22310
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Searching for a plugin.

Post by jsmorley »

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: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Searching for a plugin.

Post by kyriakos876 »

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: 22310
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Searching for a plugin.

Post by jsmorley »

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.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Searching for a plugin.

Post by kyriakos876 »

jsmorley wrote: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
I've noticed that too, but in my case the "targeted" pixel is in the midle of the circle which is the same color and there is no anti-alias stuff going on. :)
User avatar
raiguard
Posts: 655
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Searching for a plugin.

Post by raiguard »

I have a slight problem... this plugin is causing some massive lag on my PC when invoked. Here's a GIF to demonstrate:
LAGGGGGGG.gif
(For reference, usually the dragging is almost lagless, with just a little bit of a hiccup when Disks Meter updates).

There are two skins at play here: The 'control' skin, which consists of a 1-pixel dot in each corner of the monitor's work area, and another, which is a simple image meter with the FrostedGlass plugin (I am aware of the issues this plugin causes, but this lag happens even if I disable the plugin).

The idea is that I have a reserved column where I can keep my gadgets, and they will always remain visible. Whenever a window is maximized, a translucent background is added to fill the empty space, greatly enhancing the aesthetics.

This works by using the PixelColor plugin to check the color of each corner pixel. If it is equal to the color of the dot, then it returns 0. If the color is different from what it should be (which means that a window is covering it), then it returns 1. This is used to determine whether or not a window is maximized. It is very similar to the method adopted by Adaptive Translucent Taskbar skin.

Here is the code for the "control" skin:

Code: Select all

[Rainmeter]
MiddleMouseUpAction=[!Refresh]
OnRefreshAction=[!ZPos -2][!ClickThrough 1][!AutoSelectScreen 1][!Move "[#WORKAREAX@[#sb1Monitor]]" "[#WORKAREAY@[#sb1Monitor]]"]
OnCloseAction=[!CommandMeasure MeasureLoadSkinScript "ToggleSkin('[MeasureSb1BgConfig]', nil, 0)"]
AccurateText=1
DynamicWindowSize=1
Group=ModernGadgets | MgImportRefresh | MgSb1

[Variables]
@includeStyleSheet=#@#StyleSheet.inc
@includeGlobalSettings=#@#Settings\GlobalSettings.inc

state=1

; ==================================================
;  MEASURES
; ==================================================

[MeasurePixelColor]
Measure=Plugin
Plugin=PixelColor

[MeasureConfigActive]
Measure=Plugin
Plugin=ConfigActive

[MeasureLoadSkinScript]
Measure=Script
ScriptFile=#scriptPath#LoadSkin.lua

[MeasureVerifyScript]
Measure=Script
ScriptFile=#scriptPath#Verify.lua

[MeasureSb1BgConfig]
Measure=String
String=ModernGadgets\Settings\Sidebars\Backgrounds\1
Substitute="\":"\\"

[MeasureWorkAreaWidth]
Measure=Calc
Formula=(#WORKAREAX# + #WORKAREAWIDTH# - 1)
DynamicVariables=1

[MeasureWorkAreaHeight]
Measure=Calc
Formula=(#WORKAREAY# + #WORKAREAHEIGHT# - 1)
DynamicVariables=1

[MeasureDirectionControl]
Measure=String
String=#sb1Alignment#
IfMatch=right
IfMatchAction=[!EnableMeasure MeasureControlRight]
IfNotMatchAction=[!EnableMeasure MeasureControlLeft]

[MeasureControlRight]
Measure=Calc
Formula=([&MeasureVerifyScript:CheckColor('[&MeasurePixelColor:PixelRGB([&MeasureWorkAreaWidth:],[#WORKAREAY])]')] <> #state#) + ([&MeasureVerifyScript:CheckColor('[&MeasurePixelColor:PixelRGB([&MeasureWorkAreaWidth:],[&MeasureWorkAreaHeight:])]')] <> #state#)
DynamicVariables=1
IfCondition=MeasureControlRight = 2
IfTrueAction=[!SetVariable state "(abs(#state#-1))"][!EnableMeasure MeasureToggleBackground][!UpdateMeasure MeasureToggleBackground][!UpdateMeasure MeasureControlRight]
Disabled=1

[MeasureControlLeft]
Measure=Calc
Formula=([&MeasureVerifyScript:CheckColor('[&MeasurePixelColor:PixelRGB([#WORKAREAX],[#WORKAREAY])]')] <> #state#) + ([&MeasureVerifyScript:CheckColor('[&MeasurePixelColor:PixelRGB([#WORKAREAX],[&MeasureWorkAreaHeight:])]')] <> #state#)
DynamicVariables=1
IfCondition=MeasureControlLeft = 2
IfTrueAction=[!SetVariable state "(abs(#state#-1))"][!EnableMeasure MeasureToggleBackground][!UpdateMeasure MeasureToggleBackground][!UpdateMeasure MeasureControlLeft]
Disabled=1

[MeasureToggleBackground]
Measure=Calc
IfCondition=#state# = 1
IfTrueAction=[!CommandMeasure MeasureLoadSkinScript "ToggleSkin('[MeasureSb1BgConfig]', nil, 1)"][!DisableMeasure MeasureToggleBackground]
IfFalseAction=[!CommandMeasure MeasureLoadSkinScript "ToggleSkin('[MeasureSb1BgConfig]', nil, 0)"][!DisableMeasure MeasureToggleBackground]
DynamicVariables=1
Disabled=1

; ==================================================
;  METERS
; ==================================================

[MeterTopLeft]
Meter=Image
SolidColor=#colorSbControlCorner#
X=0
Y=0
W=1
H=1

[MeterTopRight]
Meter=Image
SolidColor=#colorSbControlCorner#
X=(#WORKAREAWIDTH# - 1)
Y=0
W=1
H=1
DynamicVariables=1

[MeterBottomLeft]
Meter=Image
SolidColor=#colorSbControlCorner#
X=0
Y=(#WORKAREAHEIGHT# - 1)
W=1
H=1
DynamicVariables=1

[MeterBottomRight]
Meter=Image
SolidColor=#colorSbControlCorner#
X=(#WORKAREAWIDTH# - 1)
Y=(#WORKAREAHEIGHT# - 1)
W=1
H=1
DynamicVariables=1

; [MeterDebugDragger]
; Meter=Image
; SolidColor=0,100,0
; X=10
; Y=10
; W=30
; H=30
(This skin is very heavily integrated into my ModernGadgets suite, so trying to run it standalone will not work. You can download the most recent beta release here. Go into the global settings skin and click the 'Enable Sidebar 1' button, then click 'Update Work Area' to set it up, if all goes well...)

Is this an issue with the plugin, or am I just using it extremely inefficiently somehow?
You do not have the required permissions to view the files attached to this post.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Searching for a plugin.

Post by kyriakos876 »

I've been using the plugin for 6 months and never have I seen any lag related to it... Are you sure it's not lagging because you have something full screen? Try invoking it with 2 small Windows on each dot. Also, check that task manager while dragging it to see what is the bottleneck.
User avatar
raiguard
Posts: 655
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Searching for a plugin.

Post by raiguard »

kyriakos876 wrote: November 1st, 2018, 11:04 am I've been using the plugin for 6 months and never have I seen any lag related to it... Are you sure it's not lagging because you have something full screen? Try invoking it with 2 small Windows on each dot. Also, check that task manager while dragging it to see what is the bottleneck.
It's not lagging because something is fullscreen, it is a constant thing. I reinstalled ATT and it exhibits the same behavior... something must be going on with my PC specifically or something?

Edit: Could it have to do with the fact that I have three monitors, two of which are 1440p and one is 1080p?
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017