1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 04:20:27 +01:00

updated upzzle, removed SetWindowInitialSize added SetWindowAspectRatio

This commit is contained in:
kojima
2000-04-09 23:06:55 +00:00
parent 779cdb0dd4
commit c08022a088
4 changed files with 102 additions and 41 deletions

View File

@@ -4,7 +4,8 @@ changes since wmaker 0.62.0:
- added drag and drop
- changed selection code
- added clientdata to WMFindInBag
- removed SetWindowInitialSize()
- added SetWindowAspectRatio()
changes since wmaker 0.61.1:
............................

View File

@@ -832,7 +832,8 @@ void WMSetWindowCloseAction(WMWindow *win, WMAction *action, void *clientData);
void WMSetWindowInitialPosition(WMWindow *win, int x, int y);
void WMSetWindowInitialSize(WMWindow *win, unsigned width, unsigned height);
void WMSetWindowAspectRatio(WMWindow *win, int minX, int minY,
int maxX, int maxY);
void WMSetWindowMaxSize(WMWindow *win, unsigned width, unsigned height);

View File

@@ -79,44 +79,66 @@ Bool SlideButton(int button)
}
#define SWAP(a,b) {int tmp; tmp=a; a=b; b=tmp;}
void ResetGame(void)
{
int i, x, y;
int i, x, y, ox, oy;
MoveCount = 0;
memset(Map, -1, Size*Size);
for (i = 0; i < Size*Size-1; i++) {
while (1) {
int pos = rand()%(Size*Size);
if (Map[pos] < 0) {
Map[pos] = i;
break;
}
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;
}
}
for (y = 0; y < Size; y++) {
for (x = 0; x < Size; x++) {
if (MAP(x,y) >= 0) {
MoveButton(MAP(x,y), x, y);
if (ok) {
MoveButton(MAP(x,y), ox, oy);
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;
}
}
}
void buttonClick(WMWidget *w, void *ptr)
{
char buffer[300];
if (SlideButton((int)ptr)) {
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);
@@ -128,6 +150,26 @@ void buttonClick(WMWidget *w, void *ptr)
}
static void resizeObserver(void *self, WMNotification *notif)
{
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));
}
}
}
}
int main(int argc, char **argv)
{
Display *dpy;
@@ -148,6 +190,15 @@ int main(int argc, char **argv)
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++) {
@@ -157,8 +208,8 @@ int main(int argc, char **argv)
RHSVColor hsv;
hsv.hue = i*360/(Size*Size-1);
hsv.saturation = 100;
hsv.value = 180;
hsv.saturation = 120;
hsv.value = 200;
RHSVtoRGB(&hsv, &col);

View File

@@ -25,9 +25,10 @@ typedef struct W_Window {
WMSize baseSize;
WMSize minSize;
WMSize maxSize;
WMPoint minAspect;
WMPoint maxAspect;
WMPoint upos;
WMSize usize;
WMAction *closeAction;
void *closeData;
@@ -39,7 +40,8 @@ typedef struct W_Window {
unsigned configured:1;
unsigned documentEdited:1;
unsigned upos_set:1;
unsigned setUPos:1;
unsigned setAspect:1;
} flags;
} _Window;
@@ -310,16 +312,11 @@ setSizeHints(WMWindow *win)
hints->flags = 0;
if (win->flags.upos_set) {
hints->flags |= PPosition;
if (win->flags.setUPos) {
hints->flags |= USPosition;
hints->x = win->upos.x;
hints->y = win->upos.y;
}
if (win->usize.width>0 && win->usize.height>0) {
hints->flags |= PSize;
hints->width = win->usize.width;
hints->height = win->usize.height;
}
if (win->minSize.width>0 && win->minSize.height>0) {
hints->flags |= PMinSize;
hints->min_width = win->minSize.width;
@@ -340,7 +337,15 @@ setSizeHints(WMWindow *win)
hints->width_inc = win->resizeIncrement.width;
hints->height_inc = win->resizeIncrement.height;
}
if (win->flags.setAspect) {
hints->flags |= PAspect;
hints->min_aspect.x = win->minAspect.x;
hints->min_aspect.y = win->minAspect.y;
hints->max_aspect.x = win->maxAspect.x;
hints->max_aspect.y = win->maxAspect.y;
}
if (hints->flags) {
XSetWMNormalHints(win->view->screen->display, win->view->window, hints);
}
@@ -447,29 +452,32 @@ realizeWindow(WMWindow *win)
void
WMSetWindowInitialPosition(WMWindow *win, int x, int y)
WMSetWindowAspectRatio(WMWindow *win, int minX, int minY,
int maxX, int maxY)
{
win->flags.upos_set = 1;
win->upos.x = x;
win->upos.y = y;
win->flags.setAspect = 1;
win->minAspect.x = minX;
win->minAspect.y = minY;
win->maxAspect.x = maxX;
win->maxAspect.y = maxY;
if (win->view->flags.realized)
setSizeHints(win);
WMMoveWidget(win, x, y);
}
void
WMSetWindowInitialSize(WMWindow *win, unsigned width, unsigned height)
WMSetWindowInitialPosition(WMWindow *win, int x, int y)
{
win->usize.width = width;
win->usize.height = height;
win->flags.setUPos = 1;
win->upos.x = x;
win->upos.y = y;
if (win->view->flags.realized)
setSizeHints(win);
WMResizeWidget(win, width, height);
setSizeHints(win);
}
void
WMSetWindowMinSize(WMWindow *win, unsigned width, unsigned height)
{