Gfxprim
Threads by month
- ----- 2026 -----
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
May 2012
- 2 participants
- 55 discussions
[repo.or.cz] gfxprim.git branch master updated: b02d3680c656b2274293750005a57cd3ff602631
by metan 04 May '12
by metan 04 May '12
04 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
discards 71fb36b2881535c76334f93cc3808dc22941f31d (commit)
via b02d3680c656b2274293750005a57cd3ff602631 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (71fb36b2881535c76334f93cc3808dc22941f31d)
N -- N -- N (b02d3680c656b2274293750005a57cd3ff602631)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/b02d3680c656b2274293750005a57cd3ff60…
commit b02d3680c656b2274293750005a57cd3ff602631
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 4 17:06:29 2012 +0200
backends: Improve X11 backend.
* Fix region update to update only the actuall region
* Add basic key event support
* Fix compilation without Xlib.
diff --git a/include/input/GP_InputDriverX11.h b/include/input/GP_InputDriverX11.h
new file mode 100644
index 0000000..117a3e0
--- /dev/null
+++ b/include/input/GP_InputDriverX11.h
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+
+
+ */
+
+#ifndef GP_INPUT_DRIVER_X11_H
+#define GP_INPUT_DRIVER_X11_H
+
+#include <stdint.h>
+#include <X11/Xlib.h>
+
+/*
+ * Converts X11 event to GFXprim event and puts it into the queue.
+ */
+void GP_InputDriverX11EventPut(XEvent *ev);
+
+#endif /* GP_INPUT_DRIVER_X11_H */
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index 30bd65d..f12ade8 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -20,11 +20,16 @@
* *
*****************************************************************************/
+#include "../../config.h"
+
+#ifdef HAVE_LIBX11
+
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#include "GP_X11.h"
#include "core/GP_Debug.h"
+#include "input/GP_InputDriverX11.h"
+#include "GP_X11.h"
struct x11_priv {
Display *dpy;
@@ -50,13 +55,29 @@ static void x11_exit(GP_Backend *self)
free(self);
}
+static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ GP_DEBUG(4, "Updating rect %ix%i-%ix%i", x0, y0, x1, y1);
+
+ XLockDisplay(x11->dpy);
+
+ XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, x0, y0, x0, y0, x1-x0, y1-y0);
+ XFlush(x11->dpy);
+
+ XUnlockDisplay(x11->dpy);
+}
+
static void x11_flip(GP_Backend *self)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
unsigned int w = x11->context->w;
unsigned int h = x11->context->h;
- GP_DEBUG(3, "Flipping context");
+ GP_DEBUG(4, "Flipping context");
XLockDisplay(x11->dpy);
@@ -79,11 +100,21 @@ static void x11_poll(GP_Backend *self)
switch (ev.type) {
case Expose:
- x11_flip(self);
+ GP_DEBUG(4, "Expose %ix%i-%ix%i %i",
+ ev.xexpose.x, ev.xexpose.y,
+ ev.xexpose.width, ev.xexpose.height,
+ ev.xexpose.count);
+ x11_update_rect(self, ev.xexpose.x, ev.xexpose.y,
+ ev.xexpose.x + ev.xexpose.width,
+ ev.xexpose.y + ev.xexpose.height);
break;
case MapNotify:
GP_DEBUG(1, "Shown");
break;
+ case KeyPress:
+ case KeyRelease:
+ GP_InputDriverX11EventPut(&ev);
+ break;
}
}
@@ -142,7 +173,8 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
}
/* Select events */
- XSelectInput(x11->dpy, x11->win, StructureNotifyMask|ExposureMask);
+ XSelectInput(x11->dpy, x11->win, StructureNotifyMask | ExposureMask |
+ KeyPressMask | KeyReleaseMask);
/* Set window caption */
XmbSetWMProperties(x11->dpy, x11->win, caption, caption,
@@ -153,7 +185,6 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
XFlush(x11->dpy);
/*
-
enum GP_PixelType pixel_type;
pixel_type = GP_PixelRGBLookup(vscri.red.length, vscri.red.offset,
vscri.green.length, vscri.green.offset,
@@ -172,7 +203,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
backend->name = "X11";
backend->context = x11->context;
backend->Flip = x11_flip;
- backend->UpdateRect = NULL;
+ backend->UpdateRect = x11_update_rect;
backend->Exit = x11_exit;
backend->fd_list = NULL;
backend->Poll = x11_poll;
@@ -188,3 +219,16 @@ err0:
free(backend);
return NULL;
}
+
+#else
+
+#include "GP_Backend.h"
+
+GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
+ unsigned int w, unsigned int h,
+ const char *caption)
+{
+ return NULL;
+}
+
+#endif /* HAVE_LIBX11 */
diff --git a/libs/input/GP_InputDriverX11.c b/libs/input/GP_InputDriverX11.c
new file mode 100644
index 0000000..d3b21c1
--- /dev/null
+++ b/libs/input/GP_InputDriverX11.c
@@ -0,0 +1,112 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include "../../config.h"
+
+#include "core/GP_Debug.h"
+#include "GP_Event.h"
+#include "GP_InputDriverX11.h"
+
+#ifdef HAVE_LIBX11
+
+/* X11 keycodes */
+static uint16_t keycode_table[] = {
+ GP_KEY_ESC, GP_KEY_1, GP_KEY_2, GP_KEY_3,
+ GP_KEY_4, GP_KEY_5, GP_KEY_6, GP_KEY_7,
+ GP_KEY_8, GP_KEY_9, GP_KEY_0, GP_KEY_MINUS,
+ GP_KEY_EQUAL, GP_KEY_BACKSPACE, GP_KEY_TAB, GP_KEY_Q,
+ GP_KEY_W, GP_KEY_E, GP_KEY_R, GP_KEY_T,
+ GP_KEY_Y, GP_KEY_U, GP_KEY_I, GP_KEY_O,
+ GP_KEY_P, GP_KEY_LEFT_BRACE, GP_KEY_RIGHT_BRACE, GP_KEY_ENTER,
+ GP_KEY_LEFT_CTRL, GP_KEY_A, GP_KEY_S, GP_KEY_D,
+ GP_KEY_F, GP_KEY_G, GP_KEY_H, GP_KEY_J,
+ GP_KEY_K, GP_KEY_L, GP_KEY_SEMICOLON, GP_KEY_APOSTROPHE,
+ 0, GP_KEY_LEFT_SHIFT, GP_KEY_BACKSLASH, GP_KEY_Z,
+ GP_KEY_X, GP_KEY_C, GP_KEY_V, GP_KEY_B,
+ GP_KEY_N, GP_KEY_M, GP_KEY_COMMA, GP_KEY_DOT,
+ GP_KEY_SLASH, GP_KEY_RIGHT_SHIFT, 0, GP_KEY_LEFT_ALT,
+ GP_KEY_SPACE, GP_KEY_CAPS_LOCK, GP_KEY_F1, GP_KEY_F2,
+ GP_KEY_F3, GP_KEY_F4, GP_KEY_F5, GP_KEY_F6,
+ GP_KEY_F7, GP_KEY_F8, GP_KEY_F9, GP_KEY_F10,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, GP_KEY_F11, GP_KEY_F12,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ GP_KEY_RIGHT_CTRL, 0, /* PRINTSCREEN */0, GP_KEY_RIGHT_ALT,
+ 0, GP_KEY_HOME, GP_KEY_UP, GP_KEY_PAGE_UP,
+ GP_KEY_LEFT, GP_KEY_RIGHT, GP_KEY_END, GP_KEY_DOWN,
+ GP_KEY_PAGE_DOWN, 0, GP_KEY_DELETE,
+};
+
+static const uint16_t keycode_table_size = sizeof(keycode_table)/2;
+
+void GP_InputDriverX11EventPut(XEvent *ev)
+{
+ int key = 0, keycode, press = 0;
+
+ switch (ev->type) {
+ /*
+ case SDL_MOUSEMOTION:
+ GP_EventPushRel(ev->motion.xrel, ev->motion.yrel, NULL);
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ switch (ev->button.button) {
+ case 1:
+ key = GP_BTN_LEFT;
+ break;
+ case 2:
+ key = GP_BTN_MIDDLE;
+ break;
+ case 3:
+ key = GP_BTN_RIGHT;
+ break;
+ default:
+ return;
+ }
+
+ GP_EventPush(GP_EV_KEY, key, ev->button.state, NULL);
+ break;
+ */
+ case KeyPress:
+ press = 1;
+ case KeyRelease:
+ keycode = ev->xkey.keycode;
+
+ if (keycode > 8 && keycode - 9 <= keycode_table_size)
+ key = keycode_table[keycode - 9];
+
+ if (key == 0) {
+ GP_DEBUG(0, "Unmapped X11 keycode %02x", keycode);
+ return;
+ }
+
+ GP_DEBUG(0, "Mapped X11 keycode %02x", keycode);
+ GP_EventPushKey(key, press, NULL);
+ break;
+ }
+}
+
+#endif /* HAVE_LIBX11 */
-----------------------------------------------------------------------
Summary of changes:
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 71fb36b2881535c76334f93cc3808dc22941f31d
by metan 04 May '12
by metan 04 May '12
04 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 71fb36b2881535c76334f93cc3808dc22941f31d (commit)
from de77d6cd49f5ec5cb956161d1599c08fda673561 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/71fb36b2881535c76334f93cc3808dc22941…
commit 71fb36b2881535c76334f93cc3808dc22941f31d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 4 17:06:29 2012 +0200
backeds: Improve X11 backend.
* Fix region update to update only the actuall region
* Add basic key event support
* Fix compilation without Xlib.
diff --git a/include/input/GP_InputDriverX11.h b/include/input/GP_InputDriverX11.h
new file mode 100644
index 0000000..117a3e0
--- /dev/null
+++ b/include/input/GP_InputDriverX11.h
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+
+
+ */
+
+#ifndef GP_INPUT_DRIVER_X11_H
+#define GP_INPUT_DRIVER_X11_H
+
+#include <stdint.h>
+#include <X11/Xlib.h>
+
+/*
+ * Converts X11 event to GFXprim event and puts it into the queue.
+ */
+void GP_InputDriverX11EventPut(XEvent *ev);
+
+#endif /* GP_INPUT_DRIVER_X11_H */
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index 30bd65d..f12ade8 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -20,11 +20,16 @@
* *
*****************************************************************************/
+#include "../../config.h"
+
+#ifdef HAVE_LIBX11
+
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#include "GP_X11.h"
#include "core/GP_Debug.h"
+#include "input/GP_InputDriverX11.h"
+#include "GP_X11.h"
struct x11_priv {
Display *dpy;
@@ -50,13 +55,29 @@ static void x11_exit(GP_Backend *self)
free(self);
}
+static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ GP_DEBUG(4, "Updating rect %ix%i-%ix%i", x0, y0, x1, y1);
+
+ XLockDisplay(x11->dpy);
+
+ XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, x0, y0, x0, y0, x1-x0, y1-y0);
+ XFlush(x11->dpy);
+
+ XUnlockDisplay(x11->dpy);
+}
+
static void x11_flip(GP_Backend *self)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
unsigned int w = x11->context->w;
unsigned int h = x11->context->h;
- GP_DEBUG(3, "Flipping context");
+ GP_DEBUG(4, "Flipping context");
XLockDisplay(x11->dpy);
@@ -79,11 +100,21 @@ static void x11_poll(GP_Backend *self)
switch (ev.type) {
case Expose:
- x11_flip(self);
+ GP_DEBUG(4, "Expose %ix%i-%ix%i %i",
+ ev.xexpose.x, ev.xexpose.y,
+ ev.xexpose.width, ev.xexpose.height,
+ ev.xexpose.count);
+ x11_update_rect(self, ev.xexpose.x, ev.xexpose.y,
+ ev.xexpose.x + ev.xexpose.width,
+ ev.xexpose.y + ev.xexpose.height);
break;
case MapNotify:
GP_DEBUG(1, "Shown");
break;
+ case KeyPress:
+ case KeyRelease:
+ GP_InputDriverX11EventPut(&ev);
+ break;
}
}
@@ -142,7 +173,8 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
}
/* Select events */
- XSelectInput(x11->dpy, x11->win, StructureNotifyMask|ExposureMask);
+ XSelectInput(x11->dpy, x11->win, StructureNotifyMask | ExposureMask |
+ KeyPressMask | KeyReleaseMask);
/* Set window caption */
XmbSetWMProperties(x11->dpy, x11->win, caption, caption,
@@ -153,7 +185,6 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
XFlush(x11->dpy);
/*
-
enum GP_PixelType pixel_type;
pixel_type = GP_PixelRGBLookup(vscri.red.length, vscri.red.offset,
vscri.green.length, vscri.green.offset,
@@ -172,7 +203,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
backend->name = "X11";
backend->context = x11->context;
backend->Flip = x11_flip;
- backend->UpdateRect = NULL;
+ backend->UpdateRect = x11_update_rect;
backend->Exit = x11_exit;
backend->fd_list = NULL;
backend->Poll = x11_poll;
@@ -188,3 +219,16 @@ err0:
free(backend);
return NULL;
}
+
+#else
+
+#include "GP_Backend.h"
+
+GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
+ unsigned int w, unsigned int h,
+ const char *caption)
+{
+ return NULL;
+}
+
+#endif /* HAVE_LIBX11 */
diff --git a/libs/input/GP_InputDriverX11.c b/libs/input/GP_InputDriverX11.c
new file mode 100644
index 0000000..d3b21c1
--- /dev/null
+++ b/libs/input/GP_InputDriverX11.c
@@ -0,0 +1,112 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include "../../config.h"
+
+#include "core/GP_Debug.h"
+#include "GP_Event.h"
+#include "GP_InputDriverX11.h"
+
+#ifdef HAVE_LIBX11
+
+/* X11 keycodes */
+static uint16_t keycode_table[] = {
+ GP_KEY_ESC, GP_KEY_1, GP_KEY_2, GP_KEY_3,
+ GP_KEY_4, GP_KEY_5, GP_KEY_6, GP_KEY_7,
+ GP_KEY_8, GP_KEY_9, GP_KEY_0, GP_KEY_MINUS,
+ GP_KEY_EQUAL, GP_KEY_BACKSPACE, GP_KEY_TAB, GP_KEY_Q,
+ GP_KEY_W, GP_KEY_E, GP_KEY_R, GP_KEY_T,
+ GP_KEY_Y, GP_KEY_U, GP_KEY_I, GP_KEY_O,
+ GP_KEY_P, GP_KEY_LEFT_BRACE, GP_KEY_RIGHT_BRACE, GP_KEY_ENTER,
+ GP_KEY_LEFT_CTRL, GP_KEY_A, GP_KEY_S, GP_KEY_D,
+ GP_KEY_F, GP_KEY_G, GP_KEY_H, GP_KEY_J,
+ GP_KEY_K, GP_KEY_L, GP_KEY_SEMICOLON, GP_KEY_APOSTROPHE,
+ 0, GP_KEY_LEFT_SHIFT, GP_KEY_BACKSLASH, GP_KEY_Z,
+ GP_KEY_X, GP_KEY_C, GP_KEY_V, GP_KEY_B,
+ GP_KEY_N, GP_KEY_M, GP_KEY_COMMA, GP_KEY_DOT,
+ GP_KEY_SLASH, GP_KEY_RIGHT_SHIFT, 0, GP_KEY_LEFT_ALT,
+ GP_KEY_SPACE, GP_KEY_CAPS_LOCK, GP_KEY_F1, GP_KEY_F2,
+ GP_KEY_F3, GP_KEY_F4, GP_KEY_F5, GP_KEY_F6,
+ GP_KEY_F7, GP_KEY_F8, GP_KEY_F9, GP_KEY_F10,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, GP_KEY_F11, GP_KEY_F12,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ GP_KEY_RIGHT_CTRL, 0, /* PRINTSCREEN */0, GP_KEY_RIGHT_ALT,
+ 0, GP_KEY_HOME, GP_KEY_UP, GP_KEY_PAGE_UP,
+ GP_KEY_LEFT, GP_KEY_RIGHT, GP_KEY_END, GP_KEY_DOWN,
+ GP_KEY_PAGE_DOWN, 0, GP_KEY_DELETE,
+};
+
+static const uint16_t keycode_table_size = sizeof(keycode_table)/2;
+
+void GP_InputDriverX11EventPut(XEvent *ev)
+{
+ int key = 0, keycode, press = 0;
+
+ switch (ev->type) {
+ /*
+ case SDL_MOUSEMOTION:
+ GP_EventPushRel(ev->motion.xrel, ev->motion.yrel, NULL);
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ switch (ev->button.button) {
+ case 1:
+ key = GP_BTN_LEFT;
+ break;
+ case 2:
+ key = GP_BTN_MIDDLE;
+ break;
+ case 3:
+ key = GP_BTN_RIGHT;
+ break;
+ default:
+ return;
+ }
+
+ GP_EventPush(GP_EV_KEY, key, ev->button.state, NULL);
+ break;
+ */
+ case KeyPress:
+ press = 1;
+ case KeyRelease:
+ keycode = ev->xkey.keycode;
+
+ if (keycode > 8 && keycode - 9 <= keycode_table_size)
+ key = keycode_table[keycode - 9];
+
+ if (key == 0) {
+ GP_DEBUG(0, "Unmapped X11 keycode %02x", keycode);
+ return;
+ }
+
+ GP_DEBUG(0, "Mapped X11 keycode %02x", keycode);
+ GP_EventPushKey(key, press, NULL);
+ break;
+ }
+}
+
+#endif /* HAVE_LIBX11 */
-----------------------------------------------------------------------
Summary of changes:
include/input/{GP_Input.h => GP_InputDriverX11.h} | 20 ++--
libs/backends/GP_X11.c | 56 +++++++++-
libs/input/GP_InputDriverX11.c | 112 +++++++++++++++++++++
3 files changed, 173 insertions(+), 15 deletions(-)
copy include/input/{GP_Input.h => GP_InputDriverX11.h} (86%)
create mode 100644 libs/input/GP_InputDriverX11.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: de77d6cd49f5ec5cb956161d1599c08fda673561
by metan 03 May '12
by metan 03 May '12
03 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via de77d6cd49f5ec5cb956161d1599c08fda673561 (commit)
from 83d2379331b535cc28f96ac11c27ef3565cfebb3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/de77d6cd49f5ec5cb956161d1599c08fda67…
commit de77d6cd49f5ec5cb956161d1599c08fda673561
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu May 3 00:24:48 2012 +0200
backends: Initial Xlib backend, not yet fully working.
What is missing:
* Input driver
* Pixel type detection
* SHM Support
* Reasonable Expose event handling
diff --git a/configure b/configure
index fe0350a..6011867 100755
--- a/configure
+++ b/configure
@@ -187,10 +187,13 @@ if __name__ == '__main__':
["giflib",
"Library to handle, display and manipulate GIF images",
[header_exists, "gif_lib.h"], "", "-lgif"],
+ ["libX11",
+ "X11 library",
+ [header_exists, "X11/Xlib.h"], "", "-lX11"],
["freetype",
"A high-quality and portable font engine",
[header_exists, "ft2build.h"], "", "`freetype-config --libs`"]], cfg)
-
+
parser = OptionParser();
# Enable disable libraries for linking
diff --git a/include/backends/GP_Backends.h b/include/backends/GP_Backends.h
index 0cd74f6..d9420e1 100644
--- a/include/backends/GP_Backends.h
+++ b/include/backends/GP_Backends.h
@@ -39,6 +39,7 @@
*/
#include "backends/GP_LinuxFB.h"
#include "backends/GP_SDL.h"
+#include "backends/GP_X11.h"
/*
* Simplified backend initalization.
diff --git a/include/backends/GP_Backends.h b/include/backends/GP_X11.h
similarity index 78%
copy from include/backends/GP_Backends.h
copy to include/backends/GP_X11.h
index 0cd74f6..198e252 100644
--- a/include/backends/GP_Backends.h
+++ b/include/backends/GP_X11.h
@@ -20,29 +20,21 @@
* *
*****************************************************************************/
-/*
-
- Catch all header for backends.
-
- */
-
-#ifndef BACKENDS_GP_BACKENDS_H
-#define BACKENDS_GP_BACKENDS_H
+#ifndef BACKENDS_GP_X11_H
+#define BACKENDS_GP_X11_H
-/*
- * Base backend definitions.
- */
-#include "backends/GP_Backend.h"
-
-/*
- * Backends.
- */
-#include "backends/GP_LinuxFB.h"
-#include "backends/GP_SDL.h"
+#include "GP_Backend.h"
/*
- * Simplified backend initalization.
+ * Initalize X11 backend.
+ *
+ * The display may be NULL default display. The coordinates are position and
+ * geometry for newly created window.
+ *
+ * Upon failure NULL is returned.
*/
-#include "backends/GP_BackendInit.h"
+GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
+ unsigned int w, unsigned int h,
+ const char *caption);
-#endif /* BACKENDS_GP_BACKENDS_H */
+#endif /* BACKENDS_GP_X11_H */
diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c
index 48ff440..5f6a470 100644
--- a/libs/backends/GP_BackendInit.c
+++ b/libs/backends/GP_BackendInit.c
@@ -24,9 +24,8 @@
#include "core/GP_Debug.h"
-#include "backends/GP_LinuxFB.h"
-#include "backends/GP_SDL.h"
-#include "backends/GP_BackendInit.h"
+#include "GP_Backends.h"
+#include "GP_BackendInit.h"
static void backend_sdl_help(FILE *help, const char *err)
{
@@ -125,21 +124,49 @@ static GP_Backend *backend_fb_init(char *params, const char *caption,
return GP_BackendLinuxFBInit(fb);
}
+static void backend_x11_help(FILE *help, const char *err)
+{
+ if (help == NULL)
+ return;
+
+ if (err != NULL)
+ fprintf(help, "ERROR: %sn", err);
+
+ fprintf(help, "X11 backendn"
+ "-----------n"
+ "X11:WxHn");
+}
+
+static GP_Backend *backend_x11_init(char *params, const char *caption,
+ FILE *help)
+{
+ unsigned int w, h, n;
+
+ if (sscanf(params, "%u%*[xX]%u%n", &w, &h, &n) == 2 && n == strlen(params))
+ return GP_BackendX11Init(NULL, 0, 0, w, h, caption);
+
+ backend_x11_help(help, "X11: Invalid parameters");
+ return NULL;
+}
+
static const char *backend_names[] = {
"SDL", /* libSDL */
"FB", /* Linux Framebuffer */
+ "X11", /* X11 window system */
NULL,
};
static GP_Backend *(*backend_inits[])(char *, const char *, FILE *) = {
backend_sdl_init,
backend_fb_init,
+ backend_x11_init,
NULL,
};
static void (*backend_helps[])(FILE *help, const char *err) = {
backend_sdl_help,
backend_fb_help,
+ backend_x11_help,
NULL,
};
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
new file mode 100644
index 0000000..30bd65d
--- /dev/null
+++ b/libs/backends/GP_X11.c
@@ -0,0 +1,190 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include "GP_X11.h"
+#include "core/GP_Debug.h"
+
+struct x11_priv {
+ Display *dpy;
+ int scr;
+ Window win;
+ Visual *vis;
+ XImage *img;
+
+ GP_Context *context;
+};
+
+static void x11_exit(GP_Backend *self)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ x11->img->data = NULL;
+ XDestroyImage(x11->img);
+ XDestroyWindow(x11->dpy, x11->win);
+ XCloseDisplay(x11->dpy);
+
+ GP_ContextFree(x11->context);
+
+ free(self);
+}
+
+static void x11_flip(GP_Backend *self)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+ unsigned int w = x11->context->w;
+ unsigned int h = x11->context->h;
+
+ GP_DEBUG(3, "Flipping context");
+
+ XLockDisplay(x11->dpy);
+
+ XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, 0, 0, 0, 0, w, h);
+ XFlush(x11->dpy);
+
+ XUnlockDisplay(x11->dpy);
+}
+
+static void x11_poll(GP_Backend *self)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+ XEvent ev;
+
+ XLockDisplay(x11->dpy);
+
+ while (XPending(x11->dpy)) {
+ XNextEvent(x11->dpy, &ev);
+
+ switch (ev.type) {
+ case Expose:
+ x11_flip(self);
+ break;
+ case MapNotify:
+ GP_DEBUG(1, "Shown");
+ break;
+ }
+ }
+
+ XUnlockDisplay(x11->dpy);
+}
+
+GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
+ unsigned int w, unsigned int h,
+ const char *caption)
+{
+ GP_Backend *backend;
+ struct x11_priv *x11;
+
+ GP_DEBUG(1, "Initalizing X11 display '%s'", display);
+
+ backend = malloc(sizeof(GP_Backend) +
+ sizeof(struct x11_priv));
+
+ if (backend == NULL)
+ return NULL;
+
+ x11 = GP_BACKEND_PRIV(backend);
+
+ x11->context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888);
+
+ if (x11->context == NULL)
+ goto err0;
+
+ //TODO: Error checking
+ XInitThreads();
+
+ x11->dpy = XOpenDisplay(display);
+
+ if (x11->dpy == NULL)
+ goto err1;
+
+ x11->scr = DefaultScreen(x11->dpy);
+ x11->vis = DefaultVisual(x11->dpy, x11->scr);
+
+ GP_DEBUG(2, "Opening window '%s' %ix%i-%ux%u",
+ caption, x, y, w, h);
+
+ x11->img = XCreateImage(x11->dpy, x11->vis, 24, ZPixmap, 0, NULL,
+ w, h, 32, 0);
+
+ x11->img->data = (char*)x11->context->pixels;
+
+ x11->win = XCreateWindow(x11->dpy, DefaultRootWindow(x11->dpy),
+ x, y, w, h, 0, CopyFromParent,
+ InputOutput, CopyFromParent, 0, NULL);
+
+ if (x11->win == None) {
+ //TODO: Error message?
+ GP_DEBUG(1, "Failed to create window");
+ goto err2;
+ }
+
+ /* Select events */
+ XSelectInput(x11->dpy, x11->win, StructureNotifyMask|ExposureMask);
+
+ /* Set window caption */
+ XmbSetWMProperties(x11->dpy, x11->win, caption, caption,
+ NULL, 0, NULL, NULL, NULL);
+
+ /* Show window */
+ XMapWindow(x11->dpy, x11->win);
+ XFlush(x11->dpy);
+
+/*
+
+ enum GP_PixelType pixel_type;
+ pixel_type = GP_PixelRGBLookup(vscri.red.length, vscri.red.offset,
+ vscri.green.length, vscri.green.offset,
+ vscri.blue.length, vscri.blue.offset,
+ vscri.transp.length, vscri.transp.offset,
+ vscri.bits_per_pixel);
+
+ if (pixel_type == GP_PIXEL_UNKNOWN) {
+ GP_DEBUG(1, "Unknown pixel typen");
+ goto err3;
+ }
+
+
+*/
+
+ backend->name = "X11";
+ backend->context = x11->context;
+ backend->Flip = x11_flip;
+ backend->UpdateRect = NULL;
+ backend->Exit = x11_exit;
+ backend->fd_list = NULL;
+ backend->Poll = x11_poll;
+
+ return backend;
+//err3:
+// XDestroyWindow(x11->dpy, x11->win);
+err2:
+ XCloseDisplay(x11->dpy);
+err1:
+ GP_ContextFree(x11->context);
+err0:
+ free(backend);
+ return NULL;
+}
-----------------------------------------------------------------------
Summary of changes:
configure | 5 +-
include/backends/GP_Backends.h | 1 +
include/backends/{GP_LinuxFB.h => GP_X11.h} | 21 ++--
libs/backends/GP_BackendInit.c | 33 ++++-
libs/backends/GP_X11.c | 190 +++++++++++++++++++++++++++
5 files changed, 235 insertions(+), 15 deletions(-)
copy include/backends/{GP_LinuxFB.h => GP_X11.h} (79%)
create mode 100644 libs/backends/GP_X11.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 83d2379331b535cc28f96ac11c27ef3565cfebb3
by metan 01 May '12
by metan 01 May '12
01 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 83d2379331b535cc28f96ac11c27ef3565cfebb3 (commit)
via 347598ceea691da3a252b3f119f33e0ee188c6ac (commit)
from f36ba9ddb07263d7922546bbe4b823a029572702 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/83d2379331b535cc28f96ac11c27ef3565cf…
commit 83d2379331b535cc28f96ac11c27ef3565cfebb3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 1 20:55:12 2012 +0200
core: Fix stupid bug in special case blit.
diff --git a/libs/core/GP_Blit.gen.c.t b/libs/core/GP_Blit.gen.c.t
index 50496e6..988223e 100644
--- a/libs/core/GP_Blit.gen.c.t
+++ b/libs/core/GP_Blit.gen.c.t
@@ -59,7 +59,7 @@ void blitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src,
/* General case - memcpy() each horizontal line */
GP_Coord y;
- for (y = y0; y <= y1; y++)
+ for (y = 0; y <= (y1 - y0); y++)
memcpy(GP_PIXEL_ADDR_{{ ps.suffix }}(dst, x2, y2 + y),
GP_PIXEL_ADDR_{{ ps.suffix }}(src, x0, y0 + y),
{{ int(ps.size/8) }} * (x1 - x0 + 1));
http://repo.or.cz/w/gfxprim.git/commit/347598ceea691da3a252b3f119f33e0ee188…
commit 347598ceea691da3a252b3f119f33e0ee188c6ac
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 1 18:56:39 2012 +0200
core: Make the Clipped blit more versatile.
diff --git a/include/core/GP_Blit.h b/include/core/GP_Blit.h
index 46d478b..cacfa8b 100644
--- a/include/core/GP_Blit.h
+++ b/include/core/GP_Blit.h
@@ -48,9 +48,9 @@ void GP_BlitXYXY(const GP_Context *src,
GP_Context *dst, GP_Coord x2, GP_Coord y2);
/*
- * Clipped variant, if destination context size (from x2, y2 to the end of the
- * context) is not big enough the source rectangle is clipped, eg. only initial
- * part of the source (starting on x0, y0) will be blitted.
+ * Clipped variant. Could handle destination coordinates outside of the
+ * destination rectangle (both possitive and negative). Source larger than
+ * destination and so.
*/
void GP_BlitXYXY_Clipped(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
@@ -65,9 +65,9 @@ void GP_BlitXYWH(const GP_Context *src,
GP_Context *dst, GP_Coord x1, GP_Coord y1);
/*
- * Clipped variant, if destination context size (from x1, y1 to the end of the
- * context) is not big enough the source rectangle is clipped, eg. only initial
- * part of the source (starting on x0, y0) will be blitted.
+ * Clipped variant. Could handle destination coordinates outside of the
+ * destination rectangle (both possitive and negative). Source larger than
+ * destination and so.
*/
void GP_BlitXYWH_Clipped(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Size w0, GP_Size h0,
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index 13acb22..3b9f88a 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -76,12 +76,10 @@ void GP_BlitXYXY(const GP_Context *src,
GP_CHECK(x2 + (x1 - x0) < (GP_Coord)GP_ContextW(dst));
GP_CHECK(y2 + (y1 - y0) < (GP_Coord)GP_ContextH(dst));
- if (GP_CONTEXT_ROTATION_EQUAL(src, dst)) {
+ if (GP_CONTEXT_ROTATION_EQUAL(src, dst))
GP_BlitXYXY_Raw_Fast(src, x0, y0, x1, y1, dst, x2, y2);
- return;
- }
-
- GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2);
+ else
+ GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2);
}
void GP_BlitXYXY_Clipped(const GP_Context *src,
@@ -95,14 +93,31 @@ void GP_BlitXYXY_Clipped(const GP_Context *src,
if (y1 < y0)
GP_SWAP(y0, y1);
- /* All coordinates are inside of src and dst context */
- GP_CHECK(x0 < (GP_Coord)GP_ContextW(src));
- GP_CHECK(y0 < (GP_Coord)GP_ContextH(src));
- GP_CHECK(x1 < (GP_Coord)GP_ContextW(src));
- GP_CHECK(y1 < (GP_Coord)GP_ContextH(src));
- GP_CHECK(x2 < (GP_Coord)GP_ContextW(dst));
- GP_CHECK(y2 < (GP_Coord)GP_ContextH(dst));
+ /* Noting to blit return now */
+ if (x2 >= (GP_Coord)GP_ContextW(dst) ||
+ y2 >= (GP_Coord)GP_ContextH(dst))
+ return;
+
+ /* We need to shift source rectangle */
+ if (x2 < 0) {
+ x0 -= x2;
+ x1 -= x2;
+ x2 = 0;
+ }
+
+ if (y2 < 0) {
+ y0 -= y2;
+ y1 -= y2;
+ y2 = 0;
+ }
+
+ /* Make sure souce coordinates are inside of the src */
+ x0 = GP_MAX(x0, 0);
+ y0 = GP_MAX(y0, 0);
+ x1 = GP_MIN(x1, (GP_Coord)GP_ContextW(src) - 1);
+ y1 = GP_MIN(y1, (GP_Coord)GP_ContextH(src) - 1);
+ /* And source rectangle fits inside of the destination */
GP_Coord src_w = x1 - x0;
GP_Coord src_h = y1 - y0;
@@ -118,15 +133,14 @@ void GP_BlitXYXY_Clipped(const GP_Context *src,
if (src_h > dst_h)
y1 -= src_h - dst_h + 1;
- GP_DEBUG(2, "Blitting %ix%i->%ix%i in %ux%u",
- x0, y0, x1, y1, GP_ContextW(src), GP_ContextH(src));
+ GP_DEBUG(2, "Blitting %ix%i->%ix%i in %ux%u to %ix%i in %ux%u",
+ x0, y0, x1, y1, GP_ContextW(src), GP_ContextH(src),
+ x2, y2, GP_ContextW(dst), GP_ContextH(dst));
- if (GP_CONTEXT_ROTATION_EQUAL(src, dst)) {
+ if (GP_CONTEXT_ROTATION_EQUAL(src, dst))
GP_BlitXYXY_Raw_Fast(src, x0, y0, x1, y1, dst, x2, y2);
- return;
- }
-
- GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2);
+ else
+ GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2);
}
void GP_BlitXYWH(const GP_Context *src,
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Blit.h | 12 +++++-----
libs/core/GP_Blit.c | 52 ++++++++++++++++++++++++++++----------------
libs/core/GP_Blit.gen.c.t | 2 +-
3 files changed, 40 insertions(+), 26 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: f36ba9ddb07263d7922546bbe4b823a029572702
by metan 01 May '12
by metan 01 May '12
01 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via f36ba9ddb07263d7922546bbe4b823a029572702 (commit)
from 3447cc05da97de60400ac7cfbf0325e4ac84e1ad (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/f36ba9ddb07263d7922546bbe4b823a02957…
commit f36ba9ddb07263d7922546bbe4b823a029572702
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 1 18:23:26 2012 +0200
core: Add clipped blit.
diff --git a/include/core/GP_Blit.h b/include/core/GP_Blit.h
index adae66b..46d478b 100644
--- a/include/core/GP_Blit.h
+++ b/include/core/GP_Blit.h
@@ -48,6 +48,15 @@ void GP_BlitXYXY(const GP_Context *src,
GP_Context *dst, GP_Coord x2, GP_Coord y2);
/*
+ * Clipped variant, if destination context size (from x2, y2 to the end of the
+ * context) is not big enough the source rectangle is clipped, eg. only initial
+ * part of the source (starting on x0, y0) will be blitted.
+ */
+void GP_BlitXYXY_Clipped(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2);
+
+/*
* Blits rectangle from src defined by x0, y0, w0, h0 (uses w0 x h0 pixels) to
* dst starting on x2, y2.
*/
@@ -55,7 +64,16 @@ void GP_BlitXYWH(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Size w0, GP_Size h0,
GP_Context *dst, GP_Coord x1, GP_Coord y1);
-/* The default is XYWH now, will be changed */
+/*
+ * Clipped variant, if destination context size (from x1, y1 to the end of the
+ * context) is not big enough the source rectangle is clipped, eg. only initial
+ * part of the source (starting on x0, y0) will be blitted.
+ */
+void GP_BlitXYWH_Clipped(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Size w0, GP_Size h0,
+ GP_Context *dst, GP_Coord x1, GP_Coord y1);
+
+/* The default is XYWH */
static inline void GP_Blit(const GP_Context *src,
GP_Coord x0, GP_Coord y0,
GP_Size w0, GP_Size h0,
@@ -64,6 +82,14 @@ static inline void GP_Blit(const GP_Context *src,
GP_BlitXYWH(src, x0, y0, w0, h0, dst, x1, y1);
}
+static inline void GP_Blit_Clipped(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0,
+ GP_Size w0, GP_Size h0,
+ GP_Context *dst, GP_Coord x1, GP_Coord y1)
+{
+ GP_BlitXYWH_Clipped(src, x0, y0, w0, h0, dst, x1, y1);
+}
+
/*
* Same as GP_BlitXYXY but doesn't respect rotations. Faster (for now).
*/
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index e69d7da..13acb22 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -25,6 +25,7 @@
#include "GP_GetPutPixel.h"
#include "GP_Context.h"
#include "GP_Convert.h"
+#include "GP_Debug.h"
#include "GP_Blit.h"
/* Generated functions */
@@ -83,6 +84,51 @@ void GP_BlitXYXY(const GP_Context *src,
GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2);
}
+void GP_BlitXYXY_Clipped(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
+ GP_Context *dst, GP_Coord x2, GP_Coord y2)
+{
+ /* Normalize source rectangle */
+ if (x1 < x0)
+ GP_SWAP(x0, x1);
+
+ if (y1 < y0)
+ GP_SWAP(y0, y1);
+
+ /* All coordinates are inside of src and dst context */
+ GP_CHECK(x0 < (GP_Coord)GP_ContextW(src));
+ GP_CHECK(y0 < (GP_Coord)GP_ContextH(src));
+ GP_CHECK(x1 < (GP_Coord)GP_ContextW(src));
+ GP_CHECK(y1 < (GP_Coord)GP_ContextH(src));
+ GP_CHECK(x2 < (GP_Coord)GP_ContextW(dst));
+ GP_CHECK(y2 < (GP_Coord)GP_ContextH(dst));
+
+ GP_Coord src_w = x1 - x0;
+ GP_Coord src_h = y1 - y0;
+
+ GP_Coord dst_w = GP_ContextW(dst) - x2;
+ GP_Coord dst_h = GP_ContextH(dst) - y2;
+
+ GP_DEBUG(2, "Blitting %ix%i, available %ix%i",
+ src_w, src_h, dst_w, dst_h);
+
+ if (src_w > dst_w)
+ x1 -= src_w - dst_w + 1;
+
+ if (src_h > dst_h)
+ y1 -= src_h - dst_h + 1;
+
+ GP_DEBUG(2, "Blitting %ix%i->%ix%i in %ux%u",
+ x0, y0, x1, y1, GP_ContextW(src), GP_ContextH(src));
+
+ if (GP_CONTEXT_ROTATION_EQUAL(src, dst)) {
+ GP_BlitXYXY_Raw_Fast(src, x0, y0, x1, y1, dst, x2, y2);
+ return;
+ }
+
+ GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2);
+}
+
void GP_BlitXYWH(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Size w0, GP_Size h0,
GP_Context *dst, GP_Coord x1, GP_Coord y1)
@@ -93,6 +139,16 @@ void GP_BlitXYWH(const GP_Context *src,
GP_BlitXYXY(src, x0, y0, x0 + w0 - 1, y0 + h0 - 1, dst, x1, y1);
}
+void GP_BlitXYWH_Clipped(const GP_Context *src,
+ GP_Coord x0, GP_Coord y0, GP_Size w0, GP_Size h0,
+ GP_Context *dst, GP_Coord x1, GP_Coord y1)
+{
+ if (w0 == 0 || h0 == 0)
+ return;
+
+ GP_BlitXYXY_Clipped(src, x0, y0, x0 + w0 - 1, y0 + h0 - 1, dst, x1, y1);
+}
+
void GP_BlitXYXY_Raw(const GP_Context *src,
GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1,
GP_Context *dst, GP_Coord x2, GP_Coord y2)
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Blit.h | 28 +++++++++++++++++++++++-
libs/core/GP_Blit.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 1 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0