commit 41b22dd9a7bfba5db01103c4d9fbc0ac8430396d Author: James Whiteman Date: Wed Dec 22 01:47:19 2021 -0800 X11 hello world diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3bf8a32 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 James Whiteman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2c4e1d1 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Develop +If you are on Linux: +- Navigate to command/linux in terminal. +- Run `sh setup.sh` to setup your environment. +- Run `sh rebuild.sh` to build the application. +- Navigate to earn/ and run `executable` to run the built program. + +If you are on Windows: +- Navigate to command/windows in command prompt. +- Run `setup.bat` to setup your environment. +- Run `rebuild.bat` to build the application. +- Navigate to earn/ and run `executable.exe` to run the built program. diff --git a/command/linux/rebuild.sh b/command/linux/rebuild.sh new file mode 100755 index 0000000..db9af49 --- /dev/null +++ b/command/linux/rebuild.sh @@ -0,0 +1,48 @@ +#Global definitions. +F_ROOT=$(readlink -f "$0") +D_ROOT=$(dirname "${F_ROOT}")/../../. +D_COMPILE=${D_ROOT}/compile +D_LINK=${D_ROOT}/link +D_EARN=${D_ROOT}/earn +F_COMPILE_LIST=${D_COMPILE}/project_files.txt +F_LINK_LIST=${D_LINK}/project_files.txt +echo "" > ${F_LINK_LIST} + +# Compile. +LINE=0 +LINE_COUNT=$(cat ${F_COMPILE_LIST} | wc -l) +while true +do + if [ ${LINE} -ge ${LINE_COUNT} ]; then + break + fi + LINE=$((LINE+1)) + F_COMPILE=$(head -n ${LINE} ${F_COMPILE_LIST} | tail -n 1) + I_COMPILE=${D_COMPILE}/${F_COMPILE} + O_COMPILE=${D_LINK}/${F_COMPILE}.o + mkdir -p "${O_COMPILE%/*}" + clang++ -I ${D_COMPILE} -c ${I_COMPILE} -o ${O_COMPILE} + echo ${O_COMPILE} >> ${F_LINK_LIST} +done + +# Libraries. +F_LIBRARY_LIST=${D_COMPILE}/libraries.txt +F_LIBRARY_OPTIONS=${D_LINK}/library_options.txt +echo "" > ${F_LIBRARY_OPTIONS} +LINE=0 +LINE_COUNT=$(cat ${F_LIBRARY_LIST} | wc -l) +while true +do + if [ ${LINE} -ge ${LINE_COUNT} ]; then + break + fi + LINE=$((LINE+1)) + LIBRARY="-l$(head -n ${LINE} ${F_LIBRARY_LIST}) " + echo $LIBRARY >> ${F_LIBRARY_OPTIONS} +done + +# Link. +I_LINK=$(cat ${F_LINK_LIST}) +I_LIBRARIES=$(cat ${F_LIBRARY_OPTIONS}) +O_LINK=${D_EARN}/executable +clang++ ${I_LIBRARIES} ${I_LINK} -o ${O_LINK} diff --git a/command/linux/setup.sh b/command/linux/setup.sh new file mode 100755 index 0000000..e69de29 diff --git a/compile/controller/event.h b/compile/controller/event.h new file mode 100644 index 0000000..7764354 --- /dev/null +++ b/compile/controller/event.h @@ -0,0 +1,7 @@ +#ifndef CONTROLLER_EVENT +#define CONTROLLER_EVENT +enum controller_event_t { + start, + stop +}; +#endif diff --git a/compile/controller/root.cpp b/compile/controller/root.cpp new file mode 100644 index 0000000..cb9438c --- /dev/null +++ b/compile/controller/root.cpp @@ -0,0 +1,36 @@ +#include "controller/root.h" +#include +#include +#include +#include + +controller_status_t root_controller_t::on_event(controller_event_t event) { + Display *d; + Window w; + XEvent e; + const char *msg = "Hello, World!"; + int s; + + d = XOpenDisplay(NULL); + if (d == NULL) { + return controller_status_t::error; + } + + s = DefaultScreen(d); + w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, BlackPixel(d, s), WhitePixel(d, s)); + XSelectInput(d, w, ExposureMask | KeyPressMask); + XMapWindow(d, w); + + while (true) { + XNextEvent(d, &e); + if (e.type == Expose) { + XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10); + XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg)); + } + if (e.type == KeyPress) + break; + } + + XCloseDisplay(d); + return controller_status_t::ok; +} diff --git a/compile/controller/root.h b/compile/controller/root.h new file mode 100644 index 0000000..e5d8205 --- /dev/null +++ b/compile/controller/root.h @@ -0,0 +1,11 @@ +#ifndef CONTROLLER_ROOT +#define CONTROLLER_ROOT +#include "controller/status.h" +#include "controller/event.h" + +class root_controller_t { + public: + + controller_status_t on_event(controller_event_t event); +}; +#endif diff --git a/compile/controller/status.h b/compile/controller/status.h new file mode 100644 index 0000000..7610fe7 --- /dev/null +++ b/compile/controller/status.h @@ -0,0 +1,7 @@ +#ifndef CONTROLLER_STATUS +#define CONTROLLER_STATUS +enum controller_status_t { + ok, + error +}; +#endif diff --git a/compile/libraries.txt b/compile/libraries.txt new file mode 100644 index 0000000..08d2b99 --- /dev/null +++ b/compile/libraries.txt @@ -0,0 +1 @@ +X11 diff --git a/compile/main.cpp b/compile/main.cpp new file mode 100644 index 0000000..af1c4c2 --- /dev/null +++ b/compile/main.cpp @@ -0,0 +1,8 @@ +#include "controller/root.h" +#include "controller/status.h" + +int main(int argc, char *argv[]) { + root_controller_t* controller = new root_controller_t(); + controller_status_t status = controller->on_event(controller_event_t::start); + return status; +} diff --git a/compile/project_files.txt b/compile/project_files.txt new file mode 100644 index 0000000..24b0fd7 --- /dev/null +++ b/compile/project_files.txt @@ -0,0 +1,2 @@ +main.cpp +controller/root.cpp diff --git a/earn/executable b/earn/executable new file mode 100755 index 0000000..b35282e Binary files /dev/null and b/earn/executable differ diff --git a/link/controller/root.cpp.o b/link/controller/root.cpp.o new file mode 100644 index 0000000..7526cf1 Binary files /dev/null and b/link/controller/root.cpp.o differ diff --git a/link/library_options.txt b/link/library_options.txt new file mode 100644 index 0000000..9ab6786 --- /dev/null +++ b/link/library_options.txt @@ -0,0 +1,2 @@ + +-lX11 diff --git a/link/main.cpp.o b/link/main.cpp.o new file mode 100644 index 0000000..bf7546a Binary files /dev/null and b/link/main.cpp.o differ diff --git a/link/project_files.txt b/link/project_files.txt new file mode 100644 index 0000000..53ecc27 --- /dev/null +++ b/link/project_files.txt @@ -0,0 +1,3 @@ + +/home/cogentleman/main/art/cpp_launchpad/command/linux/../.././link/main.cpp.o +/home/cogentleman/main/art/cpp_launchpad/command/linux/../.././link/controller/root.cpp.o