mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-20 04:48:06 +01:00
updated upzzle, removed SetWindowInitialSize added SetWindowAspectRatio
This commit is contained in:
@@ -4,7 +4,8 @@ changes since wmaker 0.62.0:
|
|||||||
- added drag and drop
|
- added drag and drop
|
||||||
- changed selection code
|
- changed selection code
|
||||||
- added clientdata to WMFindInBag
|
- added clientdata to WMFindInBag
|
||||||
|
- removed SetWindowInitialSize()
|
||||||
|
- added SetWindowAspectRatio()
|
||||||
|
|
||||||
changes since wmaker 0.61.1:
|
changes since wmaker 0.61.1:
|
||||||
............................
|
............................
|
||||||
|
|||||||
@@ -832,7 +832,8 @@ void WMSetWindowCloseAction(WMWindow *win, WMAction *action, void *clientData);
|
|||||||
|
|
||||||
void WMSetWindowInitialPosition(WMWindow *win, int x, int y);
|
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);
|
void WMSetWindowMaxSize(WMWindow *win, unsigned width, unsigned height);
|
||||||
|
|
||||||
|
|||||||
@@ -79,28 +79,50 @@ Bool SlideButton(int button)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define SWAP(a,b) {int tmp; tmp=a; a=b; b=tmp;}
|
||||||
|
|
||||||
void ResetGame(void)
|
void ResetGame(void)
|
||||||
{
|
{
|
||||||
int i, x, y;
|
int i, x, y, ox, oy;
|
||||||
|
|
||||||
|
|
||||||
MoveCount = 0;
|
MoveCount = 0;
|
||||||
|
|
||||||
memset(Map, -1, Size*Size);
|
|
||||||
|
|
||||||
for (i = 0; i < Size*Size-1; i++) {
|
for (i = 0; i < Size*Size-1; i++) {
|
||||||
while (1) {
|
Map[i] = i;
|
||||||
int pos = rand()%(Size*Size);
|
}
|
||||||
if (Map[pos] < 0) {
|
Map[i] = -1;
|
||||||
Map[pos] = i;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
for (y = 0; y < Size; y++) {
|
oy = y;
|
||||||
for (x = 0; x < Size; x++) {
|
|
||||||
if (MAP(x,y) >= 0) {
|
|
||||||
MoveButton(MAP(x,y), x, y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
@@ -148,6 +190,15 @@ int main(int argc, char **argv)
|
|||||||
win = WMCreateWindow(scr, "puzzle");
|
win = WMCreateWindow(scr, "puzzle");
|
||||||
WMResizeWidget(win, WinSize, WinSize);
|
WMResizeWidget(win, WinSize, WinSize);
|
||||||
WMSetWindowTitle(win, "zuPzel");
|
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 (i = y = 0; y < Size && i < Size*Size-1; y++) {
|
||||||
for (x = 0; x < Size && i < Size*Size-1; x++) {
|
for (x = 0; x < Size && i < Size*Size-1; x++) {
|
||||||
@@ -157,8 +208,8 @@ int main(int argc, char **argv)
|
|||||||
RHSVColor hsv;
|
RHSVColor hsv;
|
||||||
|
|
||||||
hsv.hue = i*360/(Size*Size-1);
|
hsv.hue = i*360/(Size*Size-1);
|
||||||
hsv.saturation = 100;
|
hsv.saturation = 120;
|
||||||
hsv.value = 180;
|
hsv.value = 200;
|
||||||
|
|
||||||
RHSVtoRGB(&hsv, &col);
|
RHSVtoRGB(&hsv, &col);
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,10 @@ typedef struct W_Window {
|
|||||||
WMSize baseSize;
|
WMSize baseSize;
|
||||||
WMSize minSize;
|
WMSize minSize;
|
||||||
WMSize maxSize;
|
WMSize maxSize;
|
||||||
|
WMPoint minAspect;
|
||||||
|
WMPoint maxAspect;
|
||||||
|
|
||||||
WMPoint upos;
|
WMPoint upos;
|
||||||
WMSize usize;
|
|
||||||
|
|
||||||
WMAction *closeAction;
|
WMAction *closeAction;
|
||||||
void *closeData;
|
void *closeData;
|
||||||
@@ -39,7 +40,8 @@ typedef struct W_Window {
|
|||||||
unsigned configured:1;
|
unsigned configured:1;
|
||||||
unsigned documentEdited:1;
|
unsigned documentEdited:1;
|
||||||
|
|
||||||
unsigned upos_set:1;
|
unsigned setUPos:1;
|
||||||
|
unsigned setAspect:1;
|
||||||
} flags;
|
} flags;
|
||||||
} _Window;
|
} _Window;
|
||||||
|
|
||||||
@@ -310,16 +312,11 @@ setSizeHints(WMWindow *win)
|
|||||||
|
|
||||||
hints->flags = 0;
|
hints->flags = 0;
|
||||||
|
|
||||||
if (win->flags.upos_set) {
|
if (win->flags.setUPos) {
|
||||||
hints->flags |= PPosition;
|
hints->flags |= USPosition;
|
||||||
hints->x = win->upos.x;
|
hints->x = win->upos.x;
|
||||||
hints->y = win->upos.y;
|
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) {
|
if (win->minSize.width>0 && win->minSize.height>0) {
|
||||||
hints->flags |= PMinSize;
|
hints->flags |= PMinSize;
|
||||||
hints->min_width = win->minSize.width;
|
hints->min_width = win->minSize.width;
|
||||||
@@ -340,6 +337,14 @@ setSizeHints(WMWindow *win)
|
|||||||
hints->width_inc = win->resizeIncrement.width;
|
hints->width_inc = win->resizeIncrement.width;
|
||||||
hints->height_inc = win->resizeIncrement.height;
|
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) {
|
if (hints->flags) {
|
||||||
XSetWMNormalHints(win->view->screen->display, win->view->window, hints);
|
XSetWMNormalHints(win->view->screen->display, win->view->window, hints);
|
||||||
@@ -447,29 +452,32 @@ realizeWindow(WMWindow *win)
|
|||||||
|
|
||||||
|
|
||||||
void
|
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->flags.setAspect = 1;
|
||||||
win->upos.x = x;
|
win->minAspect.x = minX;
|
||||||
win->upos.y = y;
|
win->minAspect.y = minY;
|
||||||
|
win->maxAspect.x = maxX;
|
||||||
|
win->maxAspect.y = maxY;
|
||||||
if (win->view->flags.realized)
|
if (win->view->flags.realized)
|
||||||
setSizeHints(win);
|
setSizeHints(win);
|
||||||
WMMoveWidget(win, x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WMSetWindowInitialSize(WMWindow *win, unsigned width, unsigned height)
|
WMSetWindowInitialPosition(WMWindow *win, int x, int y)
|
||||||
{
|
{
|
||||||
win->usize.width = width;
|
win->flags.setUPos = 1;
|
||||||
win->usize.height = height;
|
win->upos.x = x;
|
||||||
|
win->upos.y = y;
|
||||||
if (win->view->flags.realized)
|
if (win->view->flags.realized)
|
||||||
setSizeHints(win);
|
setSizeHints(win);
|
||||||
WMResizeWidget(win, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WMSetWindowMinSize(WMWindow *win, unsigned width, unsigned height)
|
WMSetWindowMinSize(WMWindow *win, unsigned width, unsigned height)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user