[CYLFRAC] Change to use scrnsave library. Tidy up all now useless stuff. Tabs -> spaces. Single language link in support added. Noticable change: Multi Monitor support!

svn path=/trunk/; revision=67461
This commit is contained in:
Daniel Reimer 2015-04-27 17:25:42 +00:00
parent d793ad1a16
commit c54e0547e1
4 changed files with 181 additions and 252 deletions

View file

@ -2,5 +2,6 @@
add_executable(cylfrac cylfrac.c cylfrac.rc)
set_module_type(cylfrac win32gui UNICODE)
set_target_properties(cylfrac PROPERTIES SUFFIX ".scr")
target_link_libraries(cylfrac scrnsave)
add_importlibs(cylfrac user32 gdi32 opengl32 glu32 winmm msvcrt kernel32)
add_cd_file(TARGET cylfrac DESTINATION reactos/system32 FOR all)

View file

@ -21,6 +21,7 @@
#include <GL/gl.h>
#include <GL/glu.h>
#include <tchar.h>
#include <scrnsave.h>
#include "resource.h"
#define APPNAME _T("Cylfrac")
@ -50,284 +51,183 @@ BOOL fullscreen = FALSE;
float _RGB(float H, float M1, float M2)
{
if(H < 0.0) H += 360.0;
else if(H > 360.0) H -= 360.0;
if(H < 60) return M1 + (M2 - M1) * H / 60.0;
if((H >= 60 )&&(H < 180)) return M2;
if((H >= 180)&&(H < 240)) return M1 + (M2 - M1)*(240 - H) / 60.0;
return M1;
if(H < 0.0) H += 360.0;
else if(H > 360.0) H -= 360.0;
if(H < 60) return M1 + (M2 - M1) * H / 60.0;
if((H >= 60 )&&(H < 180)) return M2;
if((H >= 180)&&(H < 240)) return M1 + (M2 - M1)*(240 - H) / 60.0;
return M1;
}
void HLStoRGB(float H, float L, float S,
float* R, float* G, float* B)
{
float M1, M2;
if(S <= 0.5) M2 = S * (1 + L);
else M2 = S * (1 - L) + L;
M1 = 2 * S - M2;
if (L == 0.0)
{
*R = S;
*G = S;
*B = S;
} else {
*R = _RGB(H + 120.0, M1, M2);
*G = _RGB(H , M1, M2);
*B = _RGB(H - 120.0, M1, M2);
}
if(S <= 0.5) M2 = S * (1 + L);
else M2 = S * (1 - L) + L;
M1 = 2 * S - M2;
if (L == 0.0)
{
*R = S;
*G = S;
*B = S;
} else {
*R = _RGB(H + 120.0, M1, M2);
*G = _RGB(H , M1, M2);
*B = _RGB(H - 120.0, M1, M2);
}
}
void DrawCylinder(int n, float rota, float width)
{
glPushMatrix();
glColor3f(rval/n, gval/n, bval/n);
glRotatef(rota, 0.0, 1.0, 0.0);
gluCylinder(cylinder, width, width * wfactor, n * 0.5, cylquality, 1);
glTranslatef(0.0, 0.0, -n * 0.5);
gluCylinder(cylinder, width * wfactor, width, n * 0.5, cylquality, 1);
if(n > 1)
{
float r = rota * rotfactor;
glRotatef(90.0, 1.0, 0.0, 0.0);
DrawCylinder(n - 1, r, width * wfactor);
glTranslatef(0.0, n, 0.0);
DrawCylinder(n - 1, -r, width * wfactor);
}
glPopMatrix();
glPushMatrix();
glColor3f(rval/n, gval/n, bval/n);
glRotatef(rota, 0.0, 1.0, 0.0);
gluCylinder(cylinder, width, width * wfactor, n * 0.5, cylquality, 1);
glTranslatef(0.0, 0.0, -n * 0.5);
gluCylinder(cylinder, width * wfactor, width, n * 0.5, cylquality, 1);
if(n > 1)
{
float r = rota * rotfactor;
glRotatef(90.0, 1.0, 0.0, 0.0);
DrawCylinder(n - 1, r, width * wfactor);
glTranslatef(0.0, n, 0.0);
DrawCylinder(n - 1, -r, width * wfactor);
}
glPopMatrix();
}
void DrawScene(HWND hwnd, HDC dc, int ticks)
{
PAINTSTRUCT ps;
dc = BeginPaint(hwnd, &ps);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotatef(ticks * 0.01, 0.0, 1.0, -0.5);
angle += ticks * 0.01;
colorh += ticks * 0.003;
if (colorh > 360.0) colorh -= 360.0;
HLStoRGB(colorh, 1.0, 0.7, &rval, &gval, &bval);
DrawCylinder(lvls, angle, 0.2);
SwapBuffers(dc);
EndPaint(hwnd, &ps);
PAINTSTRUCT ps;
dc = BeginPaint(hwnd, &ps);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotatef(ticks * 0.01, 0.0, 1.0, -0.5);
angle += ticks * 0.01;
colorh += ticks * 0.003;
if (colorh > 360.0) colorh -= 360.0;
HLStoRGB(colorh, 1.0, 0.7, &rval, &gval, &bval);
DrawCylinder(lvls, angle, 0.2);
SwapBuffers(dc);
EndPaint(hwnd, &ps);
}
void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
InvalidateRect((HWND)dwUser, NULL, 0);
InvalidateRect((HWND)dwUser, NULL, 0);
}
void MyPixelFormat(HDC dc)
{
int npf;
PIXELFORMATDESCRIPTOR pfd;
int npf;
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
npf = ChoosePixelFormat(dc, &pfd);
if(npf != 0)
SetPixelFormat(dc, npf, &pfd);
npf = ChoosePixelFormat(dc, &pfd);
if(npf != 0)
SetPixelFormat(dc, npf, &pfd);
}
void InitGL(HWND hwnd)
{
GLfloat lightpos[4] = {2.0, 2.0, -2.0, 0.7};
GLfloat ca = 1.0;
dc = GetDC(hwnd);
MyPixelFormat(dc);
hrc = wglCreateContext(dc);
wglMakeCurrent(dc, hrc);
cylinder = gluNewQuadric();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat *)&lightpos);
glLightfv(GL_LIGHT0, GL_LINEAR_ATTENUATION, &ca);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
GLfloat lightpos[4] = {2.0, 2.0, -2.0, 0.7};
GLfloat ca = 1.0;
dc = GetDC(hwnd);
MyPixelFormat(dc);
hrc = wglCreateContext(dc);
wglMakeCurrent(dc, hrc);
cylinder = gluNewQuadric();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat *)&lightpos);
glLightfv(GL_LIGHT0, GL_LINEAR_ATTENUATION, &ca);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
}
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) {
case WM_CREATE:
GetCursorPos(&initpoint);
InitGL(hwnd);
oldticks = GetTickCount();
TimerID = timeSetEvent (timerdelay, 0, TimeProc, (DWORD)hwnd, TIME_PERIODIC);
break;
case WM_PAINT:
{
DWORD ticks = oldticks;
POINT currpoint;
oldticks = GetTickCount();
DrawScene(hwnd, dc, oldticks - ticks);
if(fullscreen)
{
GetCursorPos(&currpoint);
if(abs(currpoint.x - initpoint.x) + (abs(currpoint.y - initpoint.y)) > 10)
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
break;
}
case WM_DESTROY:
timeKillEvent(TimerID);
gluDeleteQuadric(cylinder);
wglMakeCurrent(0, 0);
wglDeleteContext(hrc);
ReleaseDC(hwnd, dc);
DeleteDC(dc);
if (fullscreen)
ShowCursor(TRUE);
PostQuitMessage(0);
break;
case WM_NOTIFY:
case WM_SYSKEYDOWN:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
float fscale;
glViewport(0, 0, width, height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
fscale = 0.8/(float)lvls;
glScalef(fscale, fscale, fscale);
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
switch(msg) {
case WM_CREATE:
{
GetCursorPos(&initpoint);
InitGL(hwnd);
oldticks = GetTickCount();
TimerID = timeSetEvent (timerdelay, 0, TimeProc, (DWORD)hwnd, TIME_PERIODIC);
}
break;
case WM_PAINT:
{
DWORD ticks = oldticks;
POINT currpoint;
oldticks = GetTickCount();
DrawScene(hwnd, dc, oldticks - ticks);
if(fullscreen)
{
GetCursorPos(&currpoint);
if(abs(currpoint.x - initpoint.x) + (abs(currpoint.y - initpoint.y)) > 10)
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
}
break;
case WM_DESTROY:
{
timeKillEvent(TimerID);
gluDeleteQuadric(cylinder);
wglMakeCurrent(0, 0);
wglDeleteContext(hrc);
ReleaseDC(hwnd, dc);
DeleteDC(dc);
if (fullscreen)
ShowCursor(TRUE);
PostQuitMessage(0);
}
break;
case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
float fscale;
glViewport(0, 0, width, height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
fscale = 0.8/(float)lvls;
glScalef(fscale, fscale, fscale);
}
break;
default:
return DefScreenSaverProc(hwnd, msg, wParam, lParam);
}
return 0;
}
void InitSaver(HWND hwndParent)
BOOL WINAPI ScreenSaverConfigureDialog(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
{
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = APPNAME;
RegisterClass(&wc);
if (hwndParent != 0)
{
RECT rect;
GetClientRect(hwndParent, &rect);
CreateWindow(APPNAME, APPNAME,
WS_VISIBLE | WS_CHILD,
0, 0,
rect.right,
rect.bottom,
hwndParent, 0,
hInstance, NULL);
fullscreen = FALSE;
} else {
HWND hwnd;
hwnd = CreateWindow(APPNAME, APPNAME,
WS_VISIBLE | WS_POPUP | WS_EX_TOPMOST,
0, 0,
GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
HWND_DESKTOP, 0,
hInstance, NULL);
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
ShowCursor(FALSE);
fullscreen = TRUE;
}
return FALSE;
}
//
// Look for any options Windows has passed to us:
//
// -a <hwnd> (set password)
// -s (screensave)
// -p <hwnd> (preview)
// -c <hwnd> (configure)
//
VOID ParseCommandLine(LPWSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
BOOL WINAPI RegisterDialogClasses(HANDLE hmodule)
{
UCHAR ch = *szCmdLine++;
TCHAR szTitle[256];
TCHAR szText[256];
if(ch == '-' || ch == '/')
ch = *szCmdLine++;
LoadString(hmodule,
IDS_TITLE,
szTitle,
256);
if(ch >= 'A' && ch <= 'Z')
ch += 'a' - 'A'; //convert to lower case
LoadString(hmodule,
IDS_TEXT,
szText,
256);
*chOption = ch;
ch = *szCmdLine++;
if(ch == ':')
ch = *szCmdLine++;
while(ch == ' ' || ch == '\t')
ch = *szCmdLine++;
if(isdigit(ch))
{
unsigned int i = _wtoi(szCmdLine - 1);
*hwndParent = (HWND)i;
}
else
*hwndParent = NULL;
MessageBox(0,
szText,
szTitle,
MB_OK | MB_ICONWARNING);
return FALSE;
}
void Configure(void)
{
TCHAR szTitle[256];
TCHAR szText[256];
LoadString(hInstance,
IDS_TITLE,
szTitle,
256);
LoadString(hInstance,
IDS_TEXT,
szText,
256);
MessageBox(0,
szText,
szTitle,
MB_OK | MB_ICONWARNING);
}
int CALLBACK wWinMain (HINSTANCE hInst,
HINSTANCE hPrev,
LPWSTR lpCmdLine,
int iCmdShow)
{
HWND hwndParent = 0;
UCHAR chOption;
MSG Message;
hInstance = hInst;
ParseCommandLine(lpCmdLine, &chOption, &hwndParent);
switch(chOption)
{
case 's':
InitSaver(0);
break;
case 'p':
InitSaver(hwndParent);
break;
case 'c':
default:
Configure();
return 0;
}
while (GetMessage(&Message, 0, 0, 0))
DispatchMessage(&Message);
return Message.wParam;
}

View file

@ -1,4 +1,5 @@
#include <windows.h>
#include <scrnsave.h>
#include "resource.h"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
@ -10,18 +11,44 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#include <reactos/version.rc>
#include <reactos/manifest_exe.rc>
/* UTF-8 */
#pragma code_page(65001)
#include "lang/bg-BG.rc"
#include "lang/de-DE.rc"
#include "lang/en-US.rc"
#include "lang/es-ES.rc"
#include "lang/fr-FR.rc"
#include "lang/lt-LT.rc"
#include "lang/nl-NL.rc"
#include "lang/no-NO.rc"
#include "lang/pl-PL.rc"
#include "lang/ro-RO.rc"
#include "lang/sk-SK.rc"
#include "lang/uk-UA.rc"
#ifdef LANGUAGE_BG_BG
#include "lang/bg-BG.rc"
#endif
#ifdef LANGUAGE_DE_DE
#include "lang/de-DE.rc"
#endif
#ifdef LANGUAGE_EN_US
#include "lang/en-US.rc"
#endif
#ifdef LANGUAGE_ES_ES
#include "lang/es-ES.rc"
#endif
#ifdef LANGUAGE_ES_ES
#include "lang/fr-FR.rc"
#endif
#ifdef LANGUAGE_LT_LT
#include "lang/lt-LT.rc"
#endif
#ifdef LANGUAGE_NL_NL
#include "lang/nl-NL.rc"
#endif
#ifdef LANGUAGE_NO_NO
#include "lang/no-NO.rc"
#endif
#ifdef LANGUAGE_PL_PL
#include "lang/pl-PL.rc"
#endif
#ifdef LANGUAGE_RO_RO
#include "lang/ro-RO.rc"
#endif
#ifdef LANGUAGE_SK_SK
#include "lang/sk-SK.rc"
#endif
#ifdef LANGUAGE_UK_UA
#include "lang/uk-UA.rc"
#endif

View file

@ -1,3 +1,4 @@
#pragma once
#define IDS_DESCRIPTION 1
#define IDS_TITLE 2