source: powerpipo/trunk/src/main.c @ 2610

Last change on this file since 2610 was 1818, checked in by Sam Hocevar, 16 years ago
  • Powerpipo proof of concept. Needs the SVN version of TOIlet, but will eventually be standalone.
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1/*
2 *  powerpipo          business presentation software
3 *  Copyright (c) 2007 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: main.c 1818 2007-09-30 10:03:06Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16
17#include <stdio.h>
18
19#include <cucul.h>
20#include <caca.h>
21
22static void do_page(cucul_canvas_t *, int);
23static void runtoilet(cucul_canvas_t *, char const *, char const *);
24
25int main(int argc, char *argv[])
26{
27    caca_display_t *dp;
28    cucul_canvas_t *cv;
29    int page = 0, npages = 10, changed = 1;
30
31    cv = cucul_create_canvas(0, 0);
32
33    dp = caca_create_display(cv);
34    if(!dp)
35        return 1;
36
37    caca_set_display_time(dp, 20000);
38    caca_set_display_title(dp, "PowerPIPO presentation tool");
39
40    for(;;)
41    {
42        caca_event_t ev;
43
44        /* Handle events */
45        while(caca_get_event(dp, CACA_EVENT_KEY_PRESS
46                                  | CACA_EVENT_QUIT, &ev, 10000))
47        {
48            if(ev.type == CACA_EVENT_QUIT)
49                goto end;
50            switch(ev.data.key.ch)
51            {
52            case CACA_KEY_ESCAPE:
53                goto end;
54                break;
55            case ' ':
56            case CACA_KEY_PAGEDOWN:
57                page++;
58                if(page > npages - 1)
59                    page = npages - 1;
60                changed = 1;
61                break;
62            case CACA_KEY_PAGEUP:
63                page--;
64                if(page < 0)
65                    page = 0;
66                changed = 1;
67                break;
68            }
69        }
70
71        if(changed)
72        {
73            do_page(cv, page);
74            caca_refresh_display(dp);
75            changed = 0;
76        }
77    }
78
79 end:
80    caca_free_display(dp);
81    cucul_free_canvas(cv);
82
83    return 0;
84}
85
86static void do_page(cucul_canvas_t *cv, int page)
87{
88    char str[BUFSIZ];
89    cucul_canvas_t *tmp;
90
91    cucul_clear_canvas(cv);
92    tmp = cucul_create_canvas(0, 0);
93
94    if(page < 1) goto end;
95    sprintf(str, "\x1b[33;93m» \x1b[37;97mEfficient presentations");
96    runtoilet(tmp, "-f smmono12", str);
97    cucul_blit(cv, 4, 0, tmp, NULL);
98
99    if(page < 2) goto end;
100    sprintf(str, "\x1b[32;92m» \x1b[37;97mWhy text mode?");
101    runtoilet(tmp, "-f smmono9", str);
102    cucul_blit(cv, 11, 9, tmp, NULL);
103
104    if(page < 3) goto end;
105    sprintf(str, "\x1b[32;92m» \x1b[37;97mExample: \x1b[34mp\x1b[35mo\x1b[36mw\x1b[32me\x1b[31mr\x1b[34mp\x1b[35mi\x1b[36mp\x1b[32mo\x1b[37m™");
106    runtoilet(tmp, "-f smmono9", str);
107    cucul_blit(cv, 11, 16, tmp, NULL);
108
109    if(page < 4) goto end;
110    sprintf(str, "\x1b[33;93m» \x1b[37;97mAdvanced stuff");
111    runtoilet(tmp, "-f smmono12", str);
112    cucul_blit(cv, 4, 24, tmp, NULL);
113
114    if(page < 5) goto end;
115    sprintf(str, "\x1b[32;92m» \x1b[37;97mTransition effects");
116    runtoilet(tmp, "-f smmono9", str);
117    cucul_blit(cv, 11, 34, tmp, NULL);
118
119    if(page < 6) goto end;
120    sprintf(str, "\x1b[32;92m» \x1b[37;97mColor filters");
121    runtoilet(tmp, "-f smmono9 --gay", str);
122    cucul_blit(cv, 11, 41, tmp, NULL);
123
124    if(page < 7) goto end;
125    sprintf(str, "\x1b[32;92m» \x1b[37;97mPictures and movies");
126    runtoilet(tmp, "-f smmono9", str);
127    cucul_blit(cv, 11, 48, tmp, NULL);
128
129    if(page < 8) goto end;
130    sprintf(str, "\x1b[32;92m» \x1b[37;97mEmbedded applications");
131    runtoilet(tmp, "-f smmono9", str);
132    cucul_blit(cv, 11, 55, tmp, NULL);
133
134end:
135    cucul_printf(cv, 0, 0, "page %i", page);
136}
137
138/* Warning: quotes are not safe */
139static void runtoilet(cucul_canvas_t *cv, char const *options, char const *str)
140{
141    char buf[BUFSIZ], cmd[BUFSIZ];
142    FILE *f;
143    int ret;
144
145    cucul_set_canvas_size(cv, 0, 0);
146
147    sprintf(cmd, "toilet -w 1000 %s '%s'", options, str);
148    f = popen(cmd, "r");
149    if(!f)
150        return;
151    ret = fread(buf, 1, BUFSIZ, f);
152    fclose(f);
153    if(ret <= 0)
154        return;
155
156    ret = cucul_import_memory(cv, buf, ret, "utf8");
157    if(ret <= 0)
158        return;
159}
160
Note: See TracBrowser for help on using the repository browser.