Resizing working.
This commit is contained in:
parent
b6f78593e4
commit
88f440f0c4
4 changed files with 74 additions and 79 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,5 +4,6 @@ build-*/
|
|||
installed/
|
||||
thirdparty/jpeg-9e/.deps/
|
||||
thirdparty/libpng-1.6.37/.deps/
|
||||
capture/
|
||||
|
||||
*~
|
||||
|
|
|
@ -134,6 +134,7 @@ static void windowCache(WindowT *w) {
|
|||
if (w->title) {
|
||||
fontSet(__guiFontVGA8x16);
|
||||
fontColorSet(GUI_WHITE, titleBackgroundColor);
|
||||
// ***TODO*** Does not clip!
|
||||
fontRender(w->title, w->titlebar.x + 12, w->titlebar.y + 2);
|
||||
}
|
||||
surfaceBoxHighlight(w->titlebar.x, w->titlebar.y, w->titlebar.x2, w->titlebar.y2, GUI_WHITE, GUI_BLACK);
|
||||
|
@ -283,23 +284,38 @@ void windowFocusSet(WindowT *win) {
|
|||
|
||||
// Do we have a focused window at the moment?
|
||||
if (!_windowTop || !win) {
|
||||
// If there's a list of windows, use the topmost.
|
||||
_windowTop = NULL;
|
||||
// If there's a list of windows, use the topmost non-minimized.
|
||||
if (arrlen(_windowList) > 0) {
|
||||
_windowTop = _windowList[arrlen(_windowList) - 1];
|
||||
guiWidgetDirtySet(W(_windowTop), 1);
|
||||
} else {
|
||||
// If no list, set it to NULL.
|
||||
_windowTop = NULL;
|
||||
// Work backwards through the window list.
|
||||
i = arrlen(_windowList) - 1;
|
||||
for (; i>=0; i--) {
|
||||
if (_windowList[i]->flags & WIN_IS_ICON) {
|
||||
// Minimized window. Skip it.
|
||||
continue;
|
||||
} else {
|
||||
// Open window. Use as new top.
|
||||
_windowTop = _windowList[i];
|
||||
guiWidgetDirtySet(W(_windowTop), 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Did they even pass in a window? If not, we're just intended to fixup _windowTop.
|
||||
if (!win) return;
|
||||
|
||||
// Are we already the topmost window?
|
||||
// Were we already the topmost window?
|
||||
if (win == _windowTop) return;
|
||||
|
||||
// Is this window minimized?
|
||||
if (win->flags & WIN_IS_ICON) {
|
||||
// Can't receive focus - find new top.
|
||||
windowFocusSet(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark old focus and new focus dirty to repaint title bar.
|
||||
guiWidgetDirtySet(W(win), 1);
|
||||
guiWidgetDirtySet(W(_windowTop), 1);
|
||||
|
@ -321,6 +337,14 @@ void windowFocusSet(WindowT *win) {
|
|||
}
|
||||
|
||||
|
||||
void windowMinimize(WindowT *win) {
|
||||
// Minimize.
|
||||
win->flags |= WIN_IS_ICON;
|
||||
// Find topmost non-minimized window.
|
||||
windowFocusSet(NULL);
|
||||
}
|
||||
|
||||
|
||||
void windowMoveTo(WindowT *w, uint16_t x, uint16_t y) {
|
||||
int16_t dx = x - w->base.r.x;
|
||||
int16_t dy = y - w->base.r.y;
|
||||
|
@ -435,6 +459,22 @@ RegisterT *windowRegister(uint8_t magic) {
|
|||
}
|
||||
|
||||
|
||||
void windowResizeTo(WindowT *win, uint16_t width, uint16_t height) {
|
||||
// Too small?
|
||||
if (width < 80) width = 80;
|
||||
if (height < 80) height = 80;
|
||||
|
||||
// Too big?
|
||||
if (win->bounds.w - win->bounds.x + (width - win->base.r.w) > surfaceWidthGet(win->content)) width = (win->base.r.w - (win->bounds.x2 - win->bounds.x) + surfaceWidthGet(win->content));
|
||||
if (win->bounds.h - win->bounds.y + (height - win->base.r.h) > surfaceHeightGet(win->content)) height = (win->base.r.h - (win->bounds.y2 - win->bounds.y) + surfaceHeightGet(win->content));
|
||||
|
||||
// Do resize.
|
||||
win->base.r.w = width;
|
||||
win->base.r.h =height;
|
||||
windowCache(win);
|
||||
}
|
||||
|
||||
|
||||
void wmShutdown(void) {
|
||||
while (arrlen(_windowList) > 0) {
|
||||
windowDestroy((WidgetT *)_windowList[0]);
|
||||
|
@ -454,7 +494,7 @@ void wmUpdate(EventT *event) {
|
|||
int16_t y2;
|
||||
uint8_t onResize = 0;
|
||||
WidgetT *widget;
|
||||
WindowT *win;
|
||||
WindowT *win = NULL;
|
||||
static uint8_t resizing = 0;
|
||||
static PointT resizeOffset = { 0 };
|
||||
static uint8_t dragging = 0;
|
||||
|
@ -475,17 +515,19 @@ void wmUpdate(EventT *event) {
|
|||
}
|
||||
|
||||
// Get top window.
|
||||
win = _windowList[arrlen(_windowList) - 1];
|
||||
win = _windowTop;
|
||||
|
||||
// Get right/bottom of window.
|
||||
x2 = win->base.r.x + win->base.r.w - 1;
|
||||
y2 = win->base.r.y + win->base.r.h - 1;
|
||||
// If we found a window, get right/bottom.
|
||||
if (win) {
|
||||
x2 = win->base.r.x + win->base.r.w - 1;
|
||||
y2 = win->base.r.y + win->base.r.h - 1;
|
||||
}
|
||||
|
||||
// Wrap left button processing with a 'for' so we can 'break' out of it.
|
||||
for (;;) {
|
||||
|
||||
// Does the topmost window have a resize?
|
||||
if (win->flags & WIN_RESIZE) {
|
||||
if (win && win->flags & WIN_RESIZE) {
|
||||
// Are we over the resize of the topmost window?
|
||||
if ((event->x <= win->resize1.x2 && event->x >= win->resize1.x && event->y <= win->resize1.y2 && event->y >= win->resize1.y) ||
|
||||
(event->x <= win->resize2.x2 && event->x >= win->resize2.x && event->y <= win->resize2.y2 && event->y >= win->resize2.y) ||
|
||||
|
@ -520,19 +562,22 @@ void wmUpdate(EventT *event) {
|
|||
|
||||
if (resizing) {
|
||||
|
||||
} else { // Resizing
|
||||
windowResizeTo(win, event->x - resizeOffset.x, event->y - resizeOffset.y);
|
||||
break;
|
||||
|
||||
} else { // Resizing.
|
||||
|
||||
// Did the button just go down?
|
||||
if (event->flags & EVENT_FLAG_LEFT_DOWN) {
|
||||
|
||||
// Are we on the topmost window?
|
||||
if (event->x <= x2 && event->x >= win->base.r.x && event->y <= y2 && event->y >= win->base.r.y) {
|
||||
if (win && event->x <= x2 && event->x >= win->base.r.x && event->y <= y2 && event->y >= win->base.r.y) {
|
||||
|
||||
// Are we on the resizing area?
|
||||
if (onResize) {
|
||||
resizing = 1;
|
||||
resizeOffset.x = event->x - win->base.r.x;
|
||||
resizeOffset.y = event->y - win->base.r.y;
|
||||
resizeOffset.x = event->x - win->base.r.w;
|
||||
resizeOffset.y = event->y - win->base.r.h;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -556,7 +601,8 @@ void wmUpdate(EventT *event) {
|
|||
|
||||
// Are we inside the minimize button? Does not include button frame on purpose.
|
||||
if (win->flags & WIN_MINIMIZE &&event->x < win->minimize.x2 && event->x > win->minimize.x && event->y < win->minimize.y2 && event->y > win->minimize.y) {
|
||||
win->flags |= WIN_IS_ICON;
|
||||
windowMinimize(win);
|
||||
break;
|
||||
}
|
||||
|
||||
// Are we inside the maximize button? Does not include button frame on purpose.
|
||||
|
@ -567,10 +613,14 @@ void wmUpdate(EventT *event) {
|
|||
} else { // On topmost window.
|
||||
|
||||
// Not over topmost window. Search backwards to find first window we're inside.
|
||||
i = arrlen(_windowList) - 2;
|
||||
i = arrlen(_windowList) - 1;
|
||||
if (i >= 0) {
|
||||
for (; i>=0; i--) {
|
||||
win = _windowList[i];
|
||||
// Is this the current window?
|
||||
if (win == _windowTop) continue;
|
||||
// Is this window minimized?
|
||||
if (win->flags & WIN_IS_ICON) continue;
|
||||
// Get right/bottom of window.
|
||||
x2 = win->base.r.x + win->base.r.w - 1;
|
||||
y2 = win->base.r.y + win->base.r.h - 1;
|
||||
|
|
|
@ -37,9 +37,11 @@ extern uint8_t __MAGIC_WINDOW; // Magic ID assigned to us from the GUI.
|
|||
WindowT *windowCreate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, char *title, int flags, ...);
|
||||
void windowDestroy(struct WidgetS *widget, ...);
|
||||
void windowFocusSet(WindowT *win);
|
||||
void windowMinimize(WindowT *win);
|
||||
void windowMoveTo(WindowT *win, uint16_t x, uint16_t y);
|
||||
void windowPaint(struct WidgetS *widget, ...);
|
||||
RegisterT *windowRegister(uint8_t magic);
|
||||
void windowResizeTo(WindowT *win, uint16_t width, uint16_t height);
|
||||
|
||||
|
||||
void wmShutdown(void);
|
||||
|
|
|
@ -11,7 +11,7 @@ int main(int argc, char *argv[]) {
|
|||
memoryStartup(argv[0]);
|
||||
logOpenByHandle(memoryLogHandleGet());
|
||||
|
||||
if (guiStartup(800, 600, 32) == SUCCESS) {
|
||||
if (guiStartup(800, 600, 16) == SUCCESS) {
|
||||
for (i=1; i<4; i++) {
|
||||
sprintf(title, "Testing %d", i);
|
||||
windowCreate(i * 50, i * 50, 300, 200, title, WIN_CLOSE | WIN_MAXIMIZE | WIN_MINIMIZE);
|
||||
|
@ -25,61 +25,3 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int tui(int argc, char *argv[]) {
|
||||
EventT event = { 0 };
|
||||
uint16_t x = 5;
|
||||
uint16_t y = 5;
|
||||
uint16_t tx;
|
||||
uint16_t ty;
|
||||
FontT *vga8x16 = NULL;
|
||||
FontT *vga8x8 = NULL;
|
||||
|
||||
(void)argc;
|
||||
|
||||
memoryStartup(argv[0]);
|
||||
logOpenByHandle(memoryLogHandleGet());
|
||||
|
||||
if (guiStartup(800, 600, 32) == SUCCESS) {
|
||||
|
||||
vga8x8 = fontLoad("vga8x8.dat");
|
||||
vga8x16 = fontLoad("vga8x16.dat");
|
||||
|
||||
// Run until keypress.
|
||||
while (1) {
|
||||
// Paint desktop.
|
||||
surfaceSet(__guiBackBuffer);
|
||||
surfaceClear(GUI_CYAN);
|
||||
|
||||
// Paint GUI.
|
||||
ty = y;
|
||||
fontSet(vga8x16);
|
||||
fontRender("\x1\xf\x2\x8 Title Bar _ \xfe X ", C(x), C(ty++)); ty++;
|
||||
fontSet(vga8x8);
|
||||
fontRender("\x2\x7\xda\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xbf\x1e", C(x), C(ty++));
|
||||
for (tx=0; tx<10; tx++) fontRender("\xb3 \xb3\xb0", C(x), C(ty++));
|
||||
fontRender("\xc0\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xd9\x1f", C(x), C(ty++));
|
||||
fontRender("\x11\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\x10\xfe", C(x), C(ty++));
|
||||
|
||||
// Copy to screen.
|
||||
videoBlit(0, 0, __guiBackBuffer);
|
||||
|
||||
// Check for exit.
|
||||
platformEventGet(&event);
|
||||
if (event.flags & EVENT_FLAG_KEYPRESS && event.key == KEY_ESC) break;
|
||||
}
|
||||
|
||||
fontUnload(&vga8x16);
|
||||
fontUnload(&vga8x8);
|
||||
|
||||
guiShutdown();
|
||||
}
|
||||
|
||||
logClose();
|
||||
memoryShutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue