Subversion Repositories programming

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
292 ira 1
/*******************************************************************************
2
 * draw.c - implementation for libggi-based drawing on the GNU/Linux
3
 *          framebuffer device.
4
 *
5
 * Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)
6
 ******************************************************************************/
7
 
8
#include <ggi/ggi.h>
9
#include <stdio.h>
10
#include "draw.h"
11
 
12
/* Initialize GGI for drawing */
13
void draw_init ()
14
{
15
    /* Initialize the palette */
16
    palette[BLACK].r = 0;
17
    palette[BLACK].g = 0;
18
    palette[BLACK].b = 0;
19
 
20
    palette[RED].r = 0xffff;
21
    palette[RED].g = 0;
22
    palette[RED].b = 0;
23
 
24
    palette[GREEN].r = 0;
25
    palette[GREEN].g = 0xffff;
26
    palette[GREEN].b = 0;
27
 
28
    palette[BLUE].r = 0;
29
    palette[BLUE].g = 0;
30
    palette[BLUE].b = 0xffff;
31
 
32
    palette[WHITE].r = 0xffff;
33
    palette[WHITE].g = 0xffff;
34
    palette[WHITE].b = 0xffff;
35
 
36
    /* Intialize GGI itself */
37
    if (ggiInit () != 0)
38
    {
39
        printf ("Error initialising GGI!\n");
40
        exit (1);
41
    }
42
 
43
    /* Try to open the screen */
44
    if ((vis = ggiOpen (NULL)) == NULL)
45
    {
46
        printf ("Error opening visual!\n");
47
        ggiExit ();
48
        exit (1);
49
    }
50
 
51
    /* Try to set the screen mode */
52
    if (ggiSetSimpleMode (vis, GGI_AUTO, GGI_AUTO, 0, GT_AUTO))
53
    {
54
        printf ("Set the GGI_DISPLAY variable to the palemu!\n");
55
        exit (1);
56
    }
57
 
58
    /* load the palette to the screen */
59
    ggiSetPalette (vis, 0, 5, palette);
60
}
61
 
62
/* Close GGI when we're done drawing */
63
void draw_close ()
64
{
65
    ggiClose (vis);
66
    ggiExit ();
67
}
68
 
69
void draw_clearscreen ()
70
{
71
    ggiSetGCForeground (vis, BLACK);
72
    ggiFillscreen (vis);
73
    ggiFlush (vis);
74
}
75
 
76
void draw_putpixel (int x, int y, int color)
77
{
78
    ggiSetGCForeground (vis, color);
79
    ggiDrawPixel (vis, x, y);
80
    ggiFlush (vis);
81
}
82
 
83
void draw_box (int x, int y, int width, int height, int color)
84
{
85
    ggiSetGCForeground (vis, color);
86
    ggiDrawBox (vis, x, y, width, height);
87
    ggiFlush (vis);
88
}
89
 
90
void draw_line (int x1, int y1, int x2, int y2, int color)
91
{
92
    ggiSetGCForeground (vis, color);
93
    ggiDrawLine (vis, x1, y1, x2, y2);
94
    ggiFlush (vis);
95
}
96
 
295 ira 97
void draw_putc (int x, int y, char c, int color)
98
{
99
    ggiSetGCForeground (vis, color);
100
    ggiPutc (vis, x, y, c);
101
    ggiFlush (vis);
102
}
103
 
104
void draw_puts (int x, int y, const char *str, int color)
105
{
106
    ggiSetGCForeground (vis, color);
107
    ggiPuts (vis, x, y, str);
108
    ggiFlush (vis);
109
}
110