source: neercs/trunk/src/screensaver.c @ 3501

Last change on this file since 3501 was 2995, checked in by Sam Hocevar, 12 years ago

Port neercs to the unified libcaca 0.99.beta15 API.

File size: 4.2 KB
RevLine 
[2447]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 <caca.h>
[2995]28#include <caca.h>
[2447]29
30#include "neercs.h"
31
[2448]32
[2495]33void screensaver_init(struct screen_list *screen_list)
[2448]34{
35
[2495]36    screensaver_flying_toasters_init(screen_list);
[2448]37}
38
[2495]39void screensaver_kill(struct screen_list *screen_list)
[2448]40{
41
[2495]42    screensaver_flying_toasters_kill(screen_list);
[2448]43}
44
[2495]45void draw_screensaver(struct screen_list *screen_list)
[2447]46{
[2495]47    screensaver_flying_toasters(screen_list);
[2447]48}
49
50
[2448]51
52
53/* Flying Toasters */
54
[2447]55#define COUNT 15
56#define PRECISION 100
57
58char toaster1_text[] = {
59"      __._ \n"
60"   .-'== _',\n"
61"  <|_= .-'  |\n"
62"   | --|   \\'.-_ \n"
63"   |   | \\  \" _.\n"
64"    `-_|.-\\_.-\n"};
65
66char toaster2_text[] = {
67"      __._ \n"
68"   .-'== _',\n"
69"  \\|_= .-'  |\n"
70"   | --|  __'-.\n"
71"   |   | ___.-\n"
72"    `-_|.-\n"
73};
74
75char toaster3_text[] = {
76"   _- __._\n"
77"  /.-'== _',_.-.\n"
78"  \\|_= .-'/  _.'\n"
79"   | --| / .-\n"
80"   |   |  _.|\n"
81"    `-_|.-\n"};
82
[2448]83struct flying_toaster
84{
85    int x[COUNT], y[COUNT], s[COUNT];
[2995]86    caca_canvas_t **toaster;
[2448]87};
[2447]88
[2495]89void screensaver_flying_toasters_init(struct screen_list *screen_list)
[2448]90{
91    struct flying_toaster *flying_toaster;
[2995]92    int w = caca_get_canvas_width(screen_list->cv);
93    int h = caca_get_canvas_height(screen_list->cv);
[2448]94    int i;
[2447]95
[2448]96    flying_toaster = malloc(sizeof(struct flying_toaster));
[2995]97    flying_toaster->toaster = (caca_canvas_t **)malloc(sizeof(caca_canvas_t*)*3);
[2448]98
99
[2995]100    flying_toaster->toaster[0] = caca_create_canvas(0, 0);
101    flying_toaster->toaster[1] = caca_create_canvas(0, 0);
102    flying_toaster->toaster[2] = caca_create_canvas(0, 0);
[2448]103
104
[2995]105    caca_import_memory(flying_toaster->toaster[0],
[2448]106                        toaster1_text,
107                        strlen(toaster1_text), "ansi");
[2995]108    caca_import_memory(flying_toaster->toaster[1],
[2448]109                        toaster2_text,
110                        strlen(toaster2_text), "ansi");
[2995]111    caca_import_memory(flying_toaster->toaster[2],
[2448]112                        toaster3_text,
113                        strlen(toaster3_text), "ansi");
114
115    for(i = 0; i < COUNT; i++)
116    {
117        flying_toaster->x[i] = (rand()%w) * PRECISION;
118        flying_toaster->y[i] = (rand()%h) * PRECISION;
119        flying_toaster->s[i] = (rand()%3) * PRECISION;
120    }
121
122
123    screen_list->screensaver_data = flying_toaster;
124}
125
[2495]126void screensaver_flying_toasters_kill(struct screen_list *screen_list)
[2448]127{
128    struct flying_toaster *flying_toaster = screen_list->screensaver_data;
129
[2995]130    caca_free_canvas(flying_toaster->toaster[0]);
131    caca_free_canvas(flying_toaster->toaster[1]);
132    caca_free_canvas(flying_toaster->toaster[2]);
[2448]133    free(flying_toaster->toaster);
134    free(flying_toaster);
135    screen_list->screensaver_data = NULL;
136}
137
[2495]138void screensaver_flying_toasters(struct screen_list *screen_list)
[2447]139{
[2448]140    struct flying_toaster *d = screen_list->screensaver_data;
[2447]141    int i, w, h;
[2448]142    if(!d) return;
[2447]143
[2995]144    w = caca_get_canvas_width(screen_list->cv);
145    h = caca_get_canvas_height(screen_list->cv);
[2447]146
147
[2995]148    caca_set_color_ansi(screen_list->cv, CACA_WHITE, CACA_BLACK);
149    caca_clear_canvas(screen_list->cv);
[2447]150
151
152
153    for(i = 0; i < COUNT; i++)
154    {
[2995]155        caca_blit(screen_list->cv, d->x[i]/PRECISION, d->y[i]/PRECISION, d->toaster[d->s[i]/PRECISION], NULL);
[2447]156
[2448]157        d->x[i]-=40;
158        d->y[i]+=10;
[2447]159
[2995]160        if((d->x[i]/PRECISION) + caca_get_canvas_width(d->toaster[d->s[i]/PRECISION])<=0)
[2448]161            d->x[i] = ((rand()%w)+w) * PRECISION;
162        if((d->y[i]/PRECISION)>=h)
163            d->y[i] = ((rand()%h)-h) * PRECISION;
[2447]164
[2448]165        d->s[i] = ((d->s[i]+24)%(3*PRECISION));
[2447]166    }
167}
Note: See TracBrowser for help on using the repository browser.