Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

lib.h

Go to the documentation of this file.
00001 /*
00002  * RVE: Realtime Video Effects
00003  * Copyright (C) 2002 Jonas Jensen <jbj@knef.dk>
00004  * 
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019 
00028 #ifndef _LIB_H
00029 #define _LIB_H
00030 
00031 #include <sys/poll.h>
00032 
00033 #include <fcntl.h>
00034 
00035 #include "bitmap.h"
00036 
00037 #ifndef MIN
00038 # define MAX(a, b) ((a) > (b) ? (a) : (b))
00039 # define MIN(a, b) ((a) < (b) ? (a) : (b))
00040 #endif
00041 
00042 #ifndef __GNUC__
00043 # define __attribute__(x)
00044 #endif
00045 
00053 class Readfd {
00054 public:
00059     Readfd(int fd): _fd(fd), _len(0), _pos(0), _buflimit(0), _buf(NULL) {
00060         _pollfd.fd = fd; _pollfd.events = POLLIN | POLLERR;
00061 
00062         int flags = fcntl(fd, F_GETFL, O_NONBLOCK);
00063         if (flags >= 0 && !(flags & O_NONBLOCK)) {
00064             fcntl(fd, F_SETFL, flags | O_NONBLOCK);
00065         }
00066     }
00067     ~Readfd() { free(_buf); }
00068 
00074     int read_line(std::string &str);
00075 
00082     int read_bytes(std::string &str, size_t count);
00083 
00088     int event(int timeout = -1);
00089 
00094     bool eof() { return _fd < 0; }
00095 
00099     size_t buflimit() { return _buflimit; }
00105     size_t buflimit(size_t set) { return _buflimit = set; }
00106 
00107 protected:
00108     int _fd;
00109     size_t _len, _pos, _buflimit;
00110     char *_buf;
00111     struct pollfd _pollfd;
00112     
00113     static const size_t _readsize = 1024;
00114 };
00115 
00120 
00125 void blit(const Bitmap &bitmap, int xpos, int ypos, int alpha = 0, int clear=0);
00126 
00140 void set_alpha(int width, int height, int xpos, int ypos, int alpha);
00141 
00145 void clear(int width, int height, int xpos, int ypos);
00149 void clear();
00151 
00156 
00166 void text(RGBA &bitmap, int width, char *str, 
00167         int size = 0, char *align = "left");
00168 
00173 void text_trimmed(RGBA &bitmap, int width, int height, 
00174         char *str, int size = 0, char *align = "left");
00175 
00179 void text_constsize(RGBA &bitmap, char *str, 
00180         int size = 0, char *align = "left");
00181 
00187 Bitmap *load_image(const char *filename);
00188 
00192 Bitmap *load_image_from_mem(const char *ptr, size_t len);
00194 
00199 
00201 void settimer_ms(int milliseconds);
00203 int gettimer_ms();
00204 
00209 void msleep(int msec);
00210 
00216 int runtime();
00218 
00226 int tcp_connect(const char *host, short port);
00227 
00232 void msg(int level, char *format, ...) __attribute__((format (printf, 2, 3)));
00233 
00239 int scalefont(int percent);
00240 
00245 int center(int s, int S);
00246 
00250 inline int inrange(int num, int lo, int hi);
00252 
00253 #endif

Generated on Sun Oct 19 17:34:47 2003 for rve by doxygen 1.3.3