mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-04 04:44:16 +01:00
Change to the linux kernel coding style
for arq in `git ls-files *.c`; do
echo $arq;
indent -linux -l115 $arq;
done
The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
@@ -3,40 +3,37 @@
|
||||
#include <stdio.h>
|
||||
#include <WINGs/WINGs.h>
|
||||
|
||||
|
||||
|
||||
void showSelectedColor(void *self, void *cdata)
|
||||
{
|
||||
WMColorPanel *panel= (WMColorPanel*)self;
|
||||
WMColorPanel *panel = (WMColorPanel *) self;
|
||||
|
||||
printf("Selected Color: %s\n", WMGetColorRGBDescription(WMGetColorPanelColor(panel)));
|
||||
printf("Selected Color: %s\n", WMGetColorRGBDescription(WMGetColorPanelColor(panel)));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Display *dpy;
|
||||
WMScreen *scr;
|
||||
Display *dpy;
|
||||
WMScreen *scr;
|
||||
|
||||
WMInitializeApplication("wmcolorpick", &argc, argv);
|
||||
WMInitializeApplication("wmcolorpick", &argc, argv);
|
||||
|
||||
dpy = XOpenDisplay("");
|
||||
if (!dpy) {
|
||||
printf("could not open display\n");
|
||||
exit(1);
|
||||
}
|
||||
dpy = XOpenDisplay("");
|
||||
if (!dpy) {
|
||||
printf("could not open display\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
|
||||
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
|
||||
|
||||
{
|
||||
WMColorPanel *panel= WMGetColorPanel(scr);
|
||||
{
|
||||
WMColorPanel *panel = WMGetColorPanel(scr);
|
||||
|
||||
WMSetColorPanelAction(panel, showSelectedColor, NULL);
|
||||
WMSetColorPanelAction(panel, showSelectedColor, NULL);
|
||||
|
||||
WMShowColorPanel(panel);
|
||||
}
|
||||
WMShowColorPanel(panel);
|
||||
}
|
||||
|
||||
WMScreenMainLoop(scr);
|
||||
WMScreenMainLoop(scr);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -13,186 +12,161 @@
|
||||
|
||||
#include <WINGs/WINGs.h>
|
||||
|
||||
|
||||
|
||||
static int initialized = 0;
|
||||
|
||||
static void didReceiveInput(ConnectionDelegate * self, WMConnection * cPtr);
|
||||
|
||||
static void connectionDidDie(ConnectionDelegate * self, WMConnection * cPtr);
|
||||
|
||||
static void didReceiveInput(ConnectionDelegate *self, WMConnection *cPtr);
|
||||
|
||||
static void connectionDidDie(ConnectionDelegate *self, WMConnection *cPtr);
|
||||
|
||||
static void didInitialize(ConnectionDelegate *self, WMConnection *cPtr);
|
||||
|
||||
|
||||
static void didInitialize(ConnectionDelegate * self, WMConnection * cPtr);
|
||||
|
||||
static ConnectionDelegate socketDelegate = {
|
||||
NULL, /* data */
|
||||
NULL, /* canResumeSending */
|
||||
NULL, /* didCatchException */
|
||||
connectionDidDie, /* didDie */
|
||||
didInitialize, /* didInitialize */
|
||||
didReceiveInput, /* didReceiveInput */
|
||||
NULL /* didTimeout */
|
||||
NULL, /* data */
|
||||
NULL, /* canResumeSending */
|
||||
NULL, /* didCatchException */
|
||||
connectionDidDie, /* didDie */
|
||||
didInitialize, /* didInitialize */
|
||||
didReceiveInput, /* didReceiveInput */
|
||||
NULL /* didTimeout */
|
||||
};
|
||||
|
||||
|
||||
|
||||
void
|
||||
wAbort(Bool foo)
|
||||
void wAbort(Bool foo)
|
||||
{
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
static char*
|
||||
getMessage(WMConnection *cPtr)
|
||||
static char *getMessage(WMConnection * cPtr)
|
||||
{
|
||||
char *buffer;
|
||||
WMData *aData;
|
||||
int length;
|
||||
char *buffer;
|
||||
WMData *aData;
|
||||
int length;
|
||||
|
||||
aData = WMGetConnectionAvailableData(cPtr);
|
||||
if (!aData)
|
||||
return NULL;
|
||||
if ((length=WMGetDataLength(aData))==0) {
|
||||
WMReleaseData(aData);
|
||||
return NULL;
|
||||
}
|
||||
aData = WMGetConnectionAvailableData(cPtr);
|
||||
if (!aData)
|
||||
return NULL;
|
||||
if ((length = WMGetDataLength(aData)) == 0) {
|
||||
WMReleaseData(aData);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer = (char*)wmalloc(length+1);
|
||||
WMGetDataBytes(aData, buffer);
|
||||
buffer[length]= '\0';
|
||||
WMReleaseData(aData);
|
||||
buffer = (char *)wmalloc(length + 1);
|
||||
WMGetDataBytes(aData, buffer);
|
||||
buffer[length] = '\0';
|
||||
WMReleaseData(aData);
|
||||
|
||||
return buffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
inputHandler(int fd, int mask, void *clientData)
|
||||
static void inputHandler(int fd, int mask, void *clientData)
|
||||
{
|
||||
WMConnection *cPtr = (WMConnection*)clientData;
|
||||
WMData *aData;
|
||||
char buf[4096];
|
||||
int n;
|
||||
WMConnection *cPtr = (WMConnection *) clientData;
|
||||
WMData *aData;
|
||||
char buf[4096];
|
||||
int n;
|
||||
|
||||
if (!initialized)
|
||||
return;
|
||||
if (!initialized)
|
||||
return;
|
||||
|
||||
n = read(fd, buf, 4096);
|
||||
if (n>0) {
|
||||
aData = WMCreateDataWithBytes(buf, n);
|
||||
WMSendConnectionData(cPtr, aData);
|
||||
WMReleaseData(aData);
|
||||
}
|
||||
n = read(fd, buf, 4096);
|
||||
if (n > 0) {
|
||||
aData = WMCreateDataWithBytes(buf, n);
|
||||
WMSendConnectionData(cPtr, aData);
|
||||
WMReleaseData(aData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
didReceiveInput(ConnectionDelegate *self, WMConnection *cPtr)
|
||||
static void didReceiveInput(ConnectionDelegate * self, WMConnection * cPtr)
|
||||
{
|
||||
char *buffer;
|
||||
char *buffer;
|
||||
|
||||
buffer = getMessage(cPtr);
|
||||
if (!buffer) {
|
||||
fprintf(stderr, "Connection closed by peer.\n");
|
||||
exit(0);
|
||||
}
|
||||
buffer = getMessage(cPtr);
|
||||
if (!buffer) {
|
||||
fprintf(stderr, "Connection closed by peer.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf("%s", buffer);
|
||||
printf("%s", buffer);
|
||||
|
||||
wfree(buffer);
|
||||
wfree(buffer);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
connectionDidDie(ConnectionDelegate *self, WMConnection *cPtr)
|
||||
static void connectionDidDie(ConnectionDelegate * self, WMConnection * cPtr)
|
||||
{
|
||||
WMCloseConnection(cPtr);
|
||||
WMCloseConnection(cPtr);
|
||||
|
||||
fprintf(stderr, "Connection closed by peer.\n");
|
||||
exit(0);
|
||||
fprintf(stderr, "Connection closed by peer.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
didInitialize(ConnectionDelegate *self, WMConnection *cPtr)
|
||||
static void didInitialize(ConnectionDelegate * self, WMConnection * cPtr)
|
||||
{
|
||||
int state = WMGetConnectionState(cPtr);
|
||||
WMHost *host;
|
||||
int state = WMGetConnectionState(cPtr);
|
||||
WMHost *host;
|
||||
|
||||
if (state == WCConnected) {
|
||||
host = WMGetHostWithAddress(WMGetConnectionAddress(cPtr));
|
||||
fprintf(stderr, "connected to '%s:%s'\n",
|
||||
host?WMGetHostName(host):WMGetConnectionAddress(cPtr),
|
||||
WMGetConnectionService(cPtr));
|
||||
initialized = 1;
|
||||
if (host)
|
||||
WMReleaseHost(host);
|
||||
return;
|
||||
} else {
|
||||
wsyserrorwithcode(WCErrorCode, "Unable to connect");
|
||||
exit(1);
|
||||
}
|
||||
if (state == WCConnected) {
|
||||
host = WMGetHostWithAddress(WMGetConnectionAddress(cPtr));
|
||||
fprintf(stderr, "connected to '%s:%s'\n",
|
||||
host ? WMGetHostName(host) : WMGetConnectionAddress(cPtr), WMGetConnectionService(cPtr));
|
||||
initialized = 1;
|
||||
if (host)
|
||||
WMReleaseHost(host);
|
||||
return;
|
||||
} else {
|
||||
wsyserrorwithcode(WCErrorCode, "Unable to connect");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *ProgName, *host, *port;
|
||||
int i;
|
||||
WMConnection *sPtr;
|
||||
char *ProgName, *host, *port;
|
||||
int i;
|
||||
WMConnection *sPtr;
|
||||
|
||||
wsetabort(wAbort);
|
||||
wsetabort(wAbort);
|
||||
|
||||
WMInitializeApplication("connect", &argc, argv);
|
||||
WMInitializeApplication("connect", &argc, argv);
|
||||
|
||||
ProgName = strrchr(argv[0],'/');
|
||||
if (!ProgName)
|
||||
ProgName = argv[0];
|
||||
else
|
||||
ProgName++;
|
||||
ProgName = strrchr(argv[0], '/');
|
||||
if (!ProgName)
|
||||
ProgName = argv[0];
|
||||
else
|
||||
ProgName++;
|
||||
|
||||
host = NULL;
|
||||
port = "34567";
|
||||
host = NULL;
|
||||
port = "34567";
|
||||
|
||||
if (argc>1) {
|
||||
for (i=1; i<argc; i++) {
|
||||
if (strcmp(argv[i], "--help")==0 || strcmp(argv[i], "-h")==0) {
|
||||
printf("usage: %s [host [port]]\n\n", ProgName);
|
||||
exit(0);
|
||||
} else {
|
||||
if (!host)
|
||||
host = argv[i];
|
||||
else
|
||||
port = argv[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (argc > 1) {
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
|
||||
printf("usage: %s [host [port]]\n\n", ProgName);
|
||||
exit(0);
|
||||
} else {
|
||||
if (!host)
|
||||
host = argv[i];
|
||||
else
|
||||
port = argv[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Trying to make connection to '%s:%s'\n",
|
||||
host?host:"localhost", port);
|
||||
printf("Trying to make connection to '%s:%s'\n", host ? host : "localhost", port);
|
||||
|
||||
sPtr = WMCreateConnectionToAddressAndNotify(host, port, NULL);
|
||||
if (!sPtr) {
|
||||
wfatal("could not create connection. exiting");
|
||||
exit(1);
|
||||
}
|
||||
sPtr = WMCreateConnectionToAddressAndNotify(host, port, NULL);
|
||||
if (!sPtr) {
|
||||
wfatal("could not create connection. exiting");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
WMSetConnectionDelegate(sPtr, &socketDelegate);
|
||||
WMSetConnectionDelegate(sPtr, &socketDelegate);
|
||||
|
||||
/* watch what user types and send it over the connection */
|
||||
WMAddInputHandler(0, WIReadMask, inputHandler, sPtr);
|
||||
/* watch what user types and send it over the connection */
|
||||
WMAddInputHandler(0, WIReadMask, inputHandler, sPtr);
|
||||
|
||||
while (1) {
|
||||
WHandleEvents();
|
||||
}
|
||||
while (1) {
|
||||
WHandleEvents();
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,88 +19,80 @@
|
||||
* USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <WINGs/WINGs.h>
|
||||
#include <WINGs/WUtil.h>
|
||||
|
||||
void
|
||||
wAbort()
|
||||
void wAbort()
|
||||
{
|
||||
exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void show(WMWidget *self, void *data)
|
||||
void show(WMWidget * self, void *data)
|
||||
{
|
||||
char buf[60];
|
||||
void *d;
|
||||
WMLabel *l = (WMLabel*)data;
|
||||
d = WMGetHangedData(self);
|
||||
sprintf(buf, "%i - 0x%x - 0%o", (int)(uintptr_t)d, (int)(uintptr_t)d,
|
||||
(int)(uintptr_t)d);
|
||||
WMSetLabelText(l, buf);
|
||||
char buf[60];
|
||||
void *d;
|
||||
WMLabel *l = (WMLabel *) data;
|
||||
d = WMGetHangedData(self);
|
||||
sprintf(buf, "%i - 0x%x - 0%o", (int)(uintptr_t) d, (int)(uintptr_t) d, (int)(uintptr_t) d);
|
||||
WMSetLabelText(l, buf);
|
||||
}
|
||||
|
||||
void quit(WMWidget *self, void *data)
|
||||
void quit(WMWidget * self, void *data)
|
||||
{
|
||||
exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Display *dpy;
|
||||
WMWindow *win;
|
||||
WMScreen *scr;
|
||||
WMButton *lab, *l0=NULL;
|
||||
WMLabel *pos;
|
||||
int x, y, c;
|
||||
char buf[20];
|
||||
Display *dpy;
|
||||
WMWindow *win;
|
||||
WMScreen *scr;
|
||||
WMButton *lab, *l0 = NULL;
|
||||
WMLabel *pos;
|
||||
int x, y, c;
|
||||
char buf[20];
|
||||
|
||||
WMInitializeApplication("FontView", &argc, argv);
|
||||
WMInitializeApplication("FontView", &argc, argv);
|
||||
|
||||
dpy = XOpenDisplay("");
|
||||
if (!dpy) {
|
||||
wfatal("cant open display");
|
||||
exit(0);
|
||||
}
|
||||
dpy = XOpenDisplay("");
|
||||
if (!dpy) {
|
||||
wfatal("cant open display");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
scr = WMCreateSimpleApplicationScreen(dpy);
|
||||
scr = WMCreateSimpleApplicationScreen(dpy);
|
||||
|
||||
win = WMCreateWindow(scr, "main");
|
||||
WMResizeWidget(win, 20*33, 20+20*9);
|
||||
WMSetWindowTitle(win, "Font Chars");
|
||||
WMSetWindowCloseAction(win, quit, NULL);
|
||||
pos = WMCreateLabel(win);
|
||||
WMResizeWidget(pos, 20*33, 20);
|
||||
WMMoveWidget(pos, 10, 5);
|
||||
win = WMCreateWindow(scr, "main");
|
||||
WMResizeWidget(win, 20 * 33, 20 + 20 * 9);
|
||||
WMSetWindowTitle(win, "Font Chars");
|
||||
WMSetWindowCloseAction(win, quit, NULL);
|
||||
pos = WMCreateLabel(win);
|
||||
WMResizeWidget(pos, 20 * 33, 20);
|
||||
WMMoveWidget(pos, 10, 5);
|
||||
|
||||
c = 0;
|
||||
for (y=0; y<8; y++) {
|
||||
for (x=0; x<32; x++, c++) {
|
||||
lab = WMCreateCustomButton(win, WBBStateLightMask);
|
||||
WMResizeWidget(lab, 20, 20);
|
||||
WMMoveWidget(lab, 10+x*20, 30+y*20);
|
||||
sprintf(buf, "%c", c);
|
||||
WMSetButtonText(lab, buf);
|
||||
WMSetButtonAction(lab, show, pos);
|
||||
WMHangData(lab, (void*)(uintptr_t)c);
|
||||
if (c>0) {
|
||||
WMGroupButtons(l0, lab);
|
||||
} else {
|
||||
l0 = lab;
|
||||
}
|
||||
}
|
||||
}
|
||||
WMRealizeWidget(win);
|
||||
WMMapSubwidgets(win);
|
||||
WMMapWidget(win);
|
||||
WMScreenMainLoop(scr);
|
||||
return 0;
|
||||
c = 0;
|
||||
for (y = 0; y < 8; y++) {
|
||||
for (x = 0; x < 32; x++, c++) {
|
||||
lab = WMCreateCustomButton(win, WBBStateLightMask);
|
||||
WMResizeWidget(lab, 20, 20);
|
||||
WMMoveWidget(lab, 10 + x * 20, 30 + y * 20);
|
||||
sprintf(buf, "%c", c);
|
||||
WMSetButtonText(lab, buf);
|
||||
WMSetButtonAction(lab, show, pos);
|
||||
WMHangData(lab, (void *)(uintptr_t) c);
|
||||
if (c > 0) {
|
||||
WMGroupButtons(l0, lab);
|
||||
} else {
|
||||
l0 = lab;
|
||||
}
|
||||
}
|
||||
}
|
||||
WMRealizeWidget(win);
|
||||
WMMapSubwidgets(win);
|
||||
WMMapWidget(win);
|
||||
WMScreenMainLoop(scr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <WINGs/WINGs.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define MAX_SIZE 10*10
|
||||
|
||||
|
||||
WMWindow *win;
|
||||
WMButton *Button[MAX_SIZE];
|
||||
char Map[MAX_SIZE];
|
||||
@@ -20,226 +16,218 @@ int MoveCount;
|
||||
|
||||
int WinSize = 120;
|
||||
|
||||
|
||||
Bool
|
||||
CheckWin(void)
|
||||
Bool CheckWin(void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < Size*Size-1; i++) {
|
||||
if (Map[i] != i)
|
||||
return False;
|
||||
}
|
||||
for (i = 0; i < Size * Size - 1; i++) {
|
||||
if (Map[i] != i)
|
||||
return False;
|
||||
}
|
||||
|
||||
return True;
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MoveButton(int button, int x, int y)
|
||||
void MoveButton(int button, int x, int y)
|
||||
{
|
||||
WMMoveWidget(Button[button], x*(WinSize/Size), y*(WinSize/Size));
|
||||
WMMoveWidget(Button[button], x * (WinSize / Size), y * (WinSize / Size));
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
SlideButton(int button)
|
||||
Bool SlideButton(int button)
|
||||
{
|
||||
int x=0, y=0, done = 0;
|
||||
int x = 0, y = 0, done = 0;
|
||||
|
||||
/* locate the button */
|
||||
for (y = 0; y < Size; y++) {
|
||||
for (x = 0; x < Size; x++) {
|
||||
if (MAP(x,y) == button) {
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (done)
|
||||
break;
|
||||
}
|
||||
/* locate the button */
|
||||
for (y = 0; y < Size; y++) {
|
||||
for (x = 0; x < Size; x++) {
|
||||
if (MAP(x, y) == button) {
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (done)
|
||||
break;
|
||||
}
|
||||
|
||||
if (x > 0 && MAP(x-1, y) < 0) {
|
||||
MAP(x,y) = -1;
|
||||
MoveButton(button, x-1, y);
|
||||
MAP(x-1,y) = button;
|
||||
} else if (x < Size-1 && MAP(x+1, y) < 0) {
|
||||
MAP(x,y) = -1;
|
||||
MoveButton(button, x+1, y);
|
||||
MAP(x+1,y) = button;
|
||||
} else if (y > 0 && MAP(x, y-1) < 0) {
|
||||
MAP(x,y) = -1;
|
||||
MoveButton(button, x, y-1);
|
||||
MAP(x,y-1) = button;
|
||||
} else if (y < Size-1 && MAP(x, y+1) < 0) {
|
||||
MAP(x,y) = -1;
|
||||
MoveButton(button, x, y+1);
|
||||
MAP(x,y+1) = button;
|
||||
} else {
|
||||
return False;
|
||||
}
|
||||
return True;
|
||||
if (x > 0 && MAP(x - 1, y) < 0) {
|
||||
MAP(x, y) = -1;
|
||||
MoveButton(button, x - 1, y);
|
||||
MAP(x - 1, y) = button;
|
||||
} else if (x < Size - 1 && MAP(x + 1, y) < 0) {
|
||||
MAP(x, y) = -1;
|
||||
MoveButton(button, x + 1, y);
|
||||
MAP(x + 1, y) = button;
|
||||
} else if (y > 0 && MAP(x, y - 1) < 0) {
|
||||
MAP(x, y) = -1;
|
||||
MoveButton(button, x, y - 1);
|
||||
MAP(x, y - 1) = button;
|
||||
} else if (y < Size - 1 && MAP(x, y + 1) < 0) {
|
||||
MAP(x, y) = -1;
|
||||
MoveButton(button, x, y + 1);
|
||||
MAP(x, y + 1) = button;
|
||||
} else {
|
||||
return False;
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
#define SWAP(a,b) {int tmp; tmp=a; a=b; b=tmp;}
|
||||
|
||||
void ResetGame(void)
|
||||
{
|
||||
int i, x, y, ox, oy;
|
||||
int i, x, y, ox, oy;
|
||||
|
||||
MoveCount = 0;
|
||||
|
||||
MoveCount = 0;
|
||||
for (i = 0; i < Size * Size - 1; i++) {
|
||||
Map[i] = i;
|
||||
}
|
||||
Map[i] = -1;
|
||||
ox = x = Size - 1;
|
||||
oy = y = Size - 1;
|
||||
for (i = 0; i < 1000; i++) {
|
||||
int ok;
|
||||
ok = 1;
|
||||
switch (rand() % 4) {
|
||||
case 0:
|
||||
if (x > 0)
|
||||
x--;
|
||||
else
|
||||
ok = 0;
|
||||
break;
|
||||
case 2:
|
||||
if (x < Size - 1)
|
||||
x++;
|
||||
else
|
||||
ok = 0;
|
||||
break;
|
||||
case 1:
|
||||
if (y > 0)
|
||||
y--;
|
||||
else
|
||||
ok = 0;
|
||||
break;
|
||||
case 3:
|
||||
if (y < Size - 1)
|
||||
y++;
|
||||
else
|
||||
ok = 0;
|
||||
break;
|
||||
}
|
||||
if (ok) {
|
||||
MoveButton(MAP(x, y), ox, oy);
|
||||
|
||||
for (i = 0; i < Size*Size-1; i++) {
|
||||
Map[i] = i;
|
||||
}
|
||||
Map[i] = -1;
|
||||
ox = x = Size-1;
|
||||
oy = y = Size-1;
|
||||
for (i = 0; i < 1000; i++) {
|
||||
int ok;
|
||||
ok = 1;
|
||||
switch (rand()%4) {
|
||||
case 0:
|
||||
if (x > 0) x--; else ok = 0;
|
||||
break;
|
||||
case 2:
|
||||
if (x < Size-1) x++; else ok = 0;
|
||||
break;
|
||||
case 1:
|
||||
if (y > 0) y--; else ok = 0;
|
||||
break;
|
||||
case 3:
|
||||
if (y < Size-1) y++; else ok = 0;
|
||||
break;
|
||||
}
|
||||
if (ok) {
|
||||
MoveButton(MAP(x,y), ox, oy);
|
||||
SWAP(MAP(ox, oy), MAP(x, y));
|
||||
|
||||
SWAP(MAP(ox, oy), MAP(x, y));
|
||||
|
||||
while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) {
|
||||
XEvent ev;
|
||||
WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev);
|
||||
WMHandleEvent(&ev);
|
||||
}
|
||||
ox = x;
|
||||
oy = y;
|
||||
}
|
||||
}
|
||||
while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) {
|
||||
XEvent ev;
|
||||
WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev);
|
||||
WMHandleEvent(&ev);
|
||||
}
|
||||
ox = x;
|
||||
oy = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void buttonClick(WMWidget *w, void *ptr)
|
||||
void buttonClick(WMWidget * w, void *ptr)
|
||||
{
|
||||
char buffer[300];
|
||||
char buffer[300];
|
||||
|
||||
if (SlideButton((int)(uintptr_t)ptr)) {
|
||||
MoveCount++;
|
||||
if (SlideButton((int)(uintptr_t) ptr)) {
|
||||
MoveCount++;
|
||||
|
||||
if (CheckWin()) {
|
||||
sprintf(buffer, "You finished the game in %i moves.", MoveCount);
|
||||
if (CheckWin()) {
|
||||
sprintf(buffer, "You finished the game in %i moves.", MoveCount);
|
||||
|
||||
if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer,
|
||||
"Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) {
|
||||
exit(0);
|
||||
}
|
||||
if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer,
|
||||
"Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ResetGame();
|
||||
}
|
||||
}
|
||||
ResetGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void resizeObserver(void *self, WMNotification *notif)
|
||||
static void resizeObserver(void *self, WMNotification * notif)
|
||||
{
|
||||
WMSize size = WMGetViewSize(WMWidgetView(win));
|
||||
int x, y;
|
||||
WMSize size = WMGetViewSize(WMWidgetView(win));
|
||||
int x, y;
|
||||
|
||||
WinSize = size.width;
|
||||
for (y = 0; y < Size; y++) {
|
||||
for (x = 0; x < Size; x++) {
|
||||
if (MAP(x,y) >= 0) {
|
||||
WMResizeWidget(Button[(int)MAP(x,y)],
|
||||
WinSize/Size, WinSize/Size);
|
||||
WMMoveWidget(Button[(int)MAP(x,y)],
|
||||
x*(WinSize/Size), y*(WinSize/Size));
|
||||
}
|
||||
}
|
||||
}
|
||||
WinSize = size.width;
|
||||
for (y = 0; y < Size; y++) {
|
||||
for (x = 0; x < Size; x++) {
|
||||
if (MAP(x, y) >= 0) {
|
||||
WMResizeWidget(Button[(int)MAP(x, y)], WinSize / Size, WinSize / Size);
|
||||
WMMoveWidget(Button[(int)MAP(x, y)], x * (WinSize / Size), y * (WinSize / Size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Display *dpy;
|
||||
WMScreen *scr;
|
||||
int x, y, i;
|
||||
Display *dpy;
|
||||
WMScreen *scr;
|
||||
int x, y, i;
|
||||
|
||||
WMInitializeApplication("Puzzle", &argc, argv);
|
||||
WMInitializeApplication("Puzzle", &argc, argv);
|
||||
|
||||
dpy = XOpenDisplay("");
|
||||
if (!dpy) {
|
||||
printf("could not open display\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dpy = XOpenDisplay("");
|
||||
if (!dpy) {
|
||||
printf("could not open display\n");
|
||||
exit(1);
|
||||
}
|
||||
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
|
||||
|
||||
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
|
||||
win = WMCreateWindow(scr, "puzzle");
|
||||
WMResizeWidget(win, WinSize, WinSize);
|
||||
WMSetWindowTitle(win, "zuPzel");
|
||||
WMSetWindowMinSize(win, 80, 80);
|
||||
WMSetWindowAspectRatio(win, 2, 2, 2, 2);
|
||||
WMSetWindowResizeIncrements(win, Size, Size);
|
||||
WMSetViewNotifySizeChanges(WMWidgetView(win), True);
|
||||
WMAddNotificationObserver(resizeObserver, NULL, WMViewSizeDidChangeNotification, WMWidgetView(win));
|
||||
|
||||
win = WMCreateWindow(scr, "puzzle");
|
||||
WMResizeWidget(win, WinSize, WinSize);
|
||||
WMSetWindowTitle(win, "zuPzel");
|
||||
WMSetWindowMinSize(win, 80, 80);
|
||||
WMSetWindowAspectRatio(win, 2, 2, 2, 2);
|
||||
WMSetWindowResizeIncrements(win, Size, Size);
|
||||
WMSetViewNotifySizeChanges(WMWidgetView(win), True);
|
||||
WMAddNotificationObserver(resizeObserver, NULL,
|
||||
WMViewSizeDidChangeNotification,
|
||||
WMWidgetView(win));
|
||||
for (i = y = 0; y < Size && i < Size * Size - 1; y++) {
|
||||
for (x = 0; x < Size && i < Size * Size - 1; x++) {
|
||||
char buf[32];
|
||||
WMColor *color;
|
||||
RColor col;
|
||||
RHSVColor hsv;
|
||||
|
||||
hsv.hue = i * 360 / (Size * Size - 1);
|
||||
hsv.saturation = 120;
|
||||
hsv.value = 200;
|
||||
|
||||
RHSVtoRGB(&hsv, &col);
|
||||
|
||||
for (i = y = 0; y < Size && i < Size*Size-1; y++) {
|
||||
for (x = 0; x < Size && i < Size*Size-1; x++) {
|
||||
char buf[32];
|
||||
WMColor *color;
|
||||
RColor col;
|
||||
RHSVColor hsv;
|
||||
color = WMCreateRGBColor(scr, col.red << 8, col.green << 8, col.blue << 8, False);
|
||||
|
||||
hsv.hue = i*360/(Size*Size-1);
|
||||
hsv.saturation = 120;
|
||||
hsv.value = 200;
|
||||
MAP(x, y) = i;
|
||||
Button[i] = WMCreateButton(win, WBTMomentaryLight);
|
||||
WMSetWidgetBackgroundColor(Button[i], color);
|
||||
WMReleaseColor(color);
|
||||
WMSetButtonAction(Button[i], buttonClick, (void *)(uintptr_t) i);
|
||||
WMResizeWidget(Button[i], WinSize / Size, WinSize / Size);
|
||||
WMMoveWidget(Button[i], x * (WinSize / Size), y * (WinSize / Size));
|
||||
sprintf(buf, "%i", i + 1);
|
||||
WMSetButtonText(Button[i], buf);
|
||||
WMSetButtonTextAlignment(Button[i], WACenter);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
RHSVtoRGB(&hsv, &col);
|
||||
WMMapSubwidgets(win);
|
||||
WMMapWidget(win);
|
||||
WMRealizeWidget(win);
|
||||
|
||||
color = WMCreateRGBColor(scr, col.red<<8, col.green<<8,
|
||||
col.blue<<8, False);
|
||||
ResetGame();
|
||||
|
||||
MAP(x,y) = i;
|
||||
Button[i] = WMCreateButton(win, WBTMomentaryLight);
|
||||
WMSetWidgetBackgroundColor(Button[i], color);
|
||||
WMReleaseColor(color);
|
||||
WMSetButtonAction(Button[i], buttonClick, (void*)(uintptr_t)i);
|
||||
WMResizeWidget(Button[i], WinSize/Size, WinSize/Size);
|
||||
WMMoveWidget(Button[i], x*(WinSize/Size), y*(WinSize/Size));
|
||||
sprintf(buf, "%i", i+1);
|
||||
WMSetButtonText(Button[i], buf);
|
||||
WMSetButtonTextAlignment(Button[i], WACenter);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
WMScreenMainLoop(scr);
|
||||
|
||||
WMMapSubwidgets(win);
|
||||
WMMapWidget(win);
|
||||
WMRealizeWidget(win);
|
||||
|
||||
ResetGame();
|
||||
|
||||
WMScreenMainLoop(scr);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user