208 lines
5.5 KiB
C
208 lines
5.5 KiB
C
/*
|
|
* Kangaroo Punch MultiPlayer Game Server Mark II
|
|
* Copyright (C) 2020-2021 Scott Duensing
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
|
|
/*
|
|
* To Do:
|
|
*
|
|
* - Fix function naming to be classItemVerb (checkboxValueGet instead of checkboxGetValue)
|
|
* - Replace any direct data manipulation from outside a class with methods to handle it
|
|
* - More widget states: Ghosted, hidden
|
|
* - Move setup math for paint events inside the dirty check
|
|
* - Methods that can change the width of a widget (such as setTitle) need to repaint the parent window as well
|
|
*
|
|
*/
|
|
|
|
|
|
#include "os.h"
|
|
#include "vesa.h"
|
|
#include "mouse.h"
|
|
#include "keyboard.h"
|
|
#include "task.h"
|
|
#include "image.h"
|
|
#include "font.h"
|
|
|
|
#include "gui.h"
|
|
#include "widget.h"
|
|
#include "desktop.h"
|
|
#include "window.h"
|
|
#include "button.h"
|
|
#include "label.h"
|
|
#include "checkbox.h"
|
|
#include "radio.h"
|
|
#include "picture.h"
|
|
#include "frame.h"
|
|
#include "textbox.h"
|
|
|
|
|
|
void buttonClick(WidgetT *widget) {
|
|
logWrite("'%s' was clicked.\n", ((ButtonT *)widget)->title);
|
|
}
|
|
|
|
|
|
void test(void *data) {
|
|
MouseT *mouse = NULL;
|
|
ImageT *pointer = NULL;
|
|
ColorT alpha;
|
|
DesktopT *desktop = (DesktopT *)guiRootGet();
|
|
WindowT *w1 = NULL;
|
|
WindowT *w2 = NULL;
|
|
WindowT *w3 = NULL;
|
|
ButtonT *b1 = NULL;
|
|
LabelT *l1 = NULL;
|
|
CheckboxT *c1 = NULL;
|
|
RadioT *r1a = NULL;
|
|
RadioT *r2a = NULL;
|
|
RadioT *r3a = NULL;
|
|
RadioT *r1b = NULL;
|
|
RadioT *r2b = NULL;
|
|
RadioT *r3b = NULL;
|
|
PictureT *p1 = NULL;
|
|
FrameT *f1 = NULL;
|
|
TextboxT *t1 = NULL;
|
|
int8_t key = 0;
|
|
|
|
(void)data;
|
|
|
|
pointer = imageLoad("mouse.png");
|
|
alpha = imagePixelGet(pointer, 5, 0);
|
|
|
|
// Windows
|
|
w1 = windowNew(25, 25, 300, 200, "Window 1");
|
|
guiAttach(W(desktop), W(w1));
|
|
w2 = windowNew(150, 150, 300, 200, "Window 2");
|
|
guiAttach(W(desktop), W(w2));
|
|
w3 = windowNew(300, 300, 300, 200, "Window 3");
|
|
guiAttach(W(desktop), W(w3));
|
|
|
|
// Window 1
|
|
p1 = pictureNew(0, 0, "kanga.png");
|
|
guiAttach(W(w1), W(p1));
|
|
|
|
// Window 2
|
|
r1a = radioNew(10, 10, "Radio 1a", 1);
|
|
guiAttach(W(w2), W(r1a));
|
|
r2a = radioNew(20 + widgetGetWidth(W(r1a)), 10, "Radio 2a", 1);
|
|
guiAttach(W(w2), W(r2a));
|
|
r3a = radioNew(30 + widgetGetWidth(W(r1a)) + widgetGetWidth(W(r2a)), 10, "Radio 3a", 1);
|
|
guiAttach(W(w2), W(r3a));
|
|
r1b = radioNew(10, 35, "Radio 1b", 2);
|
|
guiAttach(W(w2), W(r1b));
|
|
r2b = radioNew(20 + widgetGetWidth(W(r1b)), 35, "Radio 2b", 2);
|
|
guiAttach(W(w2), W(r2b));
|
|
r3b = radioNew(30 + widgetGetWidth(W(r1b)) + widgetGetWidth(W(r2b)), 35, "Radio 3b", 2);
|
|
guiAttach(W(w2), W(r3b));
|
|
radioSetSelected(r1a);
|
|
radioSetSelected(r2b);
|
|
t1 = textboxNew(10, 60, 265, "Test Textbox");
|
|
textboxSetValue(t1, "Text to edit!");
|
|
guiAttach(W(w2), W(t1));
|
|
|
|
// Window 3
|
|
f1 = frameNew(10, 5, 175, 125, "Test Frame");
|
|
guiAttach(W(w3), W(f1));
|
|
b1 = buttonNew(10, 10, "Test Button", buttonClick);
|
|
guiAttach(W(f1), W(b1));
|
|
l1 = labelNew(10, 40, "Test Label");
|
|
guiAttach(W(f1), W(l1));
|
|
c1 = checkboxNew(10, 65, "Test Checkbox");
|
|
guiAttach(W(f1), W(c1));
|
|
|
|
do {
|
|
mouse = mouseRead();
|
|
if (keyHit()) {
|
|
key = keyASCII();
|
|
guiProcessKeyboard(keyASCII(), keyScanCode(), keyShift(), keyControl(), keyAlt());
|
|
} else {
|
|
key = 0;
|
|
}
|
|
guiProcessMouse(mouse);
|
|
guiComposite();
|
|
imageRenderWithAlpha(pointer, mouse->x, mouse->y, alpha);
|
|
vbeWaitVBlank();
|
|
vbePresent();
|
|
} while (key != 27 && !(!mouse->buttonRight && mouse->buttonRightWasDown)); // Exit on release of right-click.
|
|
|
|
imageUnload(&pointer);
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
uint16_t xResolution = 0;
|
|
uint16_t yResolution = 0;
|
|
uint16_t colorDepth = 0;
|
|
char logName[32] = { "log.log" };
|
|
char *c = NULL;
|
|
int16_t x = strlen(argv[0]);
|
|
|
|
// 0 1 2 3 4 5 6 7 8
|
|
// 12345678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
printf("Kangaroo Punch MultiPlayer DOS Game Client Mark II\n");
|
|
printf("Copyright (C) 2020-2021 Scott Duensing scott@kangaroopunch.com\n\n");
|
|
|
|
// Find last portion of filename.
|
|
while (x > 0) {
|
|
if (argv[0][x] == '/' || argv[0][x] == '\\') break;
|
|
x--;
|
|
}
|
|
if (strlen(argv[0]) - x < 32) {
|
|
// Replace any extension with ".log"
|
|
strncpy(logName, &argv[0][x + 1], 31);
|
|
c = strstr(logName, ".");
|
|
if (c) *c = 0;
|
|
strncat(logName, ".log", 31);
|
|
}
|
|
|
|
logOpen(logName, 0);
|
|
|
|
// Command line needs to have the desired resolution and color depth on it.
|
|
if (argc != 4) {
|
|
vbeShowInfo();
|
|
return 0;
|
|
}
|
|
xResolution = atoi(argv[1]);
|
|
yResolution = atoi(argv[2]);
|
|
colorDepth = atoi(argv[3]);
|
|
|
|
// Do we have the video mode they asked for?
|
|
if (vbeStartup(xResolution, yResolution, colorDepth)) {
|
|
return 1;
|
|
}
|
|
|
|
mouseStartup();
|
|
guiStartup();
|
|
taskStartup(64);
|
|
|
|
taskCreate(test, NULL);
|
|
taskRun();
|
|
|
|
taskShutdown();
|
|
guiShutdown();
|
|
mouseShutdown();
|
|
vbeShutdown();
|
|
|
|
#ifdef memoryLeakShow
|
|
memoryLeaksShow();
|
|
#endif
|
|
|
|
logClose();
|
|
|
|
return 0;
|
|
}
|