source: libcaca/trunk/cxx/caca++.h @ 2822

Last change on this file since 2822 was 2822, checked in by Sam Hocevar, 11 years ago

Continuing the libcucul-libcaca merge.

  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1/*
2 *  libcaca++      C++ bindings for libcaca
3 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
6 *  $Id: caca++.h 2822 2008-09-27 14:11:36Z sam $
7 *
8 *  This library 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/** \file caca++.h
16 *  \version \$Id: caca++.h 2822 2008-09-27 14:11:36Z sam $
17 *  \author Jean-Yves Lamoureux <jylam@lnxscene.org>
18 *  \brief The \e libcaca++ public header.
19 *
20 *  This header contains the public types and functions that applications
21 *  using \e libcaca++ may use.
22 */
23#ifndef _CACA_PP_H
24#define _CACA_PP_H
25
26#include <caca.h>
27
28#undef __class
29#if defined(_WIN32) && defined(__LIBCACA_PP__)
30#   define __class class __declspec(dllexport)
31#else
32#   define __class class
33#endif
34
35class Canvas;
36
37__class Charset
38{
39 public:
40    uint32_t utf8ToUtf32(char const *, size_t *);
41    size_t utf32ToUtf8(char *, uint32_t);
42    uint8_t utf32ToCp437(uint32_t);
43    uint32_t cp437ToUtf32(uint8_t);
44};
45
46/* Ugly, I know */
47__class Font
48{
49 public:
50    ~Font();
51    Font(void const *, unsigned int);
52    char const *const * getList(void);
53    unsigned int getWidth();
54    unsigned int getHeight();
55    void renderCanvas(Canvas *, uint8_t *, unsigned int,
56                               unsigned int, unsigned int);
57    uint32_t const *getBlocks();
58
59 private:
60    caca_font *font;
61};
62
63__class Dither
64{
65 public:
66    Dither(unsigned int, unsigned int, unsigned int, unsigned int,
67           unsigned int, unsigned int, unsigned int, unsigned int);
68    ~Dither();
69
70    void setPalette(uint32_t r[], uint32_t g[],
71                    uint32_t b[], uint32_t a[]);
72    void setBrightness(float);
73    void setGamma(float);
74    void setContrast(float);
75    void setAntialias(char const *);
76    char const *const * getAntialiasList();
77    void setColor(char const *);
78    char const *const * getColorList();
79    void setCharset(char const *);
80    char const *const * getCharsetList();
81    void setMode(char const *);
82    char const *const * getModeList();
83    void Bitmap(Canvas *, int, int, int, int, void *);
84
85 private:
86    caca_dither *dither;
87};
88
89__class Canvas
90{
91    friend class Caca;
92    friend class Dither;
93    friend class Font;
94 public:
95    Canvas();
96    Canvas(int width, int height);
97    ~Canvas();
98
99    void setSize(unsigned int w, unsigned int h);
100    unsigned int getWidth(void);
101    unsigned int getHeight(void);
102    uint32_t getAttr(int, int);
103    int setAttr(uint32_t);
104    int setColorANSI(uint8_t f, uint8_t b);
105    int setColorARGB(unsigned int f, unsigned int b);
106    void Printf(int x, int y , char const * format, ...);
107    void putChar(int x, int y, uint32_t ch);
108    uint32_t getChar(int, int);
109    void putStr(int x, int y, char *str);
110    void Clear(void);
111    void Blit(int, int, Canvas* c1, Canvas* c2);
112    void Invert();
113    void Flip();
114    void Flop();
115    void Rotate180();
116    void RotateLeft();
117    void RotateRight();
118    void drawLine(int, int, int, int, uint32_t);
119    void drawPolyline(int const x[], int const y[], int, uint32_t);
120    void drawThinLine(int, int, int, int);
121    void drawThinPolyline(int const x[], int const y[], int);
122    void drawCircle(int, int, int, uint32_t);
123    void drawEllipse(int, int, int, int, uint32_t);
124    void drawThinEllipse(int, int, int, int);
125    void fillEllipse(int, int, int, int, uint32_t);
126    void drawBox(int, int, int, int, uint32_t);
127    void drawThinBox(int, int, int, int);
128    void drawCP437Box(int, int, int, int);
129    void fillBox(int, int, int, int, uint32_t);
130    void drawTriangle(int, int, int, int, int, int, uint32_t);
131    void drawThinTriangle(int, int, int, int, int, int);
132    void fillTriangle(int, int, int, int, int, int, uint32_t);
133    int setBoundaries(caca_canvas_t *, int, int, unsigned int, unsigned int);
134    unsigned int getFrameCount();
135    int setFrame(unsigned int);
136    int createFrame(unsigned int);
137    int freeFrame(unsigned int);
138
139    char const * const * getImportList(void);
140    long int importMemory(void const *, size_t, char const *);
141    long int importFile(char const *, char const *);
142    char const * const * getExportList(void);
143    void *exportMemory(char const *, size_t *);
144
145    static int Rand(int, int);
146    static char const * getVersion();
147
148 protected:
149    caca_canvas_t *get_caca_canvas_t();
150
151 private:
152    caca_canvas_t *cv;
153};
154
155__class Event
156{
157    friend class Caca;
158 public:
159    enum caca_event_type
160        {
161            CACA_EVENT_NONE =          0x0000, /**< No event. */
162
163            CACA_EVENT_KEY_PRESS =     0x0001, /**< A key was pressed. */
164            CACA_EVENT_KEY_RELEASE =   0x0002, /**< A key was released. */
165            CACA_EVENT_MOUSE_PRESS =   0x0004, /**< A mouse button was pressed. */
166            CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */
167            CACA_EVENT_MOUSE_MOTION =  0x0010, /**< The mouse was moved. */
168            CACA_EVENT_RESIZE =        0x0020, /**< The window was resized. */
169
170            CACA_EVENT_ANY =           0xffff  /**< Bitmask for any event. */
171        } type;
172
173 protected:
174    caca_event_t e;
175};
176
177__class Caca
178{
179 public:
180    Caca();
181    Caca(Canvas *cv);
182    ~Caca();
183
184    void Attach(Canvas *cv);
185    void Detach();
186    void setDisplayTime(unsigned int);
187
188    void Display();
189    unsigned int getDisplayTime();
190    unsigned int getWidth();
191    unsigned int getHeight();
192    int setTitle(char const *);
193    int getEvent(unsigned int, Event*, int);
194    unsigned int getMouseX();
195    unsigned int getMouseY();
196    void setMouse(int);
197
198    static char const * getVersion();
199 private:
200    caca_display_t *dp;
201};
202
203#endif /* _CACA_PP_H */
Note: See TracBrowser for help on using the repository browser.