summaryrefslogtreecommitdiff
path: root/libwinnie
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-01-06 06:38:28 -0500
committerRaghuram Subramani <raghus2247@gmail.com>2025-01-06 06:38:28 -0500
commita096d1b1ffaa22585322c3e2619e88c0030de566 (patch)
tree58687160d7325520c6098a510f0fa19d886cb0f7 /libwinnie
parentaf75fce2fb87fb0e285b1c876fb14bccb3c0def7 (diff)
clang-format for readability
Diffstat (limited to 'libwinnie')
-rw-r--r--libwinnie/src/geom.cc53
-rw-r--r--libwinnie/src/geom.h10
-rw-r--r--libwinnie/src/gfx.cc566
-rw-r--r--libwinnie/src/mouse_cursor.h35
-rw-r--r--libwinnie/src/pixmap.cc228
-rw-r--r--libwinnie/src/pixmap.h33
-rw-r--r--libwinnie/src/sdl/event.cc130
-rw-r--r--libwinnie/src/sdl/event.h19
-rw-r--r--libwinnie/src/sdl/gfx.cc196
-rw-r--r--libwinnie/src/sdl/gfx.h31
-rw-r--r--libwinnie/src/sdl/keyboard.cc36
-rw-r--r--libwinnie/src/sdl/keyboard.h2
-rw-r--r--libwinnie/src/sdl/mouse.cc145
-rw-r--r--libwinnie/src/sdl/mouse.h2
-rw-r--r--libwinnie/src/text.cc183
-rw-r--r--libwinnie/src/window.cc303
-rw-r--r--libwinnie/src/window.h113
-rw-r--r--libwinnie/src/winnie.cc95
-rw-r--r--libwinnie/src/winnie.h12
-rw-r--r--libwinnie/src/wm.cc841
-rw-r--r--libwinnie/src/wm.h99
21 files changed, 1667 insertions, 1465 deletions
diff --git a/libwinnie/src/geom.cc b/libwinnie/src/geom.cc
index 53181db..ff03d42 100644
--- a/libwinnie/src/geom.cc
+++ b/libwinnie/src/geom.cc
@@ -21,47 +21,48 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#include "geom.h"
-Rect::Rect()
-{
- x = y = width = height = 0;
-}
+Rect::Rect() { x = y = width = height = 0; }
Rect::Rect(int x, int y, int w, int h)
{
- this->x = x;
- this->y = y;
- width = w;
- height = h;
+ this->x = x;
+ this->y = y;
+ width = w;
+ height = h;
}
-static inline int min(int x, int y)
+static inline int
+min(int x, int y)
{
- return x < y ? x : y;
+ return x < y ? x : y;
}
-static inline int max(int x, int y)
+static inline int
+max(int x, int y)
{
- return x > y ? x : y;
+ return x > y ? x : y;
}
-Rect rect_union(const Rect &a, const Rect &b)
+Rect
+rect_union(const Rect &a, const Rect &b)
{
- Rect uni;
- uni.x = min(a.x, b.x);
- uni.y = min(a.y, b.y);
- uni.width = max(a.x + a.width, b.x + b.width) - uni.x;
- uni.height = max(a.y + a.height, b.y + b.height) - uni.y;
+ Rect uni;
+ uni.x = min(a.x, b.x);
+ uni.y = min(a.y, b.y);
+ uni.width = max(a.x + a.width, b.x + b.width) - uni.x;
+ uni.height = max(a.y + a.height, b.y + b.height) - uni.y;
- return uni;
+ return uni;
}
-Rect rect_intersection(const Rect &a, const Rect &b)
+Rect
+rect_intersection(const Rect &a, const Rect &b)
{
- Rect intersect;
- intersect.x = max(a.x, b.x);
- intersect.y = max(a.y, b.y);
- intersect.width = max(min(a.x + a.width, b.x + b.width) - intersect.x, 0);
- intersect.height = max(min(a.y + a.height, b.y + b.height) - intersect.y, 0);
+ Rect intersect;
+ intersect.x = max(a.x, b.x);
+ intersect.y = max(a.y, b.y);
+ intersect.width = max(min(a.x + a.width, b.x + b.width) - intersect.x, 0);
+ intersect.height = max(min(a.y + a.height, b.y + b.height) - intersect.y, 0);
- return intersect;
+ return intersect;
}
diff --git a/libwinnie/src/geom.h b/libwinnie/src/geom.h
index 220069d..c40ff82 100644
--- a/libwinnie/src/geom.h
+++ b/libwinnie/src/geom.h
@@ -23,14 +23,14 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#define GEOM_H_
struct Rect {
- int x, y;
- int width, height;
+ int x, y;
+ int width, height;
- Rect();
- Rect(int x, int y, int w, int h);
+ Rect();
+ Rect(int x, int y, int w, int h);
};
Rect rect_union(const Rect &a, const Rect &b);
Rect rect_intersection(const Rect &a, const Rect &b);
-#endif // GEOM_H_
+#endif // GEOM_H_
diff --git a/libwinnie/src/gfx.cc b/libwinnie/src/gfx.cc
index e35f080..a054e4c 100644
--- a/libwinnie/src/gfx.cc
+++ b/libwinnie/src/gfx.cc
@@ -18,299 +18,325 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
+#include <algorithm>
+#include <inttypes.h>
#include <stdio.h>
#include <string.h>
-#include <inttypes.h>
-#include <algorithm>
#include "geom.h"
#include "sdl/gfx.h"
// used by the polygon rasterizer
-#define MAX_SCANLINES 2048
+#define MAX_SCANLINES 2048
static int32_t left_fx[MAX_SCANLINES], right_fx[MAX_SCANLINES];
-
-void clear_screen(int r, int g, int b)
+void
+clear_screen(int r, int g, int b)
{
- Rect screen_rect = get_screen_size();
- fill_rect(screen_rect, r, g, b);
+ Rect screen_rect = get_screen_size();
+ fill_rect(screen_rect, r, g, b);
}
-void fill_rect(const Rect &rect, int r, int g, int b)
+void
+fill_rect(const Rect &rect, int r, int g, int b)
{
- Rect drect = rect;
- Rect screen_rect = get_screen_size();
- Rect clipping_rect = get_clipping_rect();
-
- if(drect.x < clipping_rect.x) {
- drect.width -= clipping_rect.x - drect.x;
- drect.x = clipping_rect.x;
- }
-
- if(drect.y < clipping_rect.y) {
- drect.height -= clipping_rect.y - drect.y;
- drect.y = clipping_rect.y;
- }
-
- if(drect.x + drect.width >= clipping_rect.x + clipping_rect.width) {
- drect.width = clipping_rect.width + clipping_rect.x - drect.x;
- }
-
- if(drect.y + drect.height >= clipping_rect.y + clipping_rect.height) {
- drect.height = clipping_rect.height + clipping_rect.y - drect.y;
- }
-
- unsigned char *fb = get_framebuffer() + (drect.x + screen_rect.width * drect.y) * 4;
- for(int i=0; i<drect.height; i++) {
- for(int j=0; j<drect.width; j++) {
- fb[j * 4] = b;
- fb[j * 4 + 1] = g;
- fb[j * 4 + 2] = r;
- }
- fb += screen_rect.width * 4;
- }
+ Rect drect = rect;
+ Rect screen_rect = get_screen_size();
+ Rect clipping_rect = get_clipping_rect();
+
+ if (drect.x < clipping_rect.x) {
+ drect.width -= clipping_rect.x - drect.x;
+ drect.x = clipping_rect.x;
+ }
+
+ if (drect.y < clipping_rect.y) {
+ drect.height -= clipping_rect.y - drect.y;
+ drect.y = clipping_rect.y;
+ }
+
+ if (drect.x + drect.width >= clipping_rect.x + clipping_rect.width) {
+ drect.width = clipping_rect.width + clipping_rect.x - drect.x;
+ }
+
+ if (drect.y + drect.height >= clipping_rect.y + clipping_rect.height) {
+ drect.height = clipping_rect.height + clipping_rect.y - drect.y;
+ }
+
+ unsigned char *fb
+ = get_framebuffer() + (drect.x + screen_rect.width * drect.y) * 4;
+ for (int i = 0; i < drect.height; i++) {
+ for (int j = 0; j < drect.width; j++) {
+ fb[j * 4] = b;
+ fb[j * 4 + 1] = g;
+ fb[j * 4 + 2] = r;
+ }
+ fb += screen_rect.width * 4;
+ }
}
-void blit(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
- const Rect &dest_rect, int dest_x, int dest_y)
+void
+blit(unsigned char *src_img,
+ const Rect &src_rect,
+ unsigned char *dest_img,
+ const Rect &dest_rect,
+ int dest_x,
+ int dest_y)
{
- int red_offs, green_offs, blue_offs;
- get_rgb_order(&red_offs, &green_offs, &blue_offs);
-
- Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
-
- int src_xoffs = 0;
- int src_yoffs = 0;
- int width = src_rect.width;
- int height = src_rect.height;
-
- int xoffs = dest_x - irect.x;
- if(xoffs < 0) {
- dest_x = irect.x;
- width += xoffs;
- src_xoffs = -xoffs;
- }
-
- int yoffs = dest_y - irect.y;
- if(yoffs < 0) {
- dest_y = irect.y;
- height += yoffs;
- src_yoffs = -yoffs;
- }
-
- int xend = dest_x + width;
- if(xend >= irect.x + irect.width) {
- width -= xend - (irect.x + irect.width);
- }
-
- int yend = dest_y + height;
- if(yend >= irect.y + irect.height) {
- height -= yend - (irect.y + irect.height);
- }
-
- if(width <= 0 || height <= 0) {
- return;
- }
-
- unsigned char *sptr = src_img + ((src_rect.y + src_yoffs) * src_rect.width + src_rect.x + src_xoffs) * 4;
- unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
-
- for(int i=0; i<height; i++) {
- for(int j=0; j<width; j++) {
- dptr[j * 4 + red_offs] = sptr[j * 4];
- dptr[j * 4 + green_offs] = sptr[j * 4 + 1];
- dptr[j * 4 + blue_offs] = sptr[j * 4 + 2];
- }
- sptr += src_rect.width * 4;
- dptr += dest_rect.width * 4;
- }
+ int red_offs, green_offs, blue_offs;
+ get_rgb_order(&red_offs, &green_offs, &blue_offs);
+
+ Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
+
+ int src_xoffs = 0;
+ int src_yoffs = 0;
+ int width = src_rect.width;
+ int height = src_rect.height;
+
+ int xoffs = dest_x - irect.x;
+ if (xoffs < 0) {
+ dest_x = irect.x;
+ width += xoffs;
+ src_xoffs = -xoffs;
+ }
+
+ int yoffs = dest_y - irect.y;
+ if (yoffs < 0) {
+ dest_y = irect.y;
+ height += yoffs;
+ src_yoffs = -yoffs;
+ }
+
+ int xend = dest_x + width;
+ if (xend >= irect.x + irect.width) {
+ width -= xend - (irect.x + irect.width);
+ }
+
+ int yend = dest_y + height;
+ if (yend >= irect.y + irect.height) {
+ height -= yend - (irect.y + irect.height);
+ }
+
+ if (width <= 0 || height <= 0) {
+ return;
+ }
+
+ unsigned char *sptr
+ = src_img
+ + ((src_rect.y + src_yoffs) * src_rect.width + src_rect.x + src_xoffs)
+ * 4;
+ unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
+
+ for (int i = 0; i < height; i++) {
+ for (int j = 0; j < width; j++) {
+ dptr[j * 4 + red_offs] = sptr[j * 4];
+ dptr[j * 4 + green_offs] = sptr[j * 4 + 1];
+ dptr[j * 4 + blue_offs] = sptr[j * 4 + 2];
+ }
+ sptr += src_rect.width * 4;
+ dptr += dest_rect.width * 4;
+ }
}
-void blit_key(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
- const Rect &dest_rect, int dest_x, int dest_y, int key_r, int key_g, int key_b)
+void
+blit_key(unsigned char *src_img,
+ const Rect &src_rect,
+ unsigned char *dest_img,
+ const Rect &dest_rect,
+ int dest_x,
+ int dest_y,
+ int key_r,
+ int key_g,
+ int key_b)
{
- int red_offs, green_offs, blue_offs;
- get_rgb_order(&red_offs, &green_offs, &blue_offs);
-
- Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
-
- int src_xoffs = 0;
- int src_yoffs = 0;
- int width = src_rect.width;
- int height = src_rect.height;
-
- int xoffs = dest_x - irect.x;
- if(xoffs < 0) {
- dest_x = irect.x;
- width += xoffs;
- src_xoffs = -xoffs;
- }
-
- int yoffs = dest_y - irect.y;
- if(yoffs < 0) {
- dest_y = irect.y;
- height += yoffs;
- src_yoffs = -yoffs;
- }
-
- int xend = dest_x + width;
- if(xend >= irect.x + irect.width) {
- width -= xend - (irect.x + irect.width);
- }
-
- int yend = dest_y + height;
- if(yend >= irect.y + irect.height) {
- height -= yend - (irect.y + irect.height);
- }
-
- if(width <= 0 || height <= 0) {
- return;
- }
-
- unsigned char *sptr = src_img + ((src_rect.y + src_yoffs) * src_rect.width + src_rect.x + src_xoffs) * 4;
- unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
-
- for(int i=0; i<height; i++) {
- for(int j=0; j<width; j++) {
- int r = sptr[j * 4];
- int g = sptr[j * 4 + 1];
- int b = sptr[j * 4 + 2];
-
- if(r != key_r || g != key_g || b != key_b) {
- dptr[j * 4 + red_offs] = r;
- dptr[j * 4 + green_offs] = g;
- dptr[j * 4 + blue_offs] = b;
- }
- }
-
- sptr += src_rect.width * 4;
- dptr += dest_rect.width * 4;
- }
+ int red_offs, green_offs, blue_offs;
+ get_rgb_order(&red_offs, &green_offs, &blue_offs);
+
+ Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
+
+ int src_xoffs = 0;
+ int src_yoffs = 0;
+ int width = src_rect.width;
+ int height = src_rect.height;
+
+ int xoffs = dest_x - irect.x;
+ if (xoffs < 0) {
+ dest_x = irect.x;
+ width += xoffs;
+ src_xoffs = -xoffs;
+ }
+
+ int yoffs = dest_y - irect.y;
+ if (yoffs < 0) {
+ dest_y = irect.y;
+ height += yoffs;
+ src_yoffs = -yoffs;
+ }
+
+ int xend = dest_x + width;
+ if (xend >= irect.x + irect.width) {
+ width -= xend - (irect.x + irect.width);
+ }
+
+ int yend = dest_y + height;
+ if (yend >= irect.y + irect.height) {
+ height -= yend - (irect.y + irect.height);
+ }
+
+ if (width <= 0 || height <= 0) {
+ return;
+ }
+
+ unsigned char *sptr
+ = src_img
+ + ((src_rect.y + src_yoffs) * src_rect.width + src_rect.x + src_xoffs)
+ * 4;
+ unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
+
+ for (int i = 0; i < height; i++) {
+ for (int j = 0; j < width; j++) {
+ int r = sptr[j * 4];
+ int g = sptr[j * 4 + 1];
+ int b = sptr[j * 4 + 2];
+
+ if (r != key_r || g != key_g || b != key_b) {
+ dptr[j * 4 + red_offs] = r;
+ dptr[j * 4 + green_offs] = g;
+ dptr[j * 4 + blue_offs] = b;
+ }
+ }
+
+ sptr += src_rect.width * 4;
+ dptr += dest_rect.width * 4;
+ }
}
-void draw_line(Pixmap *pixmap, int x0, int y0, int x1, int y1, int r, int g, int b)
+void
+draw_line(Pixmap *pixmap, int x0, int y0, int x1, int y1, int r, int g, int b)
{
- int red_offs = 0, green_offs = 1, blue_offs = 2;
- if(pixmap == get_framebuffer_pixmap()) {
- get_rgb_order(&red_offs, &green_offs, &blue_offs);
- }
-
- unsigned char *ptr = pixmap->pixels + (y0 * pixmap->width + x0) * 4;
-
- int dx = x1 - x0;
- int dy = y1 - y0;
-
- int x_inc = 4;
- int y_inc = pixmap->width * 4;
-
- if(dx < 0) {
- x_inc = -x_inc;
- dx = -dx;
- }
- if(dy < 0) {
- y_inc = -y_inc;
- dy = -dy;
- }
-
- if(dx > dy) {
- int error = (dy << 1) - dx;
- for(int i=0; i<=dx; i++) {
- ptr[red_offs] = r;
- ptr[green_offs] = g;
- ptr[blue_offs] = b;
- if(error >= 0) {
- error -= dx << 1;
- ptr += y_inc;
- }
- error += dy << 1;
- ptr += x_inc;
- }
- } else {
- int error = (dx << 1) - dy;
- for(int i=0; i<=dy; i++) {
- ptr[red_offs] = r;
- ptr[green_offs] = g;
- ptr[blue_offs] = b;
- if(error >= 0) {
- error -= dy << 1;
- ptr += x_inc;
- }
- error += dx << 1;
- ptr += y_inc;
- }
- }
+ int red_offs = 0, green_offs = 1, blue_offs = 2;
+ if (pixmap == get_framebuffer_pixmap()) {
+ get_rgb_order(&red_offs, &green_offs, &blue_offs);
+ }
+
+ unsigned char *ptr = pixmap->pixels + (y0 * pixmap->width + x0) * 4;
+
+ int dx = x1 - x0;
+ int dy = y1 - y0;
+
+ int x_inc = 4;
+ int y_inc = pixmap->width * 4;
+
+ if (dx < 0) {
+ x_inc = -x_inc;
+ dx = -dx;
+ }
+ if (dy < 0) {
+ y_inc = -y_inc;
+ dy = -dy;
+ }
+
+ if (dx > dy) {
+ int error = (dy << 1) - dx;
+ for (int i = 0; i <= dx; i++) {
+ ptr[red_offs] = r;
+ ptr[green_offs] = g;
+ ptr[blue_offs] = b;
+ if (error >= 0) {
+ error -= dx << 1;
+ ptr += y_inc;
+ }
+ error += dy << 1;
+ ptr += x_inc;
+ }
+ } else {
+ int error = (dx << 1) - dy;
+ for (int i = 0; i <= dy; i++) {
+ ptr[red_offs] = r;
+ ptr[green_offs] = g;
+ ptr[blue_offs] = b;
+ if (error >= 0) {
+ error -= dy << 1;
+ ptr += x_inc;
+ }
+ error += dx << 1;
+ ptr += y_inc;
+ }
+ }
}
-void draw_polygon(Pixmap *pixmap, int *vpos, int *vtex, int num_verts, int r, int g, int b)
+void
+draw_polygon(
+ Pixmap *pixmap, int *vpos, int *vtex, int num_verts, int r, int g, int b)
{
- int roffs = 0, goffs = 1, boffs = 2;
- if(pixmap == get_framebuffer_pixmap()) {
- get_rgb_order(&roffs, &goffs, &boffs);
- }
-
- int ystart = pixmap->height, yend = 0;
-
- for(int i=0; i<num_verts; i++) {
- int next = (i + 1) % num_verts;
- int x0 = vpos[i * 2];
- int y0 = vpos[i * 2 + 1];
- int x1 = vpos[next * 2];
- int y1 = vpos[next * 2 + 1];
-
- int dx = x1 - x0;
- int dy = y1 - y0;
-
- if(dy == 0)
- continue;
-
- /* continue in 24.8 fixed point */
- int32_t fslope = ((int32_t)dx << 8) / (int32_t)abs(dy);
- int32_t fx = x0 << 8;
-
- if(dy >= 0) {
- for(int j=y0; j<=y1; j++) {
- right_fx[j] = fx;
- fx += fslope;
- }
- } else {
- for(int j=y0; j>=y1; j--) {
- left_fx[j] = fx;
- fx += fslope;
- }
- }
-
- ystart = std::min(ystart, std::min(y0, y1));
- yend = std::max(yend, std::max(y0, y1));
- }
-
- if(ystart < 0) ystart = 0;
- if(yend > pixmap->height) yend = pixmap->height;
-
- for(int i=ystart; i<yend; i++) {
- int x = (left_fx[i] + (1 << 7)) >> 8;
- int dx = (right_fx[i] - left_fx[i]) >> 8;
-
- // accept polygons of either order
- if(dx < 0) {
- x = (right_fx[i] + (1 << 7)) >> 8;
- dx = -dx;
- }
-
- if(x < 0) {
- dx += x;
- x = 0;
- }
- if(x + dx >= pixmap->width) {
- dx = pixmap->width - x;
- }
- unsigned char *pixptr = pixmap->pixels + (i * pixmap->width + x) * 4;
-
- for(int j=0; j<=dx; j++) {
- pixptr[roffs] = r;
- pixptr[goffs] = g;
- pixptr[boffs] = b;
- pixptr += 4;
- }
- }
+ int roffs = 0, goffs = 1, boffs = 2;
+ if (pixmap == get_framebuffer_pixmap()) {
+ get_rgb_order(&roffs, &goffs, &boffs);
+ }
+
+ int ystart = pixmap->height, yend = 0;
+
+ for (int i = 0; i < num_verts; i++) {
+ int next = (i + 1) % num_verts;
+ int x0 = vpos[i * 2];
+ int y0 = vpos[i * 2 + 1];
+ int x1 = vpos[next * 2];
+ int y1 = vpos[next * 2 + 1];
+
+ int dx = x1 - x0;
+ int dy = y1 - y0;
+
+ if (dy == 0)
+ continue;
+
+ /* continue in 24.8 fixed point */
+ int32_t fslope = ((int32_t) dx << 8) / (int32_t) abs(dy);
+ int32_t fx = x0 << 8;
+
+ if (dy >= 0) {
+ for (int j = y0; j <= y1; j++) {
+ right_fx[j] = fx;
+ fx += fslope;
+ }
+ } else {
+ for (int j = y0; j >= y1; j--) {
+ left_fx[j] = fx;
+ fx += fslope;
+ }
+ }
+
+ ystart = std::min(ystart, std::min(y0, y1));
+ yend = std::max(yend, std::max(y0, y1));
+ }
+
+ if (ystart < 0)
+ ystart = 0;
+ if (yend > pixmap->height)
+ yend = pixmap->height;
+
+ for (int i = ystart; i < yend; i++) {
+ int x = (left_fx[i] + (1 << 7)) >> 8;
+ int dx = (right_fx[i] - left_fx[i]) >> 8;
+
+ // accept polygons of either order
+ if (dx < 0) {
+ x = (right_fx[i] + (1 << 7)) >> 8;
+ dx = -dx;
+ }
+
+ if (x < 0) {
+ dx += x;
+ x = 0;
+ }
+ if (x + dx >= pixmap->width) {
+ dx = pixmap->width - x;
+ }
+ unsigned char *pixptr = pixmap->pixels + (i * pixmap->width + x) * 4;
+
+ for (int j = 0; j <= dx; j++) {
+ pixptr[roffs] = r;
+ pixptr[goffs] = g;
+ pixptr[boffs] = b;
+ pixptr += 4;
+ }
+ }
}
diff --git a/libwinnie/src/mouse_cursor.h b/libwinnie/src/mouse_cursor.h
index f64934e..c070efc 100644
--- a/libwinnie/src/mouse_cursor.h
+++ b/libwinnie/src/mouse_cursor.h
@@ -25,25 +25,16 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
const int mouse_cursor_width = 8;
const int mouse_cursor_height = 16;
-const int mouse_cursor_bw[] = {
- 128, 128, 0, 0, 0, 0, 0, 0,
- 128, 255, 128, 0, 0, 0, 0, 0,
- 128, 255, 255, 128, 0, 0, 0, 0,
- 128, 255, 255, 255, 128, 0, 0, 0,
- 128, 255, 255, 255, 255, 128, 0, 0,
- 128, 255, 255, 255, 255, 255, 128, 0,
- 128, 255, 255, 255, 255, 255, 255, 128,
- 128, 255, 255, 255, 255, 255, 128, 0,
- 128, 255, 255, 255, 255, 128, 0, 0,
- 128, 255, 255, 255, 255, 128, 0, 0,
- 128, 255, 255, 255, 255, 255, 128, 0,
- 128, 255, 255, 255, 255, 255, 128, 0,
- 128, 255, 128, 128, 255, 255, 255, 128,
- 128, 128, 0, 128, 255, 255, 255, 128,
- 128, 0, 0, 0, 128, 255, 255, 128,
- 0, 0, 0, 0, 0, 128, 128, 128
-};
-
-
-
-#endif // MOUSE_CURSOR_H_
+const int mouse_cursor_bw[]
+ = { 128, 128, 0, 0, 0, 0, 0, 0, 128, 255, 128, 0, 0,
+ 0, 0, 0, 128, 255, 255, 128, 0, 0, 0, 0, 128, 255,
+ 255, 255, 128, 0, 0, 0, 128, 255, 255, 255, 255, 128, 0,
+ 0, 128, 255, 255, 255, 255, 255, 128, 0, 128, 255, 255, 255,
+ 255, 255, 255, 128, 128, 255, 255, 255, 255, 255, 128, 0, 128,
+ 255, 255, 255, 255, 128, 0, 0, 128, 255, 255, 255, 255, 128,
+ 0, 0, 128, 255, 255, 255, 255, 255, 128, 0, 128, 255, 255,
+ 255, 255, 255, 128, 0, 128, 255, 128, 128, 255, 255, 255, 128,
+ 128, 128, 0, 128, 255, 255, 255, 128, 128, 0, 0, 0, 128,
+ 255, 255, 128, 0, 0, 0, 0, 0, 128, 128, 128 };
+
+#endif // MOUSE_CURSOR_H_
diff --git a/libwinnie/src/pixmap.cc b/libwinnie/src/pixmap.cc
index 8e50fa3..35fb16e 100644
--- a/libwinnie/src/pixmap.cc
+++ b/libwinnie/src/pixmap.cc
@@ -19,159 +19,167 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
+#include "pixmap.h"
+#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <errno.h>
-#include "pixmap.h"
Pixmap::Pixmap()
{
- width = height = 0;
- pixels = 0;
+ width = height = 0;
+ pixels = 0;
}
Pixmap::Pixmap(const Pixmap &pixmap)
{
- width = height = 0;
- pixels = 0;
- set_image(pixmap.width, pixmap.height, pixmap.pixels);
+ width = height = 0;
+ pixels = 0;
+ set_image(pixmap.width, pixmap.height, pixmap.pixels);
}
-Pixmap &Pixmap::operator=(const Pixmap &pixmap)
+Pixmap &
+Pixmap::operator=(const Pixmap &pixmap)
{
- if(this != &pixmap) {
- set_image(pixmap.width, pixmap.height, pixmap.pixels);
- }
+ if (this != &pixmap) {
+ set_image(pixmap.width, pixmap.height, pixmap.pixels);
+ }
- return *this;
+ return *this;
}
Pixmap::~Pixmap()
{
- if(pixels) {
- delete [] pixels;
- }
+ if (pixels) {
+ delete[] pixels;
+ }
}
-int Pixmap::get_width() const
+int
+Pixmap::get_width() const
{
- return width;
+ return width;
}
-int Pixmap::get_height() const
+int
+Pixmap::get_height() const
{
- return height;
+ return height;
}
-Rect Pixmap::get_rect() const
+Rect
+Pixmap::get_rect() const
{
- Rect rect(0, 0, width, height);
- return rect;
+ Rect rect(0, 0, width, height);
+ return rect;
}
-bool Pixmap::set_image(int x, int y, unsigned char *pix)
+bool
+Pixmap::set_image(int x, int y, unsigned char *pix)
{
- delete [] pixels;
+ delete[] pixels;
- pixels = new unsigned char[x * y * 4];
- width = x;
- height = y;
+ pixels = new unsigned char[x * y * 4];
+ width = x;
+ height = y;
- if(pix) {
- memcpy(pixels, pix, x * y * 4);
- }
- return true;
+ if (pix) {
+ memcpy(pixels, pix, x * y * 4);
+ }
+ return true;
}
-const unsigned char *Pixmap::get_image() const
+const unsigned char *
+Pixmap::get_image() const
{
- return pixels;
+ return pixels;
}
-unsigned char *Pixmap::get_image()
+unsigned char *
+Pixmap::get_image()
{
- return pixels;
+ return pixels;
}
-bool Pixmap::load(const char *fname)
+bool
+Pixmap::load(const char *fname)
{
- FILE *fp;
- int hdrline = 0;
-
- if(!(fp = fopen(fname, "rb"))) {
- fprintf(stderr, "failed to open pixmap: %s: %s\n", fname, strerror(errno));
- return false;
- }
-
- /* read ppm header */
- while(hdrline < 3) {
- char buf[64];
-
- if(!fgets(buf, sizeof buf, fp))
- goto err;
-
- /* skip comments */
- if(buf[0] == '#')
- continue;
-
- switch(hdrline++) {
- case 0:
- /* first header line should be P6 */
- if(strcmp(buf, "P6\n") != 0)
- goto err;
- break;
-
- case 1:
- /* second header line contains the pixmap dimensions */
- if(sscanf(buf, "%d %d", &width, &height) != 2)
- goto err;
- break;
- }
- }
-
- set_image(width, height, 0);
-
- for(int i=0; i<width * height * 4; i++) {
- int c;
- if(i % 4 != 3) {
- c = fgetc(fp);
- if(c < 0)
- goto err;
- }
- else {
- c = 255;
- }
- pixels[i] = c;
- }
- fclose(fp);
- return true;
+ FILE *fp;
+ int hdrline = 0;
+
+ if (!(fp = fopen(fname, "rb"))) {
+ fprintf(stderr, "failed to open pixmap: %s: %s\n", fname, strerror(errno));
+ return false;
+ }
+
+ /* read ppm header */
+ while (hdrline < 3) {
+ char buf[64];
+
+ if (!fgets(buf, sizeof buf, fp))
+ goto err;
+
+ /* skip comments */
+ if (buf[0] == '#')
+ continue;
+
+ switch (hdrline++) {
+ case 0:
+ /* first header line should be P6 */
+ if (strcmp(buf, "P6\n") != 0)
+ goto err;
+ break;
+
+ case 1:
+ /* second header line contains the pixmap dimensions */
+ if (sscanf(buf, "%d %d", &width, &height) != 2)
+ goto err;
+ break;
+ }
+ }
+
+ set_image(width, height, 0);
+
+ for (int i = 0; i < width * height * 4; i++) {
+ int c;
+ if (i % 4 != 3) {
+ c = fgetc(fp);
+ if (c < 0)
+ goto err;
+ } else {
+ c = 255;
+ }
+ pixels[i] = c;
+ }
+ fclose(fp);
+ return true;
err:
- fprintf(stderr, "failed to load pixmap: %s\n", fname);
- fclose(fp);
- return false;
+ fprintf(stderr, "failed to load pixmap: %s\n", fname);
+ fclose(fp);
+ return false;
}
-bool Pixmap::save(const char *fname) const
+bool
+Pixmap::save(const char *fname) const
{
- if(!pixels) {
- return false;
- }
-
- FILE *fp = fopen(fname, "wb");
- if(!fp) {
- fprintf(stderr, "failed to save pixmap: %s: %s\n", fname, strerror(errno));
- return false;
- }
-
- fprintf(fp, "P6\n%d %d\n255\n", width, height);
-
- for(int i=0; i<width * height; i++) {
- fputc(pixels[i * 4], fp);
- fputc(pixels[i * 4 + 1], fp);
- fputc(pixels[i * 4 + 2], fp);
- }
-
- fclose(fp);
- return true;
+ if (!pixels) {
+ return false;
+ }
+
+ FILE *fp = fopen(fname, "wb");
+ if (!fp) {
+ fprintf(stderr, "failed to save pixmap: %s: %s\n", fname, strerror(errno));
+ return false;
+ }
+
+ fprintf(fp, "P6\n%d %d\n255\n", width, height);
+
+ for (int i = 0; i < width * height; i++) {
+ fputc(pixels[i * 4], fp);
+ fputc(pixels[i * 4 + 1], fp);
+ fputc(pixels[i * 4 + 2], fp);
+ }
+
+ fclose(fp);
+ return true;
}
diff --git a/libwinnie/src/pixmap.h b/libwinnie/src/pixmap.h
index 3ebfd87..b4bc0cc 100644
--- a/libwinnie/src/pixmap.h
+++ b/libwinnie/src/pixmap.h
@@ -24,28 +24,29 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#include "geom.h"
-class Pixmap {
+class Pixmap
+{
public:
- int width, height;
- unsigned char *pixels;
+ int width, height;
+ unsigned char *pixels;
- Pixmap();
+ Pixmap();
- Pixmap(const Pixmap &pixmap);
- Pixmap &operator=(const Pixmap& pixmap);
+ Pixmap(const Pixmap &pixmap);
+ Pixmap &operator=(const Pixmap &pixmap);
- ~Pixmap();
+ ~Pixmap();
- int get_width() const;
- int get_height() const;
- Rect get_rect() const;
+ int get_width() const;
+ int get_height() const;
+ Rect get_rect() const;
- bool set_image(int x, int y, unsigned char *pix = 0);
- const unsigned char *get_image() const;
- unsigned char *get_image();
+ bool set_image(int x, int y, unsigned char *pix = 0);
+ const unsigned char *get_image() const;
+ unsigned char *get_image();
- bool load(const char *fname);
- bool save(const char *fname) const;
+ bool load(const char *fname);
+ bool save(const char *fname) const;
};
-#endif // PIXMAP_H_
+#endif // PIXMAP_H_
diff --git a/libwinnie/src/sdl/event.cc b/libwinnie/src/sdl/event.cc
index 5835704..8e5c234 100644
--- a/libwinnie/src/sdl/event.cc
+++ b/libwinnie/src/sdl/event.cc
@@ -20,90 +20,90 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
#ifdef WINNIE_SDL
-#include <stdlib.h>
#include <SDL/SDL.h>
+#include <stdlib.h>
#include "sdl/event.h"
#include "sdl/keyboard.h"
#include "sdl/mouse.h"
#include "wm.h"
-enum {
- TIMER_EVENT = SDL_USEREVENT
-};
+enum { TIMER_EVENT = SDL_USEREVENT };
SDL_Event sdl_event;
-void process_events()
+void
+process_events()
{
- wm->process_windows();
- if(!SDL_WaitEvent(&sdl_event)) {
- return;
- }
-
- do {
- switch(sdl_event.type) {
- case SDL_KEYDOWN:
- case SDL_KEYUP:
- process_keyboard_event();
- break;
- case SDL_MOUSEMOTION:
- case SDL_MOUSEBUTTONDOWN:
- case SDL_MOUSEBUTTONUP:
- process_mouse_event();
- break;
- case SDL_QUIT:
- exit(0);
-
- case TIMER_EVENT:
- {
- Window *win = (Window*)sdl_event.user.data1;
- TimerFuncType func = win->get_timer_callback();
- if(func) {
- func(win);
- } else {
- fprintf(stderr, "timer gone off but window has no timer callback!\n");
- }
- }
- break;
-
- default:
- break;
- }
- } while(SDL_PollEvent(&sdl_event));
+ wm->process_windows();
+ if (!SDL_WaitEvent(&sdl_event)) {
+ return;
+ }
+
+ do {
+ switch (sdl_event.type) {
+ case SDL_KEYDOWN:
+ case SDL_KEYUP:
+ process_keyboard_event();
+ break;
+ case SDL_MOUSEMOTION:
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ process_mouse_event();
+ break;
+ case SDL_QUIT:
+ exit(0);
+
+ case TIMER_EVENT: {
+ Window *win = (Window *) sdl_event.user.data1;
+ TimerFuncType func = win->get_timer_callback();
+ if (func) {
+ func(win);
+ } else {
+ fprintf(stderr, "timer gone off but window has no timer callback!\n");
+ }
+ } break;
+
+ default:
+ break;
+ }
+ } while (SDL_PollEvent(&sdl_event));
}
struct TimerData {
- SDL_TimerID sdl_timer;
- Window *win;
- TimerMode mode;
+ SDL_TimerID sdl_timer;
+ Window *win;
+ TimerMode mode;
};
-static unsigned int timer_callback(unsigned int interval, void *cls)
+static unsigned int
+timer_callback(unsigned int interval, void *cls)
{
- TimerData *td = (TimerData*)cls;
-
- SDL_Event ev;
- ev.type = TIMER_EVENT;
- ev.user.data1 = td->win;
- SDL_PushEvent(&ev);
-
- if(td->mode == TIMER_ONESHOT) {
- delete td;
- return 0;
- }
- return interval; // repeat at same interval
+ TimerData *td = (TimerData *) cls;
+
+ SDL_Event ev;
+ ev.type = TIMER_EVENT;
+ ev.user.data1 = td->win;
+ SDL_PushEvent(&ev);
+
+ if (td->mode == TIMER_ONESHOT) {
+ delete td;
+ return 0;
+ }
+ return interval; // repeat at same interval
}
-void set_window_timer(Window *win, unsigned int msec, TimerMode mode)
+void
+set_window_timer(Window *win, unsigned int msec, TimerMode mode)
{
- if(!win->get_timer_callback()) {
- fprintf(stderr, "trying to start a timer without having a timer callback!\n");
- return;
- }
- TimerData *td = new TimerData;
- td->win = win;
- td->mode = mode;
- td->sdl_timer = SDL_AddTimer(msec, timer_callback, td);
+ if (!win->get_timer_callback()) {
+ fprintf(stderr,
+ "trying to start a timer without having a timer callback!\n");
+ return;
+ }
+ TimerData *td = new TimerData;
+ td->win = win;
+ td->mode = mode;
+ td->sdl_timer = SDL_AddTimer(msec, timer_callback, td);
}
#endif // WINNIE_SDL
diff --git a/libwinnie/src/sdl/event.h b/libwinnie/src/sdl/event.h
index 5c1db45..036dea5 100644
--- a/libwinnie/src/sdl/event.h
+++ b/libwinnie/src/sdl/event.h
@@ -26,22 +26,25 @@ class Window;
typedef void (*DisplayFuncType)(Window *win);
typedef void (*KeyboardFuncType)(Window *win, int key, bool pressed);
-typedef void (*MouseButtonFuncType)(Window *win, int bn, bool pressed, int x, int y);
+typedef void (*MouseButtonFuncType)(
+ Window *win, int bn, bool pressed, int x, int y);
typedef void (*MouseMotionFuncType)(Window *win, int x, int y);
typedef void (*TimerFuncType)(Window *win);
struct Callbacks {
- DisplayFuncType display;
- KeyboardFuncType keyboard;
- MouseButtonFuncType button;
- MouseMotionFuncType motion;
- TimerFuncType timer;
+ DisplayFuncType display;
+ KeyboardFuncType keyboard;
+ MouseButtonFuncType button;
+ MouseMotionFuncType motion;
+ TimerFuncType timer;
};
void process_events();
-enum TimerMode {TIMER_ONESHOT, TIMER_REPEAT};
+enum TimerMode { TIMER_ONESHOT, TIMER_REPEAT };
-void set_window_timer(Window *win, unsigned int msec, TimerMode mode = TIMER_ONESHOT);
+void set_window_timer(Window *win,
+ unsigned int msec,
+ TimerMode mode = TIMER_ONESHOT);
#endif
diff --git a/libwinnie/src/sdl/gfx.cc b/libwinnie/src/sdl/gfx.cc
index a955358..bb5eb68 100644
--- a/libwinnie/src/sdl/gfx.cc
+++ b/libwinnie/src/sdl/gfx.cc
@@ -20,10 +20,10 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
#ifdef WINNIE_SDL
-#include <stdio.h>
-#include <stdlib.h>
#include <SDL/SDL.h>
#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
#include "sdl/gfx.h"
#include "winnie.h"
@@ -31,132 +31,148 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
static SDL_Surface *fbsurf;
struct Graphics {
- Rect screen_rect;
- Rect clipping_rect;
- int color_depth; // bits per pixel
- Pixmap *pixmap;
+ Rect screen_rect;
+ Rect clipping_rect;
+ int color_depth; // bits per pixel
+ Pixmap *pixmap;
};
static Graphics *gfx;
-bool init_gfx()
+bool
+init_gfx()
{
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
- fprintf(stderr, "failed to initialize SDL\n");
- return false;
- }
-
- if(!(gfx = (Graphics*)malloc(sizeof *gfx))) {
- return false;
- }
-
- get_subsys()->graphics_offset = (intptr_t)(gfx);
-
- Rect scr_rect(0, 0, 1280, 853);
- gfx->screen_rect = scr_rect;
- gfx->color_depth = 32;
-
- if(!(fbsurf = SDL_SetVideoMode(gfx->screen_rect.width, gfx->screen_rect.height, gfx->color_depth, 0))) {
- fprintf(stderr, "Failed to set video mode\n");
- return false;
- }
- SDL_ShowCursor(0);
-
- if(!(gfx->pixmap = (Pixmap*)malloc(sizeof(Pixmap)))) {
- fprintf(stderr, "Failed to allocate pixmap.\n");
- return false;
- }
-
- gfx->pixmap->width = gfx->screen_rect.width;
- gfx->pixmap->height = gfx->screen_rect.height;
-
- int fbsize = gfx->pixmap->width * gfx->pixmap->height * gfx->color_depth / 8;
- if(!(gfx->pixmap->pixels = (unsigned char*)malloc(fbsize))) {
- fprintf(stderr, "failed to allocate the pixmap framebuffer.\n");
- return false;
- }
-
- set_clipping_rect(gfx->screen_rect);
-
- return true;
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
+ fprintf(stderr, "failed to initialize SDL\n");
+ return false;
+ }
+
+ if (!(gfx = (Graphics *) malloc(sizeof *gfx))) {
+ return false;
+ }
+
+ get_subsys()->graphics_offset = (intptr_t) (gfx);
+
+ Rect scr_rect(0, 0, 1280, 853);
+ gfx->screen_rect = scr_rect;
+ gfx->color_depth = 32;
+
+ if (!(fbsurf = SDL_SetVideoMode(gfx->screen_rect.width,
+ gfx->screen_rect.height,
+ gfx->color_depth,
+ 0))) {
+ fprintf(stderr, "Failed to set video mode\n");
+ return false;
+ }
+ SDL_ShowCursor(0);
+
+ if (!(gfx->pixmap = (Pixmap *) malloc(sizeof(Pixmap)))) {
+ fprintf(stderr, "Failed to allocate pixmap.\n");
+ return false;
+ }
+
+ gfx->pixmap->width = gfx->screen_rect.width;
+ gfx->pixmap->height = gfx->screen_rect.height;
+
+ int fbsize = gfx->pixmap->width * gfx->pixmap->height * gfx->color_depth / 8;
+ if (!(gfx->pixmap->pixels = (unsigned char *) malloc(fbsize))) {
+ fprintf(stderr, "failed to allocate the pixmap framebuffer.\n");
+ return false;
+ }
+
+ set_clipping_rect(gfx->screen_rect);
+
+ return true;
}
-void destroy_gfx()
+void
+destroy_gfx()
{
- free(gfx->pixmap->pixels);
- gfx->pixmap->pixels = 0;
- free(gfx->pixmap);
- free(gfx);
- SDL_Quit();
+ free(gfx->pixmap->pixels);
+ gfx->pixmap->pixels = 0;
+ free(gfx->pixmap);
+ free(gfx);
+ SDL_Quit();
}
-unsigned char *get_framebuffer()
+unsigned char *
+get_framebuffer()
{
- return gfx->pixmap->pixels;
+ return gfx->pixmap->pixels;
}
-Pixmap *get_framebuffer_pixmap()
+Pixmap *
+get_framebuffer_pixmap()
{
- return gfx->pixmap;
+ return gfx->pixmap;
}
-Rect get_screen_size()
+Rect
+get_screen_size()
{
- return gfx->screen_rect;
+ return gfx->screen_rect;
}
-int get_color_depth()
+int
+get_color_depth()
{
- return gfx->color_depth;
+ return gfx->color_depth;
}
-void set_clipping_rect(const Rect &rect)
+void
+set_clipping_rect(const Rect &rect)
{
- gfx->clipping_rect = rect_intersection(rect, get_screen_size());
+ gfx->clipping_rect = rect_intersection(rect, get_screen_size());
}
-const Rect &get_clipping_rect()
+const Rect &
+get_clipping_rect()
{
- return gfx->clipping_rect;
+ return gfx->clipping_rect;
}
-
-void set_cursor_visibility(bool visible)
+void
+set_cursor_visibility(bool visible)
{
}
-void gfx_update(const Rect &upd_rect)
+void
+gfx_update(const Rect &upd_rect)
{
- if(SDL_MUSTLOCK(fbsurf)) {
- SDL_LockSurface(fbsurf);
- }
-
- Rect rect = rect_intersection(upd_rect, gfx->screen_rect);
-
- unsigned char *sptr = gfx->pixmap->pixels + (rect.y * gfx->screen_rect.width + rect.x) * 4;
- unsigned char *dptr = (unsigned char*)fbsurf->pixels + (rect.y * gfx->screen_rect.width + rect.x) * 4;
-
- for(int i=0; i<rect.height; i++) {
- memcpy(dptr, sptr, rect.width * 4);
- sptr += gfx->screen_rect.width * 4;
- dptr += gfx->screen_rect.width * 4;
- }
-
- if(SDL_MUSTLOCK(fbsurf)) {
- SDL_UnlockSurface(fbsurf);
- }
- SDL_UpdateRect(fbsurf, rect.x, rect.y, rect.width, rect.height);
+ if (SDL_MUSTLOCK(fbsurf)) {
+ SDL_LockSurface(fbsurf);
+ }
+
+ Rect rect = rect_intersection(upd_rect, gfx->screen_rect);
+
+ unsigned char *sptr
+ = gfx->pixmap->pixels + (rect.y * gfx->screen_rect.width + rect.x) * 4;
+ unsigned char *dptr = (unsigned char *) fbsurf->pixels
+ + (rect.y * gfx->screen_rect.width + rect.x) * 4;
+
+ for (int i = 0; i < rect.height; i++) {
+ memcpy(dptr, sptr, rect.width * 4);
+ sptr += gfx->screen_rect.width * 4;
+ dptr += gfx->screen_rect.width * 4;
+ }
+
+ if (SDL_MUSTLOCK(fbsurf)) {
+ SDL_UnlockSurface(fbsurf);
+ }
+ SDL_UpdateRect(fbsurf, rect.x, rect.y, rect.width, rect.height);
}
-void wait_vsync()
+void
+wait_vsync()
{
}
-void get_rgb_order(int *r, int *g, int *b)
+void
+get_rgb_order(int *r, int *g, int *b)
{
- *r = fbsurf->format->Rshift / 8;
- *g = fbsurf->format->Gshift / 8;
- *b = fbsurf->format->Bshift / 8;
+ *r = fbsurf->format->Rshift / 8;
+ *g = fbsurf->format->Gshift / 8;
+ *b = fbsurf->format->Bshift / 8;
}
#endif // WINNIE_SDL
diff --git a/libwinnie/src/sdl/gfx.h b/libwinnie/src/sdl/gfx.h
index c14c22a..3674d86 100644
--- a/libwinnie/src/sdl/gfx.h
+++ b/libwinnie/src/sdl/gfx.h
@@ -42,14 +42,27 @@ void fill_rect(const Rect &rect, int r, int g, int b);
void set_cursor_visibility(bool visible);
-void blit(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
- const Rect &dest_rect, int dest_x, int dest_y);
-
-void blit_key(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
- const Rect &dest_rect, int dest_x, int dest_y, int key_r, int key_g, int key_b);
-
-void draw_line(Pixmap *pixmap, int x0, int y0, int x1, int y1, int r, int g, int b);
-void draw_polygon(Pixmap *pixmap, int *vpos, int *vtex, int num_verts, int r, int g, int b);
+void blit(unsigned char *src_img,
+ const Rect &src_rect,
+ unsigned char *dest_img,
+ const Rect &dest_rect,
+ int dest_x,
+ int dest_y);
+
+void blit_key(unsigned char *src_img,
+ const Rect &src_rect,
+ unsigned char *dest_img,
+ const Rect &dest_rect,
+ int dest_x,
+ int dest_y,
+ int key_r,
+ int key_g,
+ int key_b);
+
+void
+draw_line(Pixmap *pixmap, int x0, int y0, int x1, int y1, int r, int g, int b);
+void draw_polygon(
+ Pixmap *pixmap, int *vpos, int *vtex, int num_verts, int r, int g, int b);
void gfx_update(const Rect &rect);
@@ -57,4 +70,4 @@ void wait_vsync(); // vertical synchronization
void get_rgb_order(int *r, int *g, int *b);
-#endif //GFX_H_
+#endif // GFX_H_
diff --git a/libwinnie/src/sdl/keyboard.cc b/libwinnie/src/sdl/keyboard.cc
index 93f2e20..60edc8d 100644
--- a/libwinnie/src/sdl/keyboard.cc
+++ b/libwinnie/src/sdl/keyboard.cc
@@ -28,31 +28,35 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
extern SDL_Event sdl_event;
-bool init_keyboard()
+bool
+init_keyboard()
{
- return true;
+ return true;
}
-void destroy_keyboard()
+void
+destroy_keyboard()
{
}
-int get_keyboard_fd()
+int
+get_keyboard_fd()
{
- return -1;
+ return -1;
}
-void process_keyboard_event()
+void
+process_keyboard_event()
{
- int key = sdl_event.key.keysym.sym;
-
- Window *focused_win = wm->get_focused_window();
- if(focused_win) {
- KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback();
- if(keyb_callback) {
- bool pressed = sdl_event.key.state == SDL_PRESSED;
- keyb_callback(focused_win, key, pressed);
- }
- }
+ int key = sdl_event.key.keysym.sym;
+
+ Window *focused_win = wm->get_focused_window();
+ if (focused_win) {
+ KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback();
+ if (keyb_callback) {
+ bool pressed = sdl_event.key.state == SDL_PRESSED;
+ keyb_callback(focused_win, key, pressed);
+ }
+ }
}
#endif // WINNIE_SDL
diff --git a/libwinnie/src/sdl/keyboard.h b/libwinnie/src/sdl/keyboard.h
index 548ddbb..1366057 100644
--- a/libwinnie/src/sdl/keyboard.h
+++ b/libwinnie/src/sdl/keyboard.h
@@ -28,4 +28,4 @@ void destroy_keyboard();
int get_keyboard_fd();
void process_keyboard_event();
-#endif // KEYBOARD_H_
+#endif // KEYBOARD_H_
diff --git a/libwinnie/src/sdl/mouse.cc b/libwinnie/src/sdl/mouse.cc
index b5eac68..9ec6605 100644
--- a/libwinnie/src/sdl/mouse.cc
+++ b/libwinnie/src/sdl/mouse.cc
@@ -22,108 +22,119 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#ifdef WINNIE_SDL
#include <SDL/SDL.h>
-#include <stdlib.h>
#include <stdint.h>
+#include <stdlib.h>
#include "sdl/mouse.h"
-#include "wm.h"
#include "window.h"
#include "winnie.h"
+#include "wm.h"
extern SDL_Event sdl_event;
struct Mouse {
- int pointer_x;
- int pointer_y;
- int bnstate;
+ int pointer_x;
+ int pointer_y;
+ int bnstate;
};
static Mouse *mouse;
-bool init_mouse()
+bool
+init_mouse()
{
- if(!(mouse = (Mouse*)malloc(sizeof *mouse))) {
- return false;
- }
- get_subsys()->mouse_offset = (intptr_t)(mouse);
+ if (!(mouse = (Mouse *) malloc(sizeof *mouse))) {
+ return false;
+ }
+ get_subsys()->mouse_offset = (intptr_t) (mouse);
- memset(mouse, 0, sizeof *mouse);
- return true;
+ memset(mouse, 0, sizeof *mouse);
+ return true;
}
-void destroy_mouse()
+void
+destroy_mouse()
{
- free(mouse);
+ free(mouse);
}
-void set_mouse_bounds(const Rect &rect)
+void
+set_mouse_bounds(const Rect &rect)
{
}
-int get_mouse_fd()
+int
+get_mouse_fd()
{
- return -1;
+ return -1;
}
-void process_mouse_event()
+void
+process_mouse_event()
{
- int bn;
- MouseMotionFuncType motion_callback = 0;
- MouseButtonFuncType button_callback = 0;
-
- Window *win;
- if(!(win = wm->get_grab_window())) {
- win = wm->get_window_at_pos(mouse->pointer_x, mouse->pointer_y);
- if(win) {
- wm->set_focused_window(win);
- }
- else {
- wm->set_focused_window(0);
- }
- }
-
- switch(sdl_event.type) {
- case SDL_MOUSEMOTION:
- mouse->pointer_x = sdl_event.motion.x;
- mouse->pointer_y = sdl_event.motion.y;
- if(win && (motion_callback = win->get_mouse_motion_callback())) {
- Rect rect = win->get_absolute_rect();
- motion_callback(win, mouse->pointer_x - rect.x, mouse->pointer_y - rect.y);
- }
- break;
-
- case SDL_MOUSEBUTTONUP:
- case SDL_MOUSEBUTTONDOWN:
- bn = sdl_event.button.button - SDL_BUTTON_LEFT;
- if(sdl_event.button.state == SDL_PRESSED) {
- mouse->bnstate |= 1 << bn;
- }
- else {
- mouse->bnstate &= ~(1 << bn);
- }
- if(win && (button_callback = win->get_mouse_button_callback())) {
- Rect rect = win->get_absolute_rect();
- button_callback(win, bn, sdl_event.button.state, mouse->pointer_x - rect.x, mouse->pointer_y - rect.y);
- }
- }
+ int bn;
+ MouseMotionFuncType motion_callback = 0;
+ MouseButtonFuncType button_callback = 0;
+
+ Window *win;
+ if (!(win = wm->get_grab_window())) {
+ win = wm->get_window_at_pos(mouse->pointer_x, mouse->pointer_y);
+ if (win) {
+ wm->set_focused_window(win);
+ } else {
+ wm->set_focused_window(0);
+ }
+ }
+
+ switch (sdl_event.type) {
+ case SDL_MOUSEMOTION:
+ mouse->pointer_x = sdl_event.motion.x;
+ mouse->pointer_y = sdl_event.motion.y;
+ if (win && (motion_callback = win->get_mouse_motion_callback())) {
+ Rect rect = win->get_absolute_rect();
+ motion_callback(
+ win, mouse->pointer_x - rect.x, mouse->pointer_y - rect.y);
+ }
+ break;
+
+ case SDL_MOUSEBUTTONUP:
+ case SDL_MOUSEBUTTONDOWN:
+ bn = sdl_event.button.button - SDL_BUTTON_LEFT;
+ if (sdl_event.button.state == SDL_PRESSED) {
+ mouse->bnstate |= 1 << bn;
+ } else {
+ mouse->bnstate &= ~(1 << bn);
+ }
+ if (win && (button_callback = win->get_mouse_button_callback())) {
+ Rect rect = win->get_absolute_rect();
+ button_callback(win,
+ bn,
+ sdl_event.button.state,
+ mouse->pointer_x - rect.x,
+ mouse->pointer_y - rect.y);
+ }
+ }
}
-void get_pointer_pos(int *x, int *y)
+void
+get_pointer_pos(int *x, int *y)
{
- *x = mouse->pointer_x;
- *y = mouse->pointer_y;
+ *x = mouse->pointer_x;
+ *y = mouse->pointer_y;
}
-int get_button_state()
+int
+get_button_state()
{
- return mouse->bnstate;
+ return mouse->bnstate;
}
-int get_button(int bn)
+int
+get_button(int bn)
{
- if(bn < 0 || bn >= 3) {
- return 0;
- }
- return (mouse->bnstate & (1 << bn)) != 0;
+ if (bn < 0 || bn >= 3) {
+ return 0;
+ }
+ return (mouse->bnstate & (1 << bn)) != 0;
}
#endif // WINNIE_SDL
diff --git a/libwinnie/src/sdl/mouse.h b/libwinnie/src/sdl/mouse.h
index 6fbe711..d47a674 100644
--- a/libwinnie/src/sdl/mouse.h
+++ b/libwinnie/src/sdl/mouse.h
@@ -36,4 +36,4 @@ void get_pointer_pos(int *x, int *y);
int get_button_state();
int get_button(int bn);
-#endif // MOUSE_H_
+#endif // MOUSE_H_
diff --git a/libwinnie/src/text.cc b/libwinnie/src/text.cc
index 81fa8d7..cd1a6f7 100644
--- a/libwinnie/src/text.cc
+++ b/libwinnie/src/text.cc
@@ -19,10 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
-#include <stdlib.h>
-#include <ft2build.h>
#include <freetype/freetype.h>
+#include <ft2build.h>
#include <stdint.h>
+#include <stdlib.h>
#include "sdl/gfx.h"
#include "text.h"
@@ -35,114 +35,125 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
static int draw_glyph(Pixmap *pixmap, int x, int y, char c);
struct Text {
- FT_Library ft_lib;
- FT_Face ft_face;
- int text_x, text_y;
- int text_color[3];
+ FT_Library ft_lib;
+ FT_Face ft_face;
+ int text_x, text_y;
+ int text_color[3];
};
static Text *text;
-bool init_text()
+bool
+init_text()
{
- if(!(text = (Text*)malloc(sizeof *text))) {
- return false;
- }
+ if (!(text = (Text *) malloc(sizeof *text))) {
+ return false;
+ }
- get_subsys()->text_offset = (intptr_t)(text);
+ get_subsys()->text_offset = (intptr_t) (text);
- if(FT_Init_FreeType(&text->ft_lib)) {
- fprintf(stderr, "Failed to initialize the FreeType library!\n");
- return false;
- }
+ if (FT_Init_FreeType(&text->ft_lib)) {
+ fprintf(stderr, "Failed to initialize the FreeType library!\n");
+ return false;
+ }
- if(FT_New_Face(text->ft_lib, FONT_PATH, 0, &text->ft_face)) {
- fprintf(stderr, "Failed to load font: %s\n", FONT_PATH);
- return false;
- }
+ if (FT_New_Face(text->ft_lib, FONT_PATH, 0, &text->ft_face)) {
+ fprintf(stderr, "Failed to load font: %s\n", FONT_PATH);
+ return false;
+ }
- if(FT_Set_Char_Size(text->ft_face, 0, FONT_SIZE * 64, DPI, DPI)) {
- fprintf(stderr, "Failed to set font size\n");
- return false;
- }
+ if (FT_Set_Char_Size(text->ft_face, 0, FONT_SIZE * 64, DPI, DPI)) {
+ fprintf(stderr, "Failed to set font size\n");
+ return false;
+ }
- set_text_color(255, 255, 255);
+ set_text_color(255, 255, 255);
- return true;
+ return true;
}
-void destroy_text()
+void
+destroy_text()
{
- free(text);
+ free(text);
}
-void draw_text(const char *txt, Pixmap *pixmap)
+void
+draw_text(const char *txt, Pixmap *pixmap)
{
- if(!pixmap) {
- pixmap = get_framebuffer_pixmap();
- }
-
- while(*txt != 0) {
- text->text_x += draw_glyph(pixmap, text->text_x, text->text_y, *txt);
- txt++;
- }
+ if (!pixmap) {
+ pixmap = get_framebuffer_pixmap();
+ }
+
+ while (*txt != 0) {
+ text->text_x += draw_glyph(pixmap, text->text_x, text->text_y, *txt);
+ txt++;
+ }
}
-void set_text_position(int x, int y)
+void
+set_text_position(int x, int y)
{
- text->text_x = x;
- text->text_y = y;
-
+ text->text_x = x;
+ text->text_y = y;
}
-void set_text_color(int r, int g, int b)
+void
+set_text_color(int r, int g, int b)
{
- text->text_color[0] = r;
- text->text_color[1] = g;
- text->text_color[2] = b;
+ text->text_color[0] = r;
+ text->text_color[1] = g;
+ text->text_color[2] = b;
}
-static int draw_glyph(Pixmap *pixmap, int x, int y, char c)
+static int
+draw_glyph(Pixmap *pixmap, int x, int y, char c)
{
- if(FT_Load_Char(text->ft_face, c, FT_LOAD_RENDER)) {
- return 0;
- }
-
- x += text->ft_face->glyph->bitmap_left;
- y -= text->ft_face->glyph->bitmap_top;
-
- FT_Bitmap *ft_bmp = &text->ft_face->glyph->bitmap;
- unsigned char *bmp_ptr = ft_bmp->buffer;
- unsigned char *pxm_ptr = pixmap->get_image() + (pixmap->get_width() * y + x) * 4;
-
- Rect clipping_rect = get_clipping_rect();
-
- for(unsigned int i=0; i<ft_bmp->rows; i++) {
- int dest_y = i + y;
- if(dest_y >= clipping_rect.y + clipping_rect.height) {
- break;
- }
-
- if(dest_y >= clipping_rect.y) {
- for(unsigned int j=0; j<ft_bmp->width; j++) {
- int dest_x = j + x;
-
- if(dest_x >= clipping_rect.x + clipping_rect.width) {
- break;
- }
-
- if(bmp_ptr[j] && dest_x >= clipping_rect.x) {
- int a = (int)bmp_ptr[j];
- pxm_ptr[4 * j] = (a * text->text_color[0] + pxm_ptr[4 * j] * (255 - a)) / 255;
- pxm_ptr[4 * j + 1] = (a * text->text_color[1] + pxm_ptr[4 * j + 1] * (255 - a)) / 255;
- pxm_ptr[4 * j + 2] = (a * text->text_color[2] + pxm_ptr[4 * j + 2] * (255 - a)) / 255;
- }
- }
- }
-
- pxm_ptr += 4 * pixmap->get_width();
- bmp_ptr += ft_bmp->pitch;
- }
-
- return text->ft_face->glyph->advance.x >> 6;
+ if (FT_Load_Char(text->ft_face, c, FT_LOAD_RENDER)) {
+ return 0;
+ }
+
+ x += text->ft_face->glyph->bitmap_left;
+ y -= text->ft_face->glyph->bitmap_top;
+
+ FT_Bitmap *ft_bmp = &text->ft_face->glyph->bitmap;
+ unsigned char *bmp_ptr = ft_bmp->buffer;
+ unsigned char *pxm_ptr
+ = pixmap->get_image() + (pixmap->get_width() * y + x) * 4;
+
+ Rect clipping_rect = get_clipping_rect();
+
+ for (unsigned int i = 0; i < ft_bmp->rows; i++) {
+ int dest_y = i + y;
+ if (dest_y >= clipping_rect.y + clipping_rect.height) {
+ break;
+ }
+
+ if (dest_y >= clipping_rect.y) {
+ for (unsigned int j = 0; j < ft_bmp->width; j++) {
+ int dest_x = j + x;
+
+ if (dest_x >= clipping_rect.x + clipping_rect.width) {
+ break;
+ }
+
+ if (bmp_ptr[j] && dest_x >= clipping_rect.x) {
+ int a = (int) bmp_ptr[j];
+ pxm_ptr[4 * j]
+ = (a * text->text_color[0] + pxm_ptr[4 * j] * (255 - a)) / 255;
+ pxm_ptr[4 * j + 1]
+ = (a * text->text_color[1] + pxm_ptr[4 * j + 1] * (255 - a))
+ / 255;
+ pxm_ptr[4 * j + 2]
+ = (a * text->text_color[2] + pxm_ptr[4 * j + 2] * (255 - a))
+ / 255;
+ }
+ }
+ }
+
+ pxm_ptr += 4 * pixmap->get_width();
+ bmp_ptr += ft_bmp->pitch;
+ }
+
+ return text->ft_face->glyph->advance.x >> 6;
}
diff --git a/libwinnie/src/window.cc b/libwinnie/src/window.cc
index 22e4069..e398841 100644
--- a/libwinnie/src/window.cc
+++ b/libwinnie/src/window.cc
@@ -20,7 +20,7 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
#include <algorithm>
-#include <stdio.h> //TODO
+#include <stdio.h>
#include <string.h>
#include "sdl/gfx.h"
@@ -29,253 +29,290 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
Window::Window()
{
- parent = 0;
- title = 0;
- rect.x = rect.y = 0;
- rect.width = rect.height = 128;
- memset(&callbacks, 0, sizeof callbacks);
- dirty = true;
- managed = true;
- focusable = true;
- state = STATE_NORMAL;
+ parent = 0;
+ title = 0;
+ rect.x = rect.y = 0;
+ rect.width = rect.height = 128;
+ memset(&callbacks, 0, sizeof callbacks);
+ dirty = true;
+ managed = true;
+ focusable = true;
+ state = STATE_NORMAL;
}
Window::~Window()
{
- for(size_t i=0; i<children.size(); i++) {
- wm->remove_window(children[i]);
- delete children[i];
- }
+ for (size_t i = 0; i < children.size(); i++) {
+ wm->remove_window(children[i]);
+ delete children[i];
+ }
- delete [] title;
+ delete[] title;
}
-const Rect &Window::get_rect() const
+const Rect &
+Window::get_rect() const
{
- return rect;
+ return rect;
}
-Rect Window::get_absolute_rect() const
+Rect
+Window::get_absolute_rect() const
{
- if(!parent) {
- return rect;
- }
+ if (!parent) {
+ return rect;
+ }
- Rect absolute_rect;
- absolute_rect = parent->get_absolute_rect();
+ Rect absolute_rect;
+ absolute_rect = parent->get_absolute_rect();
- absolute_rect.x += rect.x;
- absolute_rect.y += rect.y;
- absolute_rect.width = rect.width;
- absolute_rect.height = rect.height;
+ absolute_rect.x += rect.x;
+ absolute_rect.y += rect.y;
+ absolute_rect.width = rect.width;
+ absolute_rect.height = rect.height;
- return absolute_rect;
+ return absolute_rect;
}
-bool Window::contains_point(int ptr_x, int ptr_y)
+bool
+Window::contains_point(int ptr_x, int ptr_y)
{
- Rect abs_rect = get_absolute_rect();
- return ptr_x >= abs_rect.x && ptr_x < abs_rect.x + abs_rect.width &&
- ptr_y >= abs_rect.y && ptr_y < abs_rect.y + abs_rect.height;
+ Rect abs_rect = get_absolute_rect();
+ return ptr_x >= abs_rect.x && ptr_x < abs_rect.x + abs_rect.width
+ && ptr_y >= abs_rect.y && ptr_y < abs_rect.y + abs_rect.height;
}
-void Window::move(int x, int y)
+void
+Window::move(int x, int y)
{
- invalidate(); // moved, should redraw, MUST BE CALLED FIRST
- rect.x = x;
- rect.y = y;
+ invalidate(); // moved, should redraw, MUST BE CALLED FIRST
+ rect.x = x;
+ rect.y = y;
}
-void Window::resize(int x, int y)
+void
+Window::resize(int x, int y)
{
- invalidate(); // resized, should redraw, MUST BE CALLED FIRST
- rect.width = x;
- rect.height = y;
+ invalidate(); // resized, should redraw, MUST BE CALLED FIRST
+ rect.width = x;
+ rect.height = y;
}
-void Window::set_title(const char *s)
+void
+Window::set_title(const char *s)
{
- delete [] title;
+ delete[] title;
- title = new char[strlen(s) + 1];
- strcpy(title, s);
+ title = new char[strlen(s) + 1];
+ strcpy(title, s);
}
-const char *Window::get_title() const
+const char *
+Window::get_title() const
{
- return title;
+ return title;
}
-void Window::invalidate()
+void
+Window::invalidate()
{
- dirty = true;
- Rect abs_rect = get_absolute_rect();
- wm->invalidate_region(abs_rect);
+ dirty = true;
+ Rect abs_rect = get_absolute_rect();
+ wm->invalidate_region(abs_rect);
}
-void Window::draw(Rect *dirty_region)
+void
+Window::draw(Rect *dirty_region)
{
- Rect abs_rect = get_absolute_rect();
- Rect intersect = rect_intersection(abs_rect, *dirty_region);
- if(intersect.width && intersect.height) {
- Rect prev_clip = get_clipping_rect();
- set_clipping_rect(abs_rect);
+ Rect abs_rect = get_absolute_rect();
+ Rect intersect = rect_intersection(abs_rect, *dirty_region);
+ if (intersect.width && intersect.height) {
+ Rect prev_clip = get_clipping_rect();
+ set_clipping_rect(abs_rect);
- if(callbacks.display) {
- callbacks.display(this);
- }
- dirty = false;
+ if (callbacks.display) {
+ callbacks.display(this);
+ }
+ dirty = false;
- draw_children(abs_rect);
+ draw_children(abs_rect);
- *dirty_region = rect_union(*dirty_region, abs_rect);
- set_clipping_rect(prev_clip);
- }
+ *dirty_region = rect_union(*dirty_region, abs_rect);
+ set_clipping_rect(prev_clip);
+ }
}
-void Window::draw_children(const Rect &dirty_region)
+void
+Window::draw_children(const Rect &dirty_region)
{
- Rect drect = dirty_region;
- for(size_t i=0; i<children.size(); i++) {
- children[i]->draw(&drect);
- }
+ Rect drect = dirty_region;
+ for (size_t i = 0; i < children.size(); i++) {
+ children[i]->draw(&drect);
+ }
}
-unsigned char *Window::get_win_start_on_fb()
+unsigned char *
+Window::get_win_start_on_fb()
{
- unsigned char *fb = get_framebuffer();
- Rect abs_rect = get_absolute_rect();
- return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8;
+ unsigned char *fb = get_framebuffer();
+ Rect abs_rect = get_absolute_rect();
+ return fb
+ + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x)
+ / 8;
}
-int Window::get_scanline_width()
+int
+Window::get_scanline_width()
{
- return get_screen_size().x;
+ return get_screen_size().x;
}
-void Window::set_managed(bool managed)
+void
+Window::set_managed(bool managed)
{
- this->managed = managed;
+ this->managed = managed;
}
-bool Window::get_managed() const
+bool
+Window::get_managed() const
{
- return managed;
+ return managed;
}
-void Window::set_focusable(bool focusable)
+void
+Window::set_focusable(bool focusable)
{
- this->focusable = focusable;
+ this->focusable = focusable;
}
-bool Window::get_focusable() const
+bool
+Window::get_focusable() const
{
- return focusable;
+ return focusable;
}
-bool Window::get_dirty() const
+bool
+Window::get_dirty() const
{
- return dirty;
+ return dirty;
}
-void Window::set_display_callback(DisplayFuncType func)
+void
+Window::set_display_callback(DisplayFuncType func)
{
- callbacks.display = func;
+ callbacks.display = func;
}
-void Window::set_keyboard_callback(KeyboardFuncType func)
+void
+Window::set_keyboard_callback(KeyboardFuncType func)
{
- callbacks.keyboard = func;
+ callbacks.keyboard = func;
}
-void Window::set_mouse_button_callback(MouseButtonFuncType func)
+void
+Window::set_mouse_button_callback(MouseButtonFuncType func)
{
- callbacks.button = func;
+ callbacks.button = func;
}
-void Window::set_mouse_motion_callback(MouseMotionFuncType func)
+void
+Window::set_mouse_motion_callback(MouseMotionFuncType func)
{
- callbacks.motion = func;
+ callbacks.motion = func;
}
-void Window::set_timer_callback(TimerFuncType func)
+void
+Window::set_timer_callback(TimerFuncType func)
{
- callbacks.timer = func;
+ callbacks.timer = func;
}
-const DisplayFuncType Window::get_display_callback() const
+const DisplayFuncType
+Window::get_display_callback() const
{
- return callbacks.display;
+ return callbacks.display;
}
-const KeyboardFuncType Window::get_keyboard_callback() const
+const KeyboardFuncType
+Window::get_keyboard_callback() const
{
- return callbacks.keyboard;
+ return callbacks.keyboard;
}
-const MouseButtonFuncType Window::get_mouse_button_callback() const
+const MouseButtonFuncType
+Window::get_mouse_button_callback() const
{
- return callbacks.button;
+ return callbacks.button;
}
-const MouseMotionFuncType Window::get_mouse_motion_callback() const
+const MouseMotionFuncType
+Window::get_mouse_motion_callback() const
{
- return callbacks.motion;
+ return callbacks.motion;
}
-const TimerFuncType Window::get_timer_callback() const
+const TimerFuncType
+Window::get_timer_callback() const
{
- return callbacks.timer;
+ return callbacks.timer;
}
-void Window::add_child(Window *win)
+void
+Window::add_child(Window *win)
{
- children.push_back(win);
- if(win->parent) {
- win->parent->remove_child(win);
- }
- win->parent = this;
+ children.push_back(win);
+ if (win->parent) {
+ win->parent->remove_child(win);
+ }
+ win->parent = this;
}
-void Window::remove_child(Window *win)
+void
+Window::remove_child(Window *win)
{
- std::vector<Window*>::iterator it;
- it = std::find(children.begin(), children.end(), win);
- if(it != children.end()) {
- children.erase(it);
- win->parent = 0;
- }
+ std::vector<Window *>::iterator it;
+ it = std::find(children.begin(), children.end(), win);
+ if (it != children.end()) {
+ children.erase(it);
+ win->parent = 0;
+ }
}
-Window **Window::get_children()
+Window **
+Window::get_children()
{
- if(children.empty()) {
- return 0;
- }
- return &children[0];
+ if (children.empty()) {
+ return 0;
+ }
+ return &children[0];
}
-int Window::get_children_count() const
+int
+Window::get_children_count() const
{
- return (int)children.size();
+ return (int) children.size();
}
-const Window *Window::get_parent() const
+const Window *
+Window::get_parent() const
{
- return parent;
+ return parent;
}
-Window *Window::get_parent()
+Window *
+Window::get_parent()
{
- return parent;
+ return parent;
}
-void Window::set_state(State state)
+void
+Window::set_state(State state)
{
- this->state = state;
+ this->state = state;
}
-Window::State Window::get_state() const
+Window::State
+Window::get_state() const
{
- return state;
+ return state;
}
diff --git a/libwinnie/src/window.h b/libwinnie/src/window.h
index 1d987e3..25009e1 100644
--- a/libwinnie/src/window.h
+++ b/libwinnie/src/window.h
@@ -27,86 +27,87 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#include "geom.h"
#include "sdl/event.h"
-class Window {
+class Window
+{
public:
- enum State {STATE_NORMAL, STATE_MINIMIZED, STATE_MAXIMIZED, STATE_SHADED};
+ enum State { STATE_NORMAL, STATE_MINIMIZED, STATE_MAXIMIZED, STATE_SHADED };
private:
- char *title;
- State state;
+ char *title;
+ State state;
- Rect rect;
- Rect normal_rect; // normal state rectangle managed by the wm
+ Rect rect;
+ Rect normal_rect; // normal state rectangle managed by the wm
- Callbacks callbacks;
+ Callbacks callbacks;
- std::vector<Window*> children;
- Window* parent;
+ std::vector<Window *> children;
+ Window *parent;
- bool dirty;
- bool managed; // whether the wm manages (+decorates) this win
- bool focusable;
+ bool dirty;
+ bool managed; // whether the wm manages (+decorates) this win
+ bool focusable;
public:
- Window();
- ~Window();
+ Window();
+ ~Window();
- const Rect &get_rect() const;
- Rect get_absolute_rect() const;
- bool contains_point(int ptr_x, int ptr_y);
+ const Rect &get_rect() const;
+ Rect get_absolute_rect() const;
+ bool contains_point(int ptr_x, int ptr_y);
- void move(int x, int y);
- void resize(int x, int y);
+ void move(int x, int y);
+ void resize(int x, int y);
- void set_title(const char *s);
- const char *get_title() const;
+ void set_title(const char *s);
+ const char *get_title() const;
- /* mark this window as dirty, and notify the window manager
- * to repaint it, and anything it used to cover.
- */
- void invalidate();
+ /* mark this window as dirty, and notify the window manager
+ * to repaint it, and anything it used to cover.
+ */
+ void invalidate();
- void draw(Rect *dirty_region);
- void draw_children(const Rect &dirty_region);
+ void draw(Rect *dirty_region);
+ void draw_children(const Rect &dirty_region);
- unsigned char *get_win_start_on_fb();
- int get_scanline_width();
+ unsigned char *get_win_start_on_fb();
+ int get_scanline_width();
- void set_managed(bool managed);
- bool get_managed() const;
+ void set_managed(bool managed);
+ bool get_managed() const;
- void set_focusable(bool focusable);
- bool get_focusable() const;
+ void set_focusable(bool focusable);
+ bool get_focusable() const;
- bool get_dirty() const;
+ bool get_dirty() const;
- void set_display_callback(DisplayFuncType func);
- void set_keyboard_callback(KeyboardFuncType func);
- void set_mouse_button_callback(MouseButtonFuncType func);
- void set_mouse_motion_callback(MouseMotionFuncType func);
- void set_timer_callback(TimerFuncType func);
+ void set_display_callback(DisplayFuncType func);
+ void set_keyboard_callback(KeyboardFuncType func);
+ void set_mouse_button_callback(MouseButtonFuncType func);
+ void set_mouse_motion_callback(MouseMotionFuncType func);
+ void set_timer_callback(TimerFuncType func);
- const DisplayFuncType get_display_callback() const;
- const KeyboardFuncType get_keyboard_callback() const;
- const MouseButtonFuncType get_mouse_button_callback() const;
- const MouseMotionFuncType get_mouse_motion_callback() const;
- const TimerFuncType get_timer_callback() const;
+ const DisplayFuncType get_display_callback() const;
+ const KeyboardFuncType get_keyboard_callback() const;
+ const MouseButtonFuncType get_mouse_button_callback() const;
+ const MouseMotionFuncType get_mouse_motion_callback() const;
+ const TimerFuncType get_timer_callback() const;
- // win hierarchy
- void add_child(Window *win);
- void remove_child(Window *win);
+ // win hierarchy
+ void add_child(Window *win);
+ void remove_child(Window *win);
- Window **get_children();
- int get_children_count() const;
+ Window **get_children();
+ int get_children_count() const;
- const Window *get_parent() const;
- Window *get_parent();
+ const Window *get_parent() const;
+ Window *get_parent();
- void set_state(State state);
- State get_state() const;
+ void set_state(State state);
+ State get_state() const;
- // XXX remove if not needed
- friend class WindowManager;
+ // XXX remove if not needed
+ friend class WindowManager;
};
-#endif // WINDOW_H_
+#endif // WINDOW_H_
diff --git a/libwinnie/src/winnie.cc b/libwinnie/src/winnie.cc
index d5021eb..175b9a1 100644
--- a/libwinnie/src/winnie.cc
+++ b/libwinnie/src/winnie.cc
@@ -19,8 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
-#include <stdio.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
@@ -34,74 +34,81 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
static Subsys *subsys;
-bool winnie_init()
+bool
+winnie_init()
{
- if(!(subsys = (Subsys*)malloc(sizeof *subsys))) {
- return false;
- }
+ if (!(subsys = (Subsys *) malloc(sizeof *subsys))) {
+ return false;
+ }
- if(!init_gfx()) {
- return false;
- }
+ if (!init_gfx()) {
+ return false;
+ }
- if(!init_window_manager()) {
- return false;
- }
+ if (!init_window_manager()) {
+ return false;
+ }
- if(!init_keyboard()) {
- return false;
- }
+ if (!init_keyboard()) {
+ return false;
+ }
- if(!init_mouse()) {
- return false;
- }
+ if (!init_mouse()) {
+ return false;
+ }
- if(!init_text()) {
- return false;
- }
+ if (!init_text()) {
+ return false;
+ }
- wm->invalidate_region(get_screen_size());
- return true;
+ wm->invalidate_region(get_screen_size());
+ return true;
}
-void winnie_shutdown()
+void
+winnie_shutdown()
{
- destroy_gfx();
- destroy_keyboard();
- destroy_mouse();
- destroy_text();
- destroy_window_manager();
+ destroy_gfx();
+ destroy_keyboard();
+ destroy_mouse();
+ destroy_text();
+ destroy_window_manager();
- free(subsys);
+ free(subsys);
}
-bool winnie_open()
+bool
+winnie_open()
{
- subsys = (Subsys*)malloc(sizeof(Subsys));
+ subsys = (Subsys *) malloc(sizeof(Subsys));
- return true;
+ return true;
}
-void winnie_close()
+void
+winnie_close()
{
}
-long winnie_get_time()
+long
+winnie_get_time()
{
- static struct timeval init_tv;
- struct timeval tv;
+ static struct timeval init_tv;
+ struct timeval tv;
- gettimeofday(&tv, 0);
+ gettimeofday(&tv, 0);
- if(!tv.tv_sec && !tv.tv_usec) {
- init_tv = tv;
- return 0;
- }
+ if (!tv.tv_sec && !tv.tv_usec) {
+ init_tv = tv;
+ return 0;
+ }
- return (tv.tv_usec - init_tv.tv_usec) / 1000 + (tv.tv_sec - init_tv.tv_sec) * 1000;
+ return (tv.tv_usec - init_tv.tv_usec) / 1000
+ + (tv.tv_sec - init_tv.tv_sec) * 1000;
}
-Subsys *get_subsys()
+Subsys *
+get_subsys()
{
- return subsys;
+ return subsys;
}
diff --git a/libwinnie/src/winnie.h b/libwinnie/src/winnie.h
index 5b0937a..300316f 100644
--- a/libwinnie/src/winnie.h
+++ b/libwinnie/src/winnie.h
@@ -22,8 +22,8 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#ifndef WINNIE_H_
#define WINNIE_H_
-#include "sdl/event.h"
#include "geom.h"
+#include "sdl/event.h"
#include "sdl/gfx.h"
#include "sdl/keyboard.h"
#include "sdl/mouse.h"
@@ -32,11 +32,11 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#include "wm.h"
struct Subsys {
- int graphics_offset;
- int keyboard_offset;
- int mouse_offset;
- int text_offset;
- int wm_offset;
+ int graphics_offset;
+ int keyboard_offset;
+ int mouse_offset;
+ int text_offset;
+ int wm_offset;
};
bool winnie_init();
diff --git a/libwinnie/src/wm.cc b/libwinnie/src/wm.cc
index 4d0f6d0..86562ba 100644
--- a/libwinnie/src/wm.cc
+++ b/libwinnie/src/wm.cc
@@ -22,12 +22,12 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#include <algorithm>
#include <limits.h>
#include <stdexcept>
-#include <stdio.h> // TODO
#include <stdint.h>
+#include <stdio.h>
+#include "mouse_cursor.h"
#include "sdl/gfx.h"
#include "sdl/mouse.h"
-#include "mouse_cursor.h"
#include "text.h"
#include "window.h"
#include "winnie.h"
@@ -41,539 +41,610 @@ static void display(Window *win);
static void mouse(Window *win, int bn, bool pressed, int x, int y);
static void motion(Window *win, int x, int y);
-bool init_window_manager()
+bool
+init_window_manager()
{
- void *wm_mem;
- if(!(wm_mem = malloc(sizeof *wm))) {
- return false;
- }
+ void *wm_mem;
+ if (!(wm_mem = malloc(sizeof *wm))) {
+ return false;
+ }
- wm = new (wm_mem) WindowManager;
+ wm = new (wm_mem) WindowManager;
- get_subsys()->wm_offset = (intptr_t)(wm);
+ get_subsys()->wm_offset = (intptr_t) (wm);
- return true;
+ return true;
}
-void destroy_window_manager()
+void
+destroy_window_manager()
{
- wm->~WindowManager();
- free(wm);
+ wm->~WindowManager();
+ free(wm);
}
-void WindowManager::create_frame(Window *win)
+void
+WindowManager::create_frame(Window *win)
{
- Window *frame = new Window;
- Window *parent = win->get_parent();
+ Window *frame = new Window;
+ Window *parent = win->get_parent();
- frame->set_display_callback(display);
- frame->set_mouse_button_callback(mouse);
- frame->set_mouse_motion_callback(motion);
- frame->set_focusable(false);
- frame->add_child(win);
+ frame->set_display_callback(display);
+ frame->set_mouse_button_callback(mouse);
+ frame->set_mouse_motion_callback(motion);
+ frame->set_focusable(false);
+ frame->add_child(win);
- windows.push_back(frame);
+ windows.push_back(frame);
- Rect win_rect = win->get_rect();
- frame->move(win_rect.x - frame_thickness,
- win_rect.y - frame_thickness - titlebar_thickness);
- frame->resize(win_rect.width + frame_thickness * 2,
- win_rect.height + frame_thickness * 2 + titlebar_thickness);
+ Rect win_rect = win->get_rect();
+ frame->move(win_rect.x - frame_thickness,
+ win_rect.y - frame_thickness - titlebar_thickness);
+ frame->resize(win_rect.width + frame_thickness * 2,
+ win_rect.height + frame_thickness * 2 + titlebar_thickness);
- win->move(frame_thickness, frame_thickness + titlebar_thickness);
- parent->add_child(frame);
+ win->move(frame_thickness, frame_thickness + titlebar_thickness);
+ parent->add_child(frame);
}
-void WindowManager::destroy_frame(Window *win)
+void
+WindowManager::destroy_frame(Window *win)
{
- Window *frame = win->parent;
- if(!frame) {
- return;
- }
+ Window *frame = win->parent;
+ if (!frame) {
+ return;
+ }
- if(grab_win == win) {
- release_mouse();
- }
+ if (grab_win == win) {
+ release_mouse();
+ }
- std::list<Window*>::iterator it;
- it = std::find(windows.begin(), windows.end(), frame);
- if(it != windows.end()) {
- root_win->add_child(win);
- windows.erase(it);
- delete frame;
- }
+ std::list<Window *>::iterator it;
+ it = std::find(windows.begin(), windows.end(), frame);
+ if (it != windows.end()) {
+ root_win->add_child(win);
+ windows.erase(it);
+ delete frame;
+ }
}
WindowManager::WindowManager()
{
- if(!wm) {
- wm = this;
- } else {
- throw std::runtime_error("Trying to create a second instance of WindowManager!\n");
- }
+ if (!wm) {
+ wm = this;
+ } else {
+ throw std::runtime_error(
+ "Trying to create a second instance of WindowManager!\n");
+ }
- root_win = new Window;
- root_win->resize(get_screen_size().width, get_screen_size().height);
- root_win->move(0, 0);
- root_win->set_managed(false);
+ root_win = new Window;
+ root_win->resize(get_screen_size().width, get_screen_size().height);
+ root_win->move(0, 0);
+ root_win->set_managed(false);
- grab_win = 0;
- focused_win = 0;
- background = 0;
+ grab_win = 0;
+ focused_win = 0;
+ background = 0;
- bg_color[0] = 210;
- bg_color[1] = 106;
- bg_color[2] = 106;
+ bg_color[0] = 210;
+ bg_color[1] = 106;
+ bg_color[2] = 106;
- frame_thickness = 6;
- titlebar_thickness = 18;
+ frame_thickness = 6;
+ titlebar_thickness = 18;
- set_focused_frame_color(64, 64, 64);
- set_unfocused_frame_color(160, 160, 160);
- set_bevel_size(2);
+ set_focused_frame_color(64, 64, 64);
+ set_unfocused_frame_color(160, 160, 160);
+ set_bevel_size(2);
- mouse_cursor.set_image(mouse_cursor_width, mouse_cursor_height);
- unsigned char *pixels = mouse_cursor.get_image();
+ mouse_cursor.set_image(mouse_cursor_width, mouse_cursor_height);
+ unsigned char *pixels = mouse_cursor.get_image();
- for(int i=0; i<mouse_cursor_height; i++) {
- for(int j=0; j<mouse_cursor_width; j++) {
- int val = mouse_cursor_bw[i * mouse_cursor_width + j];
- *pixels++ = val;
- *pixels++ = val;
- *pixels++ = val;
- *pixels++ = 255;
- }
- }
+ for (int i = 0; i < mouse_cursor_height; i++) {
+ for (int j = 0; j < mouse_cursor_width; j++) {
+ int val = mouse_cursor_bw[i * mouse_cursor_width + j];
+ *pixels++ = val;
+ *pixels++ = val;
+ *pixels++ = val;
+ *pixels++ = 255;
+ }
+ }
}
-WindowManager::~WindowManager()
-{
- delete root_win;
-}
+WindowManager::~WindowManager() { delete root_win; }
-void WindowManager::invalidate_region(const Rect &rect)
+void
+WindowManager::invalidate_region(const Rect &rect)
{
- dirty_rects.push_back(rect);
+ dirty_rects.push_back(rect);
}
-void WindowManager::process_windows()
+void
+WindowManager::process_windows()
{
- if(dirty_rects.empty()) {
- return;
- }
+ 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();
+ std::list<Rect>::iterator drit = dirty_rects.begin();
+ Rect uni = *drit++;
+ while (drit != dirty_rects.end()) {
+ uni = rect_union(uni, *drit++);
+ }
+ dirty_rects.clear();
- wait_vsync();
+ wait_vsync();
- if(!background) {
- fill_rect(uni, bg_color[0], bg_color[1], bg_color[2]);
- }
- else {
- blit(background->pixels, Rect(0, 0, background->width, background->height),
- get_framebuffer(), get_screen_size(), 0, 0);
- }
+ if (!background) {
+ fill_rect(uni, bg_color[0], bg_color[1], bg_color[2]);
+ } else {
+ blit(background->pixels,
+ Rect(0, 0, background->width, background->height),
+ get_framebuffer(),
+ get_screen_size(),
+ 0,
+ 0);
+ }
- root_win->draw_children(uni);
+ root_win->draw_children(uni);
- // draw mouse cursor
- int mouse_x, mouse_y;
- get_pointer_pos(&mouse_x, &mouse_y);
+ // draw mouse cursor
+ int mouse_x, mouse_y;
+ get_pointer_pos(&mouse_x, &mouse_y);
- blit_key(mouse_cursor.get_image(), mouse_cursor.get_rect(),
- get_framebuffer(), get_screen_size(), mouse_x, mouse_y,
- 0, 0, 0);
+ blit_key(mouse_cursor.get_image(),
+ mouse_cursor.get_rect(),
+ get_framebuffer(),
+ get_screen_size(),
+ mouse_x,
+ mouse_y,
+ 0,
+ 0,
+ 0);
- Rect mouse_rect(mouse_x, mouse_y, mouse_cursor.get_width(), mouse_cursor.get_height());
- invalidate_region(mouse_rect);
+ Rect mouse_rect(
+ mouse_x, mouse_y, mouse_cursor.get_width(), mouse_cursor.get_height());
+ invalidate_region(mouse_rect);
- gfx_update(uni);
+ gfx_update(uni);
}
-void WindowManager::add_window(Window *win)
+void
+WindowManager::add_window(Window *win)
{
- if(!win || win == root_win) {
- return;
- }
+ if (!win || win == root_win) {
+ return;
+ }
- root_win->add_child(win);
+ root_win->add_child(win);
- if(windows.empty()) {
- focused_win = win;
- }
+ if (windows.empty()) {
+ focused_win = win;
+ }
- if(win->get_managed()) {
- create_frame(win);
- }
+ if (win->get_managed()) {
+ create_frame(win);
+ }
- windows.push_back(win);
+ windows.push_back(win);
}
-void WindowManager::remove_window(Window *win)
+void
+WindowManager::remove_window(Window *win)
{
- std::list<Window*>::iterator it;
- it = std::find(windows.begin(), windows.end(), win);
+ std::list<Window *>::iterator it;
+ it = std::find(windows.begin(), windows.end(), win);
- if(it != windows.end()) {
- windows.erase(it);
- }
+ if (it != windows.end()) {
+ windows.erase(it);
+ }
}
-void WindowManager::set_focused_window(Window *win)
+void
+WindowManager::set_focused_window(Window *win)
{
- if(win && win == focused_win) {
- return;
- }
+ if (win && win == focused_win) {
+ return;
+ }
- if(focused_win) {
- // invalidate the frame (if any)
- Window *parent = focused_win->get_parent();
- if(parent && parent != root_win) {
- parent->invalidate();
- }
- }
+ if (focused_win) {
+ // invalidate the frame (if any)
+ Window *parent = focused_win->get_parent();
+ if (parent && parent != root_win) {
+ parent->invalidate();
+ }
+ }
- if(!win) {
- focused_win = 0;
- return;
- }
+ if (!win) {
+ focused_win = 0;
+ return;
+ }
- if(win->get_focusable()) {
- focused_win = win;
- return;
- }
+ if (win->get_focusable()) {
+ focused_win = win;
+ return;
+ }
- Window **children = win->get_children();
- for(int i=0; i<win->get_children_count(); i++) {
- if(children[0]->get_focusable()) {
- set_focused_window(children[0]);
- return;
- }
- }
+ Window **children = win->get_children();
+ for (int i = 0; i < win->get_children_count(); i++) {
+ if (children[0]->get_focusable()) {
+ set_focused_window(children[0]);
+ return;
+ }
+ }
- focused_win = 0;
+ focused_win = 0;
}
-const Window *WindowManager::get_focused_window() const
+const Window *
+WindowManager::get_focused_window() const
{
- return focused_win;
+ return focused_win;
}
-Window *WindowManager::get_focused_window()
+Window *
+WindowManager::get_focused_window()
{
- return focused_win;
+ return focused_win;
}
-Window *WindowManager::get_window_at_pos(int pointer_x, int pointer_y)
+Window *
+WindowManager::get_window_at_pos(int pointer_x, int pointer_y)
{
- Window *root_win = wm->get_root_window();
- Window **children = root_win->get_children();
- for(int i=root_win->get_children_count() - 1; i>=0; i--) {
- if(children[i]->contains_point(pointer_x, pointer_y)) {
- return children[i];
- }
- }
+ Window *root_win = wm->get_root_window();
+ Window **children = root_win->get_children();
+ for (int i = root_win->get_children_count() - 1; i >= 0; i--) {
+ if (children[i]->contains_point(pointer_x, pointer_y)) {
+ return children[i];
+ }
+ }
- return 0;
+ return 0;
}
-Window *WindowManager::get_root_window() const
+Window *
+WindowManager::get_root_window() const
{
- return root_win;
+ return root_win;
}
-void WindowManager::set_focused_frame_color(int r, int g, int b)
+void
+WindowManager::set_focused_frame_color(int r, int g, int b)
{
- frame_fcolor[0] = r;
- frame_fcolor[1] = g;
- frame_fcolor[2] = b;
+ frame_fcolor[0] = r;
+ frame_fcolor[1] = g;
+ frame_fcolor[2] = b;
}
-void WindowManager::get_focused_frame_color(int *r, int *g, int *b) const
+void
+WindowManager::get_focused_frame_color(int *r, int *g, int *b) const
{
- *r = frame_fcolor[0];
- *g = frame_fcolor[1];
- *b = frame_fcolor[2];
+ *r = frame_fcolor[0];
+ *g = frame_fcolor[1];
+ *b = frame_fcolor[2];
}
-void WindowManager::set_unfocused_frame_color(int r, int g, int b)
+void
+WindowManager::set_unfocused_frame_color(int r, int g, int b)
{
- frame_ucolor[0] = r;
- frame_ucolor[1] = g;
- frame_ucolor[2] = b;
+ frame_ucolor[0] = r;
+ frame_ucolor[1] = g;
+ frame_ucolor[2] = b;
}
-void WindowManager::get_unfocused_frame_color(int *r, int *g, int *b) const
+void
+WindowManager::get_unfocused_frame_color(int *r, int *g, int *b) const
{
- *r = frame_ucolor[0];
- *g = frame_ucolor[1];
- *b = frame_ucolor[2];
+ *r = frame_ucolor[0];
+ *g = frame_ucolor[1];
+ *b = frame_ucolor[2];
}
-void WindowManager::set_frame_size(int sz)
+void
+WindowManager::set_frame_size(int sz)
{
- frame_thickness = sz;
+ frame_thickness = sz;
}
-int WindowManager::get_frame_size() const
+int
+WindowManager::get_frame_size() const
{
- return frame_thickness;
+ return frame_thickness;
}
-void WindowManager::set_titlebar_size(int sz)
+void
+WindowManager::set_titlebar_size(int sz)
{
- titlebar_thickness = sz;
+ titlebar_thickness = sz;
}
-int WindowManager::get_titlebar_size() const
+int
+WindowManager::get_titlebar_size() const
{
- return titlebar_thickness;
+ return titlebar_thickness;
}
-void WindowManager::set_bevel_size(int sz)
+void
+WindowManager::set_bevel_size(int sz)
{
- bevel_sz = sz;
+ bevel_sz = sz;
}
-int WindowManager::get_bevel_size() const
+int
+WindowManager::get_bevel_size() const
{
- return bevel_sz;
+ return bevel_sz;
}
-void WindowManager::set_background_color(int r, int g, int b)
+void
+WindowManager::set_background_color(int r, int g, int b)
{
- bg_color[0] = r;
- bg_color[1] = g;
- bg_color[2] = b;
+ bg_color[0] = r;
+ bg_color[1] = g;
+ bg_color[2] = b;
}
-void WindowManager::get_background_color(int *r, int *g, int *b) const
+void
+WindowManager::get_background_color(int *r, int *g, int *b) const
{
- *r = bg_color[0];
- *g = bg_color[1];
- *b = bg_color[2];
+ *r = bg_color[0];
+ *g = bg_color[1];
+ *b = bg_color[2];
}
-void WindowManager::set_background(const Pixmap *pixmap)
+void
+WindowManager::set_background(const Pixmap *pixmap)
{
- if(background) {
- delete background;
- }
+ if (background) {
+ delete background;
+ }
- if(pixmap) {
- background = new Pixmap(*pixmap);
- }
- else {
- background = 0;
- }
+ if (pixmap) {
+ background = new Pixmap(*pixmap);
+ } else {
+ background = 0;
+ }
}
-const Pixmap *WindowManager::get_background() const
+const Pixmap *
+WindowManager::get_background() const
{
- return background;
+ return background;
}
-Window *WindowManager::get_grab_window() const
+Window *
+WindowManager::get_grab_window() const
{
- return grab_win;
+ return grab_win;
}
-void WindowManager::grab_mouse(Window *win)
+void
+WindowManager::grab_mouse(Window *win)
{
- grab_win = win;
+ grab_win = win;
}
-void WindowManager::release_mouse()
+void
+WindowManager::release_mouse()
{
- grab_win = 0;
+ grab_win = 0;
}
-void WindowManager::raise_window(Window *win)
+void
+WindowManager::raise_window(Window *win)
{
- if(!win) {
- return;
- }
+ if (!win) {
+ return;
+ }
- Window *parent = win->get_parent();
- if(parent != root_win) {
- if(parent->get_parent() == root_win) {
- win = parent;
- }
- else {
- return;
- }
- }
+ Window *parent = win->get_parent();
+ if (parent != root_win) {
+ if (parent->get_parent() == root_win) {
+ win = parent;
+ } else {
+ return;
+ }
+ }
- root_win->remove_child(win);
- root_win->add_child(win);
+ root_win->remove_child(win);
+ root_win->add_child(win);
}
-void WindowManager::sink_window(Window *win)
+void
+WindowManager::sink_window(Window *win)
{
- if(!win) {
- return;
- }
+ if (!win) {
+ return;
+ }
- std::list<Window*>::iterator it;
- it = std::find(windows.begin(), windows.end(), win);
- if(it != windows.end()) {
- windows.erase(it);
- windows.push_front(win);
- }
+ std::list<Window *>::iterator it;
+ it = std::find(windows.begin(), windows.end(), win);
+ if (it != windows.end()) {
+ windows.erase(it);
+ windows.push_front(win);
+ }
}
-void WindowManager::maximize_window(Window *win)
+void
+WindowManager::maximize_window(Window *win)
{
- win->normal_rect = win->rect;
-
- Rect rect = get_screen_size();
-
- Window *frame;
- if((frame = win->get_parent())) {
- frame->normal_rect = frame->rect;
- frame->resize(rect.width, rect.height);
- frame->move(rect.x, rect.y);
+ win->normal_rect = win->rect;
- rect.width -= frame_thickness * 2;
- rect.height -= frame_thickness * 2 + titlebar_thickness;
- }
- else {
- win->move(0, 0);
- }
+ Rect rect = get_screen_size();
- win->resize(rect.width, rect.height);
- win->set_state(Window::STATE_MAXIMIZED);
+ Window *frame;
+ if ((frame = win->get_parent())) {
+ frame->normal_rect = frame->rect;
+ frame->resize(rect.width, rect.height);
+ frame->move(rect.x, rect.y);
- invalidate_region(rect);
-}
-
-void WindowManager::unmaximize_window(Window *win)
-{
- win->resize(win->normal_rect.width, win->normal_rect.height);
- win->move(win->normal_rect.x, win->normal_rect.y);
+ rect.width -= frame_thickness * 2;
+ rect.height -= frame_thickness * 2 + titlebar_thickness;
+ } else {
+ win->move(0, 0);
+ }
- Window *frame;
- if((frame = win->get_parent())) {
- frame->resize(frame->normal_rect.width, frame->normal_rect.height);
- frame->move(frame->normal_rect.x, frame->normal_rect.y);
- }
+ win->resize(rect.width, rect.height);
+ win->set_state(Window::STATE_MAXIMIZED);
- win->set_state(Window::STATE_NORMAL);
+ invalidate_region(rect);
}
-static void display(Window *win)
-{
- //frame display:
- Window *child = win->get_children()[0];
- int r, g, b;
- Rect rect = win->get_absolute_rect();
-
- int tbar = wm->get_titlebar_size();
- int frm = wm->get_frame_size();
-
-
-
- if(child == wm->get_focused_window()) {
- wm->get_focused_frame_color(&r, &g, &b);
- }
- else {
- wm->get_unfocused_frame_color(&r, &g, &b);
- }
-
- // draw the four frame sides (top, bottom, left, right)
- fill_rect(Rect(rect.x, rect.y, rect.width, frm), r, g, b);
- fill_rect(Rect(rect.x, rect.y + rect.height - frm, rect.width, frm), r, g, b);
- fill_rect(Rect(rect.x, rect.y + frm, frm, rect.height - 2 * frm), r, g, b);
- fill_rect(Rect(rect.x + rect.width - frm, rect.y + frm, frm, rect.height - 2 * frm), r, g, b);
- // draw the titlebar
- fill_rect(Rect(rect.x + frm, rect.y + frm, rect.width - 2 * frm, tbar), r, g, b);
-
-
- int val = (r + g + b) / 3;
- int roffs = val < 128 ? r / 2 : (255 - r) / 2;
- int goffs = val < 128 ? g / 2 : (255 - g) / 2;
- int boffs = val < 128 ? b / 2 : (255 - b) / 2;
-
- // draw bevels
- int dark_r = r - roffs;
- int dark_g = g - goffs;
- int dark_b = b - boffs;
-
- int lt_r = r + roffs;
- int lt_g = g + goffs;
- int lt_b = b + boffs;
-
-
- set_text_position(rect.x + frm + 2, rect.y + frm + tbar - 5);
- set_text_color(80, 80, 80);
- draw_text(child->get_title());
- set_text_position(rect.x + frm + 1, rect.y + frm + tbar - 6);
- set_text_color(255, 255, 255);
- draw_text(child->get_title());
-
- int bevel = wm->get_bevel_size();
- fill_rect(Rect(rect.x, rect.y, bevel, rect.height), lt_r, lt_g, lt_b);
- fill_rect(Rect(rect.x, rect.y + rect.height - bevel, rect.width, bevel), dark_r, dark_g, dark_b);
- fill_rect(Rect(rect.x + rect.width - bevel, rect.y, bevel, rect.height), dark_r, dark_g, dark_b);
- fill_rect(Rect(rect.x, rect.y, rect.width, bevel), lt_r, lt_g, lt_b);
-
- Rect inner = Rect(rect.x + frm, rect.y + frm + tbar, rect.width - frm * 2, rect.height - frm * 2 - tbar);
- fill_rect(Rect(inner.x - bevel, inner.y + inner.height, inner.width + 2 * bevel, bevel), lt_r, lt_g, lt_b);
- fill_rect(Rect(inner.x - bevel, inner.y - bevel, bevel, inner.height + 2 * bevel), dark_r, dark_g, dark_b);
- fill_rect(Rect(inner.x + inner.width, inner.y - bevel, bevel, inner.height + 2 * bevel), lt_r, lt_g, lt_b);
- fill_rect(Rect(inner.x - bevel, inner.y - bevel, inner.width + 2 * bevel, bevel), dark_r, dark_g, dark_b);
+void
+WindowManager::unmaximize_window(Window *win)
+{
+ win->resize(win->normal_rect.width, win->normal_rect.height);
+ win->move(win->normal_rect.x, win->normal_rect.y);
+
+ Window *frame;
+ if ((frame = win->get_parent())) {
+ frame->resize(frame->normal_rect.width, frame->normal_rect.height);
+ frame->move(frame->normal_rect.x, frame->normal_rect.y);
+ }
+
+ win->set_state(Window::STATE_NORMAL);
+}
+
+static void
+display(Window *win)
+{
+ // frame display:
+ Window *child = win->get_children()[0];
+ int r, g, b;
+ Rect rect = win->get_absolute_rect();
+
+ int tbar = wm->get_titlebar_size();
+ int frm = wm->get_frame_size();
+
+ if (child == wm->get_focused_window()) {
+ wm->get_focused_frame_color(&r, &g, &b);
+ } else {
+ wm->get_unfocused_frame_color(&r, &g, &b);
+ }
+
+ // draw the four frame sides (top, bottom, left, right)
+ fill_rect(Rect(rect.x, rect.y, rect.width, frm), r, g, b);
+ fill_rect(
+ Rect(rect.x, rect.y + rect.height - frm, rect.width, frm), r, g, b);
+ fill_rect(Rect(rect.x, rect.y + frm, frm, rect.height - 2 * frm), r, g, b);
+ fill_rect(
+ Rect(
+ rect.x + rect.width - frm, rect.y + frm, frm, rect.height - 2 * frm),
+ r,
+ g,
+ b);
+ // draw the titlebar
+ fill_rect(
+ Rect(rect.x + frm, rect.y + frm, rect.width - 2 * frm, tbar), r, g, b);
+
+ int val = (r + g + b) / 3;
+ int roffs = val < 128 ? r / 2 : (255 - r) / 2;
+ int goffs = val < 128 ? g / 2 : (255 - g) / 2;
+ int boffs = val < 128 ? b / 2 : (255 - b) / 2;
+
+ // draw bevels
+ int dark_r = r - roffs;
+ int dark_g = g - goffs;
+ int dark_b = b - boffs;
+
+ int lt_r = r + roffs;
+ int lt_g = g + goffs;
+ int lt_b = b + boffs;
+
+ set_text_position(rect.x + frm + 2, rect.y + frm + tbar - 5);
+ set_text_color(80, 80, 80);
+ draw_text(child->get_title());
+ set_text_position(rect.x + frm + 1, rect.y + frm + tbar - 6);
+ set_text_color(255, 255, 255);
+ draw_text(child->get_title());
+
+ int bevel = wm->get_bevel_size();
+ fill_rect(Rect(rect.x, rect.y, bevel, rect.height), lt_r, lt_g, lt_b);
+ fill_rect(Rect(rect.x, rect.y + rect.height - bevel, rect.width, bevel),
+ dark_r,
+ dark_g,
+ dark_b);
+ fill_rect(Rect(rect.x + rect.width - bevel, rect.y, bevel, rect.height),
+ dark_r,
+ dark_g,
+ dark_b);
+ fill_rect(Rect(rect.x, rect.y, rect.width, bevel), lt_r, lt_g, lt_b);
+
+ Rect inner = Rect(rect.x + frm,
+ rect.y + frm + tbar,
+ rect.width - frm * 2,
+ rect.height - frm * 2 - tbar);
+ fill_rect(Rect(inner.x - bevel,
+ inner.y + inner.height,
+ inner.width + 2 * bevel,
+ bevel),
+ lt_r,
+ lt_g,
+ lt_b);
+ fill_rect(
+ Rect(inner.x - bevel, inner.y - bevel, bevel, inner.height + 2 * bevel),
+ dark_r,
+ dark_g,
+ dark_b);
+ fill_rect(Rect(inner.x + inner.width,
+ inner.y - bevel,
+ bevel,
+ inner.height + 2 * bevel),
+ lt_r,
+ lt_g,
+ lt_b);
+ fill_rect(
+ Rect(inner.x - bevel, inner.y - bevel, inner.width + 2 * bevel, bevel),
+ dark_r,
+ dark_g,
+ dark_b);
}
static int prev_x, prev_y;
-static void mouse(Window *win, int bn, bool pressed, int x, int y)
-{
- static long last_click = 0;
-
- if(bn == 0) {
- if(pressed) {
- wm->grab_mouse(win);
- wm->raise_window(win);
- prev_x = x;
- prev_y = y;
- }
- else {
- long time = winnie_get_time();
- if((time - last_click) < DCLICK_INTERVAL) {
- Window *child = win->get_children()[0];
- Window::State state = child->get_state();
- if(state == Window::STATE_MAXIMIZED) {
- wm->unmaximize_window(child);
- }
- else if(state == Window::STATE_NORMAL) {
- wm->maximize_window(child);
- }
- }
- last_click = time;
-
- wm->release_mouse();
- }
- }
-}
-
-static void motion(Window *win, int x, int y)
-{
- int left_bn = get_button(0);
-
- if(left_bn) {
- int dx = x - prev_x;
- int dy = y - prev_y;
- prev_x = x - dx;
- prev_y = y - dy;
-
- if(win->get_children()[0]->get_state() != Window::STATE_MAXIMIZED) {
- Rect rect = win->get_rect();
- win->move(rect.x + dx, rect.y + dy);
- }
- }
+static void
+mouse(Window *win, int bn, bool pressed, int x, int y)
+{
+ static long last_click = 0;
+
+ if (bn == 0) {
+ if (pressed) {
+ wm->grab_mouse(win);
+ wm->raise_window(win);
+ prev_x = x;
+ prev_y = y;
+ } else {
+ long time = winnie_get_time();
+ if ((time - last_click) < DCLICK_INTERVAL) {
+ Window *child = win->get_children()[0];
+ Window::State state = child->get_state();
+ if (state == Window::STATE_MAXIMIZED) {
+ wm->unmaximize_window(child);
+ } else if (state == Window::STATE_NORMAL) {
+ wm->maximize_window(child);
+ }
+ }
+ last_click = time;
+
+ wm->release_mouse();
+ }
+ }
+}
+
+static void
+motion(Window *win, int x, int y)
+{
+ int left_bn = get_button(0);
+
+ if (left_bn) {
+ int dx = x - prev_x;
+ int dy = y - prev_y;
+ prev_x = x - dx;
+ prev_y = y - dy;
+
+ if (win->get_children()[0]->get_state() != Window::STATE_MAXIMIZED) {
+ Rect rect = win->get_rect();
+ win->move(rect.x + dx, rect.y + dy);
+ }
+ }
}
diff --git a/libwinnie/src/wm.h b/libwinnie/src/wm.h
index 854f501..a6ef826 100644
--- a/libwinnie/src/wm.h
+++ b/libwinnie/src/wm.h
@@ -33,79 +33,80 @@ class Window;
bool init_window_manager();
void destroy_window_manager();
-class WindowManager {
+class WindowManager
+{
private:
- std::list<Window*> windows;
+ std::list<Window *> windows;
- std::list<Rect> dirty_rects;
+ std::list<Rect> dirty_rects;
- int bg_color[3];
- int frame_thickness;
- int titlebar_thickness;
- int frame_fcolor[3];
- int frame_ucolor[3];
- int bevel_sz;
+ int bg_color[3];
+ int frame_thickness;
+ int titlebar_thickness;
+ int frame_fcolor[3];
+ int frame_ucolor[3];
+ int bevel_sz;
- Window *root_win;
- Window *focused_win;
- Window *grab_win;
+ Window *root_win;
+ Window *focused_win;
+ Window *grab_win;
- Pixmap mouse_cursor;
- Pixmap *background;
+ Pixmap mouse_cursor;
+ Pixmap *background;
- void create_frame(Window *win);
- void destroy_frame(Window *win);
+ void create_frame(Window *win);
+ void destroy_frame(Window *win);
public:
- WindowManager();
- ~WindowManager();
+ WindowManager();
+ ~WindowManager();
- void invalidate_region(const Rect &rect);
- void process_windows();
+ void invalidate_region(const Rect &rect);
+ void process_windows();
- void add_window(Window *win);
- void remove_window(Window *win);
+ void add_window(Window *win);
+ void remove_window(Window *win);
- void set_focused_window(Window *win);
- const Window *get_focused_window() const;
- Window *get_focused_window();
+ void set_focused_window(Window *win);
+ const Window *get_focused_window() const;
+ Window *get_focused_window();
- Window *get_window_at_pos(int pointer_x, int pointer_y);
- Window *get_root_window() const;
+ Window *get_window_at_pos(int pointer_x, int pointer_y);
+ Window *get_root_window() const;
- void set_focused_frame_color(int r, int g, int b);
- void get_focused_frame_color(int *r, int *g, int *b) const;
+ void set_focused_frame_color(int r, int g, int b);
+ void get_focused_frame_color(int *r, int *g, int *b) const;
- void set_unfocused_frame_color(int r, int g, int b);
- void get_unfocused_frame_color(int *r, int *g, int *b) const;
+ void set_unfocused_frame_color(int r, int g, int b);
+ void get_unfocused_frame_color(int *r, int *g, int *b) const;
- void set_frame_size(int sz);
- int get_frame_size() const;
+ void set_frame_size(int sz);
+ int get_frame_size() const;
- void set_titlebar_size(int sz);
- int get_titlebar_size() const;
+ void set_titlebar_size(int sz);
+ int get_titlebar_size() const;
- void set_bevel_size(int sz);
- int get_bevel_size() const;
+ void set_bevel_size(int sz);
+ int get_bevel_size() const;
- void set_background_color(int r, int g, int b);
- void get_background_color(int *r, int *g, int *b) const;
+ void set_background_color(int r, int g, int b);
+ void get_background_color(int *r, int *g, int *b) const;
- void set_background(const Pixmap *pixmap);
- const Pixmap *get_background() const;
+ void set_background(const Pixmap *pixmap);
+ const Pixmap *get_background() const;
- Window *get_grab_window() const;
+ Window *get_grab_window() const;
- void grab_mouse(Window *win);
- void release_mouse();
+ void grab_mouse(Window *win);
+ void release_mouse();
- void raise_window(Window *win);
- void sink_window(Window *win);
+ void raise_window(Window *win);
+ void sink_window(Window *win);
- void maximize_window(Window *win);
- void unmaximize_window(Window *win);
+ void maximize_window(Window *win);
+ void unmaximize_window(Window *win);
};
extern WindowManager *wm;
-#endif // WM_H_
+#endif // WM_H_