Basic window manager. Too slow!
This commit is contained in:
parent
b5af19dd12
commit
a83fddc486
6 changed files with 133 additions and 64 deletions
|
@ -33,7 +33,7 @@ BINDIR = bin
|
||||||
|
|
||||||
# CFLAGS, LDFLAGS, CPPFLAGS, PREFIX can be overriden on CLI
|
# CFLAGS, LDFLAGS, CPPFLAGS, PREFIX can be overriden on CLI
|
||||||
CFLAGS := $(DEBUG)
|
CFLAGS := $(DEBUG)
|
||||||
CFLAGS += -I$(SRCDIR)/installed/dos/include -I$(SRCDIR)/client/src
|
CFLAGS += -I$(SRCDIR)/shared -I$(SRCDIR)/installed/dos/include -I$(SRCDIR)/client/src
|
||||||
CPPFLAGS :=
|
CPPFLAGS :=
|
||||||
LDFLAGS := -L$(SRCDIR)/installed/dos/lib
|
LDFLAGS := -L$(SRCDIR)/installed/dos/lib
|
||||||
LDLIBS := -lgrx20 -ljpeg -lpng -lz
|
LDLIBS := -lgrx20 -ljpeg -lpng -lz
|
||||||
|
@ -56,6 +56,7 @@ ALL_LDLIBS := $(LDLIBS) -lc
|
||||||
|
|
||||||
# Source, Binaries, Dependencies
|
# Source, Binaries, Dependencies
|
||||||
SRC := $(shell find $(SRCDIR)/client -type f -name '*.c')
|
SRC := $(shell find $(SRCDIR)/client -type f -name '*.c')
|
||||||
|
SRC += $(shell find $(SRCDIR)/shared -type f -name '*.c')
|
||||||
OBJ := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%,$(SRC:.c=.o))
|
OBJ := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%,$(SRC:.c=.o))
|
||||||
DEP := $(OBJ:.o=.d)
|
DEP := $(OBJ:.o=.d)
|
||||||
BIN := $(BINDIR)/$(TARGET)
|
BIN := $(BINDIR)/$(TARGET)
|
||||||
|
|
3
build.sh
3
build.sh
|
@ -23,7 +23,8 @@
|
||||||
# See: https://github.com/andrewwutw/build-djgpp
|
# See: https://github.com/andrewwutw/build-djgpp
|
||||||
|
|
||||||
mkdir -p \
|
mkdir -p \
|
||||||
obj/client/src
|
obj/shared/thirdparty/memwatch \
|
||||||
|
obj/client/src/gui
|
||||||
|
|
||||||
source /opt/cross/djgpp/setenv
|
source /opt/cross/djgpp/setenv
|
||||||
|
|
||||||
|
|
|
@ -117,8 +117,6 @@ void guiShutdown(void) {
|
||||||
|
|
||||||
GrDestroyContext(_mousePointer);
|
GrDestroyContext(_mousePointer);
|
||||||
|
|
||||||
DEL(__guiBaseColors);
|
|
||||||
|
|
||||||
GrDestroyContext(__guiBackBuffer);
|
GrDestroyContext(__guiBackBuffer);
|
||||||
GrSetMode(GR_default_text);
|
GrSetMode(GR_default_text);
|
||||||
}
|
}
|
||||||
|
@ -134,7 +132,7 @@ void guiStartup(int16_t width, int16_t height, int16_t depth) {
|
||||||
//***TODO*** Die
|
//***TODO*** Die
|
||||||
}
|
}
|
||||||
GrSetRGBcolorMode();
|
GrSetRGBcolorMode();
|
||||||
__guiBaseColors = GrAllocEgaColors();
|
__guiBaseColors = GrAllocEgaColors(); // This does not need released.
|
||||||
__guiScreenBuffer = GrScreenContext();
|
__guiScreenBuffer = GrScreenContext();
|
||||||
__guiBackBuffer = GrCreateContext(GrScreenX(), GrScreenY(), NULL, NULL);
|
__guiBackBuffer = GrCreateContext(GrScreenX(), GrScreenY(), NULL, NULL);
|
||||||
|
|
||||||
|
|
|
@ -13,16 +13,21 @@ struct WidgetS;
|
||||||
typedef void (*GuiCallbackT)(void *data, ...);
|
typedef void (*GuiCallbackT)(void *data, ...);
|
||||||
typedef void (*WidgetEventT)(struct WidgetS *widget, ...);
|
typedef void (*WidgetEventT)(struct WidgetS *widget, ...);
|
||||||
|
|
||||||
|
typedef struct PointS {
|
||||||
|
int16_t x;
|
||||||
|
int16_t y;
|
||||||
|
} PointT;
|
||||||
|
|
||||||
typedef struct RectS {
|
typedef struct RectS {
|
||||||
uint16_t x;
|
int16_t x;
|
||||||
uint16_t y;
|
int16_t y;
|
||||||
union {
|
union {
|
||||||
uint16_t w;
|
int16_t w;
|
||||||
uint16_t x2;
|
int16_t x2;
|
||||||
};
|
};
|
||||||
union {
|
union {
|
||||||
uint16_t h;
|
int16_t h;
|
||||||
uint16_t y2;
|
int16_t y2;
|
||||||
};
|
};
|
||||||
} RectT;
|
} RectT;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,11 @@ WindowT *windowCreate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, char *titl
|
||||||
guiWidgetBaseSet((WidgetT *)win, __MAGIC_WINDOW, x, y, w, h);
|
guiWidgetBaseSet((WidgetT *)win, __MAGIC_WINDOW, x, y, w, h);
|
||||||
win->title = strdup(title);
|
win->title = strdup(title);
|
||||||
win->flags = flags;
|
win->flags = flags;
|
||||||
|
win->close.x = win->close.y = win->close.x2 = win->close.y2 = 0;
|
||||||
|
win->titlebar.x = win->titlebar.y = win->titlebar.x2 = win->titlebar.y2 = 0;
|
||||||
|
win->minimize.x = win->minimize.y = win->minimize.x2 = win->minimize.y2 = 0;
|
||||||
|
win->maximize.x = win->maximize.y = win->maximize.x2 = win->maximize.y2 = 0;
|
||||||
|
win->bounds.x = win->bounds.y = win->bounds.x2 = win->bounds.y2 = 0;
|
||||||
|
|
||||||
arrput(_windowList, win);
|
arrput(_windowList, win);
|
||||||
|
|
||||||
|
@ -83,12 +88,7 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
// Set titlebar area.
|
// Set titlebar area.
|
||||||
w->titlebar.x = w->close.x2 + 2;
|
w->titlebar.x = w->close.x2 + 2;
|
||||||
} else {
|
} else {
|
||||||
// No close box.
|
// No close box - set titlebar area.
|
||||||
w->close.x = 0;
|
|
||||||
w->close.y = 0;
|
|
||||||
w->close.x2 = 0;
|
|
||||||
w->close.y2 = 0;
|
|
||||||
// Set titlebar area.
|
|
||||||
w->titlebar.x = x1;
|
w->titlebar.x = x1;
|
||||||
}
|
}
|
||||||
w->titlebar.y = y1;
|
w->titlebar.y = y1;
|
||||||
|
@ -118,12 +118,6 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
minimizeOffset = 26;
|
minimizeOffset = 26;
|
||||||
// Set titlebar area.
|
// Set titlebar area.
|
||||||
w->titlebar.x2 -= 26;
|
w->titlebar.x2 -= 26;
|
||||||
} else {
|
|
||||||
// No maximize box.
|
|
||||||
w->maximize.x = 0;
|
|
||||||
w->maximize.y = 0;
|
|
||||||
w->maximize.x2 = 0;
|
|
||||||
w->maximize.y2 = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Minimize box?
|
// Minimize box?
|
||||||
|
@ -146,12 +140,6 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
GrVLine(tx2, ty1, ty2, GUI_BLACK);
|
GrVLine(tx2, ty1, ty2, GUI_BLACK);
|
||||||
// Set titlebar area.
|
// Set titlebar area.
|
||||||
w->titlebar.x2 -= 26;
|
w->titlebar.x2 -= 26;
|
||||||
} else {
|
|
||||||
// No minimize box.
|
|
||||||
w->minimize.x = 0;
|
|
||||||
w->minimize.y = 0;
|
|
||||||
w->minimize.x2 = 0;
|
|
||||||
w->minimize.y2 = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Title font area is 12px high.
|
// Title font area is 12px high.
|
||||||
|
@ -206,6 +194,10 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
GrVLine(x1, y1, y2, GUI_WHITE);
|
GrVLine(x1, y1, y2, GUI_WHITE);
|
||||||
GrHLine(x1, x2, y2, GUI_DARKGRAY);
|
GrHLine(x1, x2, y2, GUI_DARKGRAY);
|
||||||
GrVLine(x2, y1, y2, GUI_DARKGRAY);
|
GrVLine(x2, y1, y2, GUI_DARKGRAY);
|
||||||
|
w->bounds.x = x1;
|
||||||
|
w->bounds.x2 = x2;
|
||||||
|
w->bounds.y = y1;
|
||||||
|
w->bounds.y2 = y2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -233,43 +225,114 @@ RegisterT *windowRegister(uint8_t magic) {
|
||||||
|
|
||||||
|
|
||||||
void wmPaint(GrMouseEvent *event) {
|
void wmPaint(GrMouseEvent *event) {
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
WidgetT *widget;
|
WidgetT *widget;
|
||||||
static char text[256] = { 0 };
|
WindowT *win;
|
||||||
|
static uint8_t dragging = 0;
|
||||||
|
static PointT dragOffset = { 0 };
|
||||||
|
|
||||||
// Paint event debug info.
|
// Do we have windows?
|
||||||
#define APPEND (&text[strlen(text)])
|
if (arrlen(_windowList) > 0) {
|
||||||
// if (event->flags != 0) {
|
|
||||||
strcpy(text, "Events: ");
|
// Paint all windows.
|
||||||
if(event->flags & GR_M_MOTION) strcpy( APPEND, "[moved] ");
|
for (i=0; i<arrlen(_windowList); i++) {
|
||||||
if(event->flags & GR_M_LEFT_DOWN) strcpy( APPEND, "[left down] ");
|
GrSetContext(__guiBackBuffer);
|
||||||
if(event->flags & GR_M_MIDDLE_DOWN) strcpy( APPEND, "[middle down] ");
|
widget = (WidgetT *)_windowList[i];
|
||||||
if(event->flags & GR_M_RIGHT_DOWN) strcpy( APPEND, "[right down] ");
|
widget->reg->paint(widget);
|
||||||
if(event->flags & GR_M_P4_DOWN) strcpy( APPEND, "[p4 down] ");
|
}
|
||||||
if(event->flags & GR_M_P5_DOWN) strcpy( APPEND, "[p5 down] ");
|
|
||||||
if(event->flags & GR_M_LEFT_UP) strcpy( APPEND, "[left up] ");
|
// Get top window.
|
||||||
if(event->flags & GR_M_MIDDLE_UP) strcpy( APPEND, "[middle up] ");
|
win = _windowList[arrlen(_windowList) - 1];
|
||||||
if(event->flags & GR_M_RIGHT_UP) strcpy( APPEND, "[right up] ");
|
|
||||||
if(event->flags & GR_M_P4_UP) strcpy( APPEND, "[p4 up] ");
|
// Wrap left button processing with a 'for' so we can 'break' out of it.
|
||||||
if(event->flags & GR_M_P5_UP) strcpy( APPEND, "[p5 up] ");
|
for (;;) {
|
||||||
if(event->flags & GR_M_KEYPRESS) sprintf(APPEND, "[key (0x%03x)] ", event->key);
|
// Is the left mouse button down?
|
||||||
sprintf(APPEND, "at X=%d, Y=%d, ", event->x, event->y);
|
if (event->buttons & GR_M_LEFT) {
|
||||||
sprintf(APPEND,
|
|
||||||
"buttons=%c%c%c, ",
|
// DEBUG - draw active regions. ***TODO*** No resize grabber here.
|
||||||
(event->buttons & GR_M_LEFT) ? 'L' : 'l',
|
GrBox(win->bounds.x, win->bounds.y, win->bounds.x2, win->bounds.y2, GUI_YELLOW);
|
||||||
(event->buttons & GR_M_MIDDLE) ? 'M' : 'm',
|
GrBox(win->base.r.x, win->base.r.y, win->base.r.x + win->base.r.w - 1, win->base.r.y + win->base.r.h - 1, GUI_YELLOW);
|
||||||
(event->buttons & GR_M_RIGHT) ? 'R' : 'r'
|
GrBox(win->close.x, win->close.y, win->close.x2, win->close.y2, GUI_RED);
|
||||||
);
|
GrBox(win->titlebar.x, win->titlebar.y, win->titlebar.x2, win->titlebar.y2, GUI_RED);
|
||||||
sprintf(APPEND, "deltaT=%ld (ms)", event->dtime);
|
GrBox(win->minimize.x, win->minimize.y, win->minimize.x2, win->minimize.y2, GUI_RED);
|
||||||
// }
|
GrBox(win->maximize.x, win->maximize.y, win->maximize.x2, win->maximize.y2, GUI_RED);
|
||||||
GrTextXY(0, 0, text, GUI_WHITE, GUI_BLACK);
|
|
||||||
|
// Are we currently dragging?
|
||||||
|
if (dragging) {
|
||||||
|
|
||||||
|
// Move window to new mouse location.
|
||||||
|
win->base.r.x = event->x - dragOffset.x;
|
||||||
|
win->base.r.y = event->y - dragOffset.y;
|
||||||
|
break;
|
||||||
|
|
||||||
|
} else { // Dragging.
|
||||||
|
|
||||||
|
// Did the button just go down?
|
||||||
|
if (event->flags & GR_M_LEFT_DOWN) {
|
||||||
|
|
||||||
|
// Are we on the topmost window?
|
||||||
|
if (event->x <= win->bounds.x2 && event->x >= win->bounds.x && event->y <= win->bounds.y2 && event->y >= win->bounds.y) {
|
||||||
|
|
||||||
|
//***TODO*** Are we inside the window content? Most likely, check first.
|
||||||
|
if (event->x <= (win->base.r.x + win->base.r.w - 1) && event->x >= win->base.r.x &&
|
||||||
|
event->y <= (win->base.r.y + win->base.r.h - 1) && event->y >= win->base.r.y) {
|
||||||
|
//***TODO*** Send to window for processing.
|
||||||
|
}
|
||||||
|
|
||||||
|
//***TODO*** Are we inside the close button?
|
||||||
|
|
||||||
|
// Are we inside the title bar to begin dragging?
|
||||||
|
if (event->x <= win->titlebar.x2 && event->x >= win->titlebar.x && event->y <= win->titlebar.y2 && event->y >= win->titlebar.y) {
|
||||||
|
dragging = 1;
|
||||||
|
dragOffset.x = event->x - win->base.r.x;
|
||||||
|
dragOffset.y = event->y - win->base.r.y;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***TODO*** Are we inside the minimize button?
|
||||||
|
//***TODO*** Are we inside the maximize button?
|
||||||
|
|
||||||
|
} else { // On topmost window.
|
||||||
|
|
||||||
|
// Not over topmost window. Search backwards to find first window we're inside.
|
||||||
|
i = arrlen(_windowList) - 2;
|
||||||
|
if (i >= 0) {
|
||||||
|
for (; i>=0; i--) {
|
||||||
|
win = _windowList[i];
|
||||||
|
if (event->x <= win->bounds.x2 && event->x >= win->bounds.x && event->y <= win->bounds.y2 && event->y >= win->bounds.y) {
|
||||||
|
// Bring this window forward.
|
||||||
|
arrdel(_windowList, i);
|
||||||
|
arrput(_windowList, win);
|
||||||
|
// If we happened to be in the title bar, go ahead and start dragging.
|
||||||
|
if (event->x <= win->titlebar.x2 && event->x >= win->titlebar.x && event->y <= win->titlebar.y2 && event->y >= win->titlebar.y) {
|
||||||
|
dragging = 1;
|
||||||
|
dragOffset.x = event->x - win->base.r.x;
|
||||||
|
dragOffset.y = event->y - win->base.r.y;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // On topmost window.
|
||||||
|
|
||||||
|
} // Button just went down.
|
||||||
|
|
||||||
|
} // Dragging.
|
||||||
|
|
||||||
|
} else { // Left mouse button.
|
||||||
|
|
||||||
|
// Left mouse not down.
|
||||||
|
|
||||||
|
// Can no longer be dragging.
|
||||||
|
dragging = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
} // Left button processing.
|
||||||
|
|
||||||
|
} // Do we have windows?
|
||||||
|
|
||||||
// Paint all windows.
|
|
||||||
for (i=0; i<arrlen(_windowList); i++) {
|
|
||||||
GrSetContext(__guiBackBuffer);
|
|
||||||
widget = (WidgetT *)_windowList[i];
|
|
||||||
widget->reg->paint(widget);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ typedef struct WindowS {
|
||||||
RectT titlebar;
|
RectT titlebar;
|
||||||
RectT minimize;
|
RectT minimize;
|
||||||
RectT maximize;
|
RectT maximize;
|
||||||
|
RectT bounds;
|
||||||
} WindowT;
|
} WindowT;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue