int width, height;
};
-// TODO probably need to implement something like this:
-/*
Rect rect_union(const Rect &a, const Rect &b);
Rect rect_intersection(const Rect &a, const Rect &b);
-*/
#endif // GEOM_H_
#define FRAMEBUFFER_SIZE(xsz, ysz, bpp) ((xsz) * (ysz) * (bpp) / CHAR_BIT)
-static unsigned char* framebuffer;
+static unsigned char *framebuffer;
static int dev_fd = -1;
static Rect screen_rect;
framebuffer = 0;
}
-unsigned char* get_framebuffer()
+unsigned char *get_framebuffer()
{
return framebuffer;
}
void clear_screen(int r, int g, int b)
{
- unsigned char* fb = framebuffer;
- for(int i=0; i<screen_rect.width * screen_rect.height; i++) {
- *fb++ = r;
- *fb++ = g;
- *fb++ = b;
- fb++;
+ fill_rect(screen_rect, r, g, b);
+}
+
+void fill_rect(const Rect &rect, int r, int g, int b)
+{
+ unsigned char *fb = framebuffer + rect.x + screen_rect.width * rect.y;
+ for(int i=0; i<rect.height; i++) {
+ for(int j=0; j<rect.width; j++) {
+ fb[j * 4] = r;
+ fb[j * 4 + 1] = g;
+ fb[j * 4 + 2] = b;
+ }
+ fb += screen_rect.width * 4;
}
}
bool init_gfx();
void destroy_gfx();
-unsigned char* get_framebuffer();
+unsigned char *get_framebuffer();
Rect get_screen_size();
int get_color_depth();
void clear_screen(int r, int g, int b);
+void fill_rect(const Rect &rect, int r, int g, int b);
void set_cursor_visibility(bool visible);
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <unistd.h>
+
#include "mouse.h"
#include "geom.h"
bool init_mouse()
{
- // TODO open /dev/psaux (see O_NONBLOCK comment below)
+ if((dev_fd = open("/dev/psaux", O_NONBLOCK)) == -1) {
+ fprintf(stderr, "Cannot open /dev/psaux : %s\n", strerror(errno));
+ return false;
+ }
+
return true;
}
void destroy_mouse()
{
- // TODO close /dev/psaux
+ close(dev_fd);
}
void set_mouse_bounds(const Rect &rect)
#include <stdexcept>
+#include "gfx.h"
#include "wm.h"
#include "window.h"
-
WindowManager *wm;
static WindowManager wminst;
} else {
throw std::runtime_error("Trying to create a second instance of WindowManager!\n");
}
+
+ bg_color[0] = 210;
+ bg_color[1] = 106;
+ bg_color[2] = 106;
}
void WindowManager::invalidate_region(const Rect &rect)
void WindowManager::process_windows()
{
- //TODO:
- //sta dirty rectangles na brw to union
- //na eleg3w poia einai sto dirty area k na ta kanw dirty
- //na ka8arizw ta dirty areas
- //prwta render to bg
- //meta ola ta dirty:
+ if(dirty_rects.empty()) {
+ return;
+ }
+
+ std::list<Rect>::iterator drit = dirty_rects.begin();
+ Rect uni = *drit++;
+ while(drit != dirty_rects.end()) {
+ uni = rect_union(uni, *drit++);
+ }
+ dirty_rects.clear();
+
+ fill_rect(uni, bg_color[0], bg_color[1], bg_color[2]);
+
std::list<Window*>::iterator it = windows.begin();
while(it != windows.end()) {
- if((*it)->dirty) {
+ Rect intersect = rect_intersection((*it)->rect, uni);
+ if(intersect.width && intersect.height) {
(*it)->draw();
}
}
std::list<Window*> windows;
std::list<Rect> dirty_rects;
+ int bg_color[3];
+
public:
WindowManager();