GTK+黑白棋reversi

language: C99 + GTK+ algorithm:对棋盘各个格子设置权值,计算总值 icon:程序截图 license: GNU General Public License v3 revision control: Mercurial bead-black.png bead-white.png texture1.png texture2.png: 8pm(http://hi.baidu.com/eightpm) 提供

gdk透明贴图好像有点麻烦(以前 Win32 API 用得是 TransparentBlt)

菜单采用GtkUIManager,可以看demo:/usr/share/gtk-2.0/demo/ui_manager.c的透明贴图:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void pixbuf_transparent(GdkPixbuf *dst, const GdkPixbuf *src, gint dstx, gint dsty, guint transcolor)
{
guchar r = (transcolor & 0xFF0000) >> 16;
guchar g = (transcolor & 0x00FF00) >> 8;
guchar b = transcolor & 0x0000FF;
guchar *p = gdk_pixbuf_get_pixels(dst),
*q = gdk_pixbuf_get_pixels(src);
int d = gdk_pixbuf_get_n_channels(src),
dd = gdk_pixbuf_get_rowstride(src),
d2 = gdk_pixbuf_get_n_channels(dst),
dd2 = gdk_pixbuf_get_rowstride(dst),
w = gdk_pixbuf_get_width(src),
h = gdk_pixbuf_get_height(src);
for (int y = 0; y < h; ++y)
for (int x = 0; x < w; ++x)
{
guchar *pp = p + (dsty+y) * dd2 + (dstx+x) * d2;
guchar *qq = q + y * dd + x * d;
if (qq[0] != r || qq[1] != g || qq[2] != b)
pp[0] = qq[0], pp[1] = qq[1], pp[2] = qq[2];
}
}