| 1 | /* |
|---|
| 2 | * neercs console-based window manager |
|---|
| 3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
|---|
| 4 | * 2008 Jean-Yves Lamoureux <jylam@lnxscene.org> |
|---|
| 5 | * All Rights Reserved |
|---|
| 6 | * |
|---|
| 7 | * $Id: main.c 2401 2008-06-15 12:50:12Z jylam $ |
|---|
| 8 | * |
|---|
| 9 | * This program is free software. It comes without any warranty, to |
|---|
| 10 | * the extent permitted by applicable law. You can redistribute it |
|---|
| 11 | * and/or modify it under the terms of the Do What The Fuck You Want |
|---|
| 12 | * To Public License, Version 2, as published by Sam Hocevar. See |
|---|
| 13 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | #include "config.h" |
|---|
| 17 | |
|---|
| 18 | #include <stdio.h> |
|---|
| 19 | #include <string.h> |
|---|
| 20 | #include <stdlib.h> |
|---|
| 21 | #include <sys/types.h> |
|---|
| 22 | #include <signal.h> |
|---|
| 23 | #include <sys/wait.h> |
|---|
| 24 | #include <errno.h> |
|---|
| 25 | #include <unistd.h> |
|---|
| 26 | |
|---|
| 27 | #include <cucul.h> |
|---|
| 28 | #include <caca.h> |
|---|
| 29 | |
|---|
| 30 | #include "neercs.h" |
|---|
| 31 | |
|---|
| 32 | void draw_screensaver(cucul_canvas_t *cv, |
|---|
| 33 | caca_display_t *dp, |
|---|
| 34 | struct screen_list *screen_list) |
|---|
| 35 | { |
|---|
| 36 | screensaver_flying_toasters(cv, dp, screen_list); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | #define COUNT 15 |
|---|
| 41 | #define PRECISION 100 |
|---|
| 42 | |
|---|
| 43 | char toaster1_text[] = { |
|---|
| 44 | " __._ \n" |
|---|
| 45 | " .-'== _',\n" |
|---|
| 46 | " <|_= .-' |\n" |
|---|
| 47 | " | --| \\'.-_ \n" |
|---|
| 48 | " | | \\ \" _.\n" |
|---|
| 49 | " `-_|.-\\_.-\n"}; |
|---|
| 50 | |
|---|
| 51 | char toaster2_text[] = { |
|---|
| 52 | " __._ \n" |
|---|
| 53 | " .-'== _',\n" |
|---|
| 54 | " \\|_= .-' |\n" |
|---|
| 55 | " | --| __'-.\n" |
|---|
| 56 | " | | ___.-\n" |
|---|
| 57 | " `-_|.-\n" |
|---|
| 58 | }; |
|---|
| 59 | |
|---|
| 60 | char toaster3_text[] = { |
|---|
| 61 | " _- __._\n" |
|---|
| 62 | " /.-'== _',_.-.\n" |
|---|
| 63 | " \\|_= .-'/ _.'\n" |
|---|
| 64 | " | --| / .-\n" |
|---|
| 65 | " | | _.|\n" |
|---|
| 66 | " `-_|.-\n"}; |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | void screensaver_flying_toasters(cucul_canvas_t *cv, |
|---|
| 71 | caca_display_t *dp, |
|---|
| 72 | struct screen_list *screen_list) |
|---|
| 73 | { |
|---|
| 74 | static int x[COUNT], y[COUNT], s[COUNT]; |
|---|
| 75 | static int inited = 0; |
|---|
| 76 | cucul_canvas_t **toaster; |
|---|
| 77 | |
|---|
| 78 | int i, w, h; |
|---|
| 79 | |
|---|
| 80 | toaster = (cucul_canvas_t **)malloc(sizeof(cucul_canvas_t *)); |
|---|
| 81 | toaster[0] = cucul_create_canvas(0, 0); |
|---|
| 82 | toaster[1] = cucul_create_canvas(0, 0); |
|---|
| 83 | toaster[2] = cucul_create_canvas(0, 0); |
|---|
| 84 | |
|---|
| 85 | w = cucul_get_canvas_width(cv); |
|---|
| 86 | h = cucul_get_canvas_height(cv); |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK); |
|---|
| 90 | cucul_clear_canvas(cv); |
|---|
| 91 | |
|---|
| 92 | cucul_import_memory(toaster[0], toaster1_text, strlen(toaster1_text), "ansi"); |
|---|
| 93 | cucul_import_memory(toaster[1], toaster2_text, strlen(toaster2_text), "ansi"); |
|---|
| 94 | cucul_import_memory(toaster[2], toaster3_text, strlen(toaster3_text), "ansi"); |
|---|
| 95 | |
|---|
| 96 | if(!inited) |
|---|
| 97 | { |
|---|
| 98 | for(i = 0; i < COUNT; i++) |
|---|
| 99 | { |
|---|
| 100 | x[i] = (rand()%w) * PRECISION; |
|---|
| 101 | y[i] = (rand()%h) * PRECISION; |
|---|
| 102 | s[i] = (rand()%3) * PRECISION; |
|---|
| 103 | } |
|---|
| 104 | inited = 1; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | for(i = 0; i < COUNT; i++) |
|---|
| 108 | { |
|---|
| 109 | cucul_blit(cv, x[i]/PRECISION, y[i]/PRECISION, toaster[s[i]/PRECISION], NULL); |
|---|
| 110 | |
|---|
| 111 | x[i]-=40; |
|---|
| 112 | y[i]+=10; |
|---|
| 113 | |
|---|
| 114 | if((x[i]/PRECISION) + cucul_get_canvas_width(toaster[s[i]/PRECISION])<=0) |
|---|
| 115 | x[i] = ((rand()%w)+w) * PRECISION; |
|---|
| 116 | if((y[i]/PRECISION)>=h) |
|---|
| 117 | y[i] = ((rand()%h)-h) * PRECISION; |
|---|
| 118 | |
|---|
| 119 | s[i] = ((s[i]+24)%(3*PRECISION)); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|