//todo: checker mandelbrot /* ______ ___ ___ * /\ _ \ /\_ \ /\_ \ * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ * /\____/ * \_/__/ * * Example program showing how to write a Windows screensaver. This * uses a fullscreen DirectX mode when activated normally, or the * GDI interface functions when it is running in preview mode from * inside the Windows screensaver selection dialog. When in * configuration mode, it just uses a standard Windows API dialog. * This also demonstrates how to load, save, and modify the * configuration options. * * Compile this like a normal executable, but rename the output * program to have a .scr extension, and then copy it into your * 'windows/system' directory (or 'winnt/system32' directory under * Windows NT/2000/XP). * * By Shawn Hargreaves. * * Modified by Andrei Ellman to demonstrate loading, saving and * modifying of configuration settings. * * See readme.txt for copyright information. */ #include #include "allegro.h" #include "winalleg.h" #include "julia2.rh" #include #define INISETTINGNAME_SHOWBLUECROSS "showbluecross" #define INISETTINGDEFAULT_SHOWBLUECROSS 1 #define INISETTINGNAME_SHOWEXTRATEXT "showextratext" #define INISETTINGDEFAULT_SHOWEXTRATEXT 1 #define INISETTINGNAME_MESSAGE "message" #define INISETTINGDEFAULT_MESSAGE "This message may be changed" #define MAX_MESSAGE_LENGTH 40 int setting_show_blue_cross, setting_show_extra_text; char saver_message[MAX_MESSAGE_LENGTH+1]; int ox, oy; int screen_width = 1024; int screen_height = 768; int objectsnum = 10; double G = 2; struct object { double x, y, ix, iy, mass, lx, ly; int size, color; }; object *objects; bool circles=true, dots=false, lines=false, web=false, erase=true, negatives=false, linear=false, bounce=false, randomsizes=false, clump=true; int following=-1, controlling=-1; BITMAP *buf; void set_saver_config(void) { /* Because of the different ways screensavers are invoked from the shell, * we must make absolutely sure we set the INI file to be in the same * directory as the SCR file. set_config_file() is not sufficient in these * circumstances, so we have to set the ABSOLUTE path of the INI file. */ char szPath[512], szINIFile[512]; /* As we are using SYSTEM_NONE as the system driver, we cannot use Allegro's * get_executable_name(). Thankfully, this is a Windows specific program, so * we can get away with the equivalent Windows code below. */ if(GetModuleFileName(NULL, szPath, sizeof(szPath))==0) szPath[0]=0; replace_filename(szINIFile, szPath, "scrsave.ini", 512); set_config_file(szINIFile); } void load_config(void) { set_saver_config(); setting_show_blue_cross = get_config_int(NULL, INISETTINGNAME_SHOWBLUECROSS, INISETTINGDEFAULT_SHOWBLUECROSS); setting_show_extra_text = get_config_int(NULL, INISETTINGNAME_SHOWEXTRATEXT, INISETTINGDEFAULT_SHOWEXTRATEXT); ustrzcpy(saver_message, MAX_MESSAGE_LENGTH+1, get_config_string(NULL, INISETTINGNAME_MESSAGE, INISETTINGDEFAULT_MESSAGE)); } void save_config(void) { set_saver_config(); set_config_int(NULL, INISETTINGNAME_SHOWBLUECROSS, setting_show_blue_cross); set_config_int(NULL, INISETTINGNAME_SHOWEXTRATEXT, setting_show_extra_text); set_config_string(NULL, INISETTINGNAME_MESSAGE, saver_message); } /* initialises our graphical effect */ void ss_init(void) { ox=oy=0; show_mouse(screen); clear_bitmap(buf); load_config(); srand(time(NULL)); objects = new object[objectsnum]; for(int i=0; i=screen_width-1) { objects[i].ix*=-1; objects[i].x+=objects[i].ix; } if(objects[i].y-objects[i].size<=0||objects[i].y+objects[i].size>=screen_height-1) { objects[i].iy*=-1; objects[i].y+=objects[i].iy; } } else { if(objects[i].x<0||objects[i].x>=screen_width) { objects[i].ix*=-1; objects[i].x+=objects[i].ix; } if(objects[i].y<0||objects[i].y>=screen_height) { objects[i].iy*=-1; objects[i].y+=objects[i].iy; } } } } } } /* draws the graphical effect */ void ss_draw(void) { if(following!=-1) { ox=objects[following].x; oy=objects[following].y; } if(erase) { clear_bitmap(buf);} if(bounce) { rect(buf, -ox, -oy, screen_width-1-ox, screen_height-1-oy, 15);} for(int i=0; i>8) { case KEY_RIGHT: ox+=screen_width/5; clear_bitmap(buf); break; case KEY_LEFT: ox-=screen_width/5; clear_bitmap(buf); break; case KEY_UP: oy-=screen_width/5; clear_bitmap(buf); break; case KEY_DOWN: oy+=screen_width/5; clear_bitmap(buf); break; } } /* else if((c>>8)==KEY_LEFT) { ox-=screen_width/5; } else if((c>>8)==KEY_UP) { oy-=screen_width/5; } else if((c>>8)==KEY_DOWN) { oy+=screen_width/5; } */ } /* if(key[KEY_RIGHT]) { ox+=5; } if(key[KEY_LEFT]) { ox-=5; } if(key[KEY_UP]) { oy-=5; } if(key[KEY_DOWN]) { oy+=5; } */ while (t < retrace_count) { ss_update(); t++; } ss_draw(); show_mouse(buf); blit(buf, screen, 0, 0, 0, 0, screen_width, screen_height); show_mouse(screen); poll_mouse(); } ss_exit(); destroy_bitmap(buf); ReleaseMutex(scrsaver_mutex); return 0; } /* the main program body */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) { HWND hwnd; char *args; args = lpszCmdParam; if ((args[0] == '-') || (args[0] == '/')) args++; if ((args[0]) && ((args[1] == ' ') || (args[1] == ':'))) hwnd = (HWND)atoi(args+2); else hwnd = GetActiveWindow(); switch (utolower(args[0])) { case 'c': return do_settings(hInstance, hPrevInstance, hwnd); case 'a': return do_password(hInstance, hPrevInstance, hwnd); case 'p': return do_preview(hInstance, hPrevInstance, hwnd); case 's': return do_saver(hInstance, hPrevInstance, hwnd); } return do_saver(hInstance, hPrevInstance, hwnd); }