Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (AndrewAMD, Ayumi, NewbieZorro), 14,141 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
get pixel color under mouse cursor #238310
11/26/08 15:11
11/26/08 15:11
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

Joined: Aug 2006
Posts: 155
Any possible way?

Regards,
Konstantin.


What kills me not, that makes me stronger.

***Working on RPG/RTS***
Re: get pixel color under mouse cursor [Re: RyuMaster] #238312
11/26/08 15:18
11/26/08 15:18
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

Joined: Aug 2006
Posts: 155
Maybe there is a way to implement GetPixel part of this code to Lite-C?

Quote:
// WhatColor.c
// Shows the position and color of the point under the cursor.
// To use, click on the window and drag the cursor around the screen.
// Dbl-click to close (or single-click on notification-area icon).

#include <windows.h>

#define SIZEX 92
#define SIZEY 42
#define POSX 0
#define POSY 0
#define COLOR_BACK RGB(0,0,0)
#define COLOR_FORE RGB(0,200,200)
#define ID_TASKBAR_ICON 1
#define MYWM_NOTIFYICON WM_USER

LRESULT CALLBACK windowProc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
static HDC hdcDisp;
static int x, y;
static COLORREF color;

switch (msg) {

case WM_CREATE:
hdcDisp = CreateDC ("DISPLAY", NULL, NULL, NULL);
break;

case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
char txt[32];

hdc = BeginPaint (hwnd, &ps);
SetBkColor (hdc, COLOR_BACK);
SetTextColor (hdc, COLOR_FORE);
TextOut (hdc, 5, 5, txt, wsprintf (txt, "(%d, %d)", x, y));
TextOut (hdc, 5, 23, txt, wsprintf (txt, "%02x %02x %02x",
GetRValue (color), GetGValue (color), GetBValue (color)));
EndPaint (hwnd, &ps);
}
break;

case WM_LBUTTONDOWN:
SetCapture (hwnd);
SendMessage (hwnd, WM_MOUSEMOVE, wp, lp);
break;

case WM_MOUSEMOVE:
if (GetCapture() != hwnd) break;
// The extra stuff here is to make it work properly
// when the window is not positioned at 0,0.
x = POSX + (SHORT) LOWORD (lp);
y = POSY + (SHORT) HIWORD (lp);
color = GetPixel (hdcDisp, x, y);
InvalidateRect (hwnd, NULL, TRUE);
break;

case WM_LBUTTONUP:
ReleaseCapture();
break;

case MYWM_NOTIFYICON:
switch (wp) {
case ID_TASKBAR_ICON:
switch (lp) {
// Reacting to the button-down message seems to pass
// the button-up to the next icon (after closing this one)
// so instead, react to the button-up message.
case WM_LBUTTONUP:
PostMessage (hwnd, WM_DESTROY, 0, 0);
break;
}
break;
}
break;

case WM_LBUTTONDBLCLK:
case WM_DESTROY:
DeleteDC (hdcDisp);
PostQuitMessage (0);
break;

default:
return DefWindowProc (hwnd, msg, wp, lp);
}
return 0;
}

BOOL taskbarAddIcon (HWND hwnd, UINT id, HICON hicon)
{
NOTIFYICONDATA nid = { sizeof (NOTIFYICONDATA) };
nid.hWnd = hwnd;
nid.uID = id;
nid.uFlags = NIF_MESSAGE | NIF_ICON;
nid.hIcon = hicon;
nid.uCallbackMessage = MYWM_NOTIFYICON;
return Shell_NotifyIcon (NIM_ADD, &nid);
}

BOOL taskbarDeleteIcon (HWND hwnd, UINT id)
{
NOTIFYICONDATA nid = { sizeof (NOTIFYICONDATA) };
nid.hWnd = hwnd;
nid.uID = id;
return Shell_NotifyIcon (NIM_DELETE, &nid);
}

void registerWindow (HINSTANCE hinst, char *appName,
HBRUSH hbrBackground, WNDPROC wndproc)
{
WNDCLASSEX wc = { sizeof (wc) };
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = wndproc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinst;
wc.hIcon = LoadIcon (hinst, appName);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = hbrBackground;
wc.lpszMenuName = NULL;
wc.lpszClassName = appName;
wc.hIconSm = LoadIcon (hinst, appName);
RegisterClassEx (&wc);
}

int WINAPI WinMain (HINSTANCE hinst, HINSTANCE unused, PSTR cmd, int show)
{
char *appName = "WhatColor";
MSG msg;
HWND hwnd;
HBRUSH hbrBackground;
HICON hIcon;

hbrBackground = (HBRUSH) CreateSolidBrush (COLOR_BACK);
registerWindow (hinst, appName, hbrBackground, windowProc);

// Create invisible parent to keep the actual window out of the taskbar.
hwnd = CreateWindow (appName, 0, 0, 0, 0, 0, 0, 0, 0, hinst, 0);
hwnd = CreateWindow (appName, appName, WS_POPUP|WS_VISIBLE,
POSX, POSY, SIZEX, SIZEY, hwnd, // The invisible parent
0, hinst, 0);

hIcon = (HICON) LoadImage (hinst, appName, IMAGE_ICON,
16, 16, LR_DEFAULTCOLOR);
taskbarAddIcon (hwnd, ID_TASKBAR_ICON, hIcon);
DestroyIcon (hIcon);

while (GetMessage (&msg, 0, 0, 0))
DispatchMessage (&msg);

taskbarDeleteIcon (hwnd, ID_TASKBAR_ICON);
DeleteObject (hbrBackground);
return msg.wParam;
}



What kills me not, that makes me stronger.

***Working on RPG/RTS***
Re: get pixel color under mouse cursor [Re: RyuMaster] #238317
11/26/08 16:05
11/26/08 16:05
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
The Lite-c way: get the current screen in a bmap using bmap_for_screen(), then check the pixel on the bmap using pixel_for_bmap().

It wont be a very fast function though.

The way you proposes above can't be done in lite-c right away to my knowledge. You need to set normal lite-c code aside and embed the engine in your new application, in either lite-c legacy code or using a plugin in C/C++.

For the hdc window used in that example needs to be the 3dgs hdc window, and you can only retrieve this window by embedding the engine.

If I'm wrong on this one, please correct me! smile


As an alternative, if you colorpick one static screen or panel, fill an array with pixel values at game start, then read the pixel from there.

Last edited by Joozey; 11/26/08 16:12.

Click and join the 3dgs irc community!
Room: #3dgs
Re: get pixel color under mouse cursor [Re: Joozey] #238321
11/26/08 16:43
11/26/08 16:43
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

Joined: Aug 2006
Posts: 155
I see. Thank You for answering! I'll think I can do what I need by combining pixel_for_bmap() plus pre-made panel with colors.


What kills me not, that makes me stronger.

***Working on RPG/RTS***
Re: get pixel color under mouse cursor [Re: RyuMaster] #238323
11/26/08 16:51
11/26/08 16:51
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

Joined: Aug 2006
Posts: 155
nothing

Last edited by RyuMaster; 11/26/08 16:52.

What kills me not, that makes me stronger.

***Working on RPG/RTS***
Re: get pixel color under mouse cursor [Re: RyuMaster] #238325
11/26/08 16:53
11/26/08 16:53
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
pixel_to_vec(COLOR* color, var alpha, ...);
*Nothing*

Last edited by Joozey; 11/26/08 16:53.

Click and join the 3dgs irc community!
Room: #3dgs
Re: get pixel color under mouse cursor [Re: Joozey] #238384
11/27/08 00:04
11/27/08 00:04
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
i had this working in A6, in A7 i've had nothing working, but trying to sort things of higher priority

though i did see a thread that someone had similar functions working in A7


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1