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

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

Add the copyright unit test and update copyright information everywhere.

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