From a61916206c710e85b277fbc952e7f4b9d0075c88 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Wed, 11 Oct 2023 14:50:35 -0700 Subject: [PATCH] import kepp, clean up build dependencies --- .gitignore | 6 +- Buffer.cc | 78 ++++++++++++++++ Buffer.h | 56 ++++++++++++ CMakeLists.txt | 148 ++++++++++++++++--------------- Cursor.cc | 102 +++++++++++++++++++++ Cursor.h | 56 ++++++++++++ Defs.cc | 24 +++++ Defs.h | 42 +++++++++ File.cc | 43 +++++++++ File.h | 63 +++++++++++++ Makefile | 11 ++- kge.cc => gmain.cc | 0 imgui.cmake | 39 ++++++++ install-cmake-debian.sh | 41 +++++++++ install-depdendencies.sh | 4 + ke.md | 14 +++ main.cc | 63 +++++++++++++ CMakePack.txt => packaging.cmake | 9 +- 18 files changed, 718 insertions(+), 81 deletions(-) create mode 100644 Buffer.cc create mode 100644 Buffer.h create mode 100644 Cursor.cc create mode 100644 Cursor.h create mode 100644 Defs.cc create mode 100644 Defs.h create mode 100644 File.cc create mode 100644 File.h rename kge.cc => gmain.cc (100%) create mode 100644 imgui.cmake create mode 100644 install-cmake-debian.sh create mode 100644 install-depdendencies.sh create mode 100644 ke.md create mode 100644 main.cc rename CMakePack.txt => packaging.cmake (84%) diff --git a/.gitignore b/.gitignore index b34b1e7..04fa645 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.cmake .idea .trunk .vc @@ -12,6 +13,5 @@ core core.* cmake-build-* -bufferTest -dictionaryTest -tlvTest +ke +kge diff --git a/Buffer.cc b/Buffer.cc new file mode 100644 index 0000000..8c0e03a --- /dev/null +++ b/Buffer.cc @@ -0,0 +1,78 @@ +/// +/// \file Buffer.cc +/// \author kyle +/// \created 10/10/23 +/// \brief Buffer implementation. +/// +/// \section COPYRIGHT +/// Copyright 2023 K. Isom +/// +/// Permission to use, copy, modify, and/or distribute this software for +/// any purpose with or without fee is hereby granted, provided that the +/// above copyright notice and this permission notice appear in all copies. +/// +/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +/// BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +/// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +/// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +/// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +/// SOFTWARE. +/// +/// @\section DESCRIPTION + + +#include +#include +#include + +#include "Buffer.h" + + +static std::string +anonymousName() +{ + std::uniform_int_distribution<> dist(1000, 9999); + std::random_device randomDevice; + std::mt19937 rng(randomDevice()); + std::stringstream ss; + + ss << "Buffer<" << dist(rng) << ">"; + return ss.str(); +} + + +Buffer::Buffer() + : name(anonymousName()), path(std::nullopt), file(std::nullopt) +{ +} + + +Buffer::Buffer(std::string fName) + : name(std::move(fName)), path(std::nullopt), file(std::nullopt) +{ + +} + + +Buffer::Buffer(std::string fName, std::string fPath) +: name(std::move(fName)), path(std::move(fPath)), file(std::nullopt) +{ + if (this->path) { + this->file = OptFile(File(this->path.value())); + } + +} + + +int Buffer::Flush(OptString altPath) +{ + return altPath ? 0 : 1; +} + + +void Buffer::ChangePath(std::string newPath) +{ + this->path = OptString(std::move(newPath)); +} diff --git a/Buffer.h b/Buffer.h new file mode 100644 index 0000000..bb6a6d0 --- /dev/null +++ b/Buffer.h @@ -0,0 +1,56 @@ +/// +/// \file Buffer.h +/// \author kyle +/// \date 2023-10-10 +/// \brief A buffer is the basic document type. +/// + +#ifndef KEPP_FRAME_H +#define KEPP_FRAME_H + + +#include "Defs.h" +#include "File.h" + + +typedef std::vector> BufferContents; + + +/// A Buffer is the atom of text editing. It represents a single document, +/// whether a memory-only buffer or a file-backed buffer. +/// +/// \details +/// +/// There are currently two main types of Buffers: file-backed and virtual. +/// A virtual buffer describes any buffer that isn't backed by a file. +/// +/// A virtual buffer can be promoted to a file frame, but a file buffer +/// cannot be demoted to a virtual buffer. +class Buffer { +public: + /// The constructor with no arguments generates a new anonymous + /// buffer. + Buffer(); + + /// A single constructor generates a virtual buffer. + Buffer(std::string fName); + + /// Instantiate a Buffer pointing to fPath. + Buffer(std::string fName, std::string fPath); + + std::string Name() const { return this->name; } + + int Flush(OptString altPath); + void ChangePath(std::string newPath); + + +private: + std::string name; + OptString path; + OptFile file; + BufferContents contents; +}; + + +#endif // KEPP_FRAME_H + diff --git a/CMakeLists.txt b/CMakeLists.txt index c222238..7d1b0e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,34 +1,32 @@ cmake_minimum_required(VERSION 3.22) -project(kge LANGUAGES CXX VERSION 0.0.1) +project(kge + DESCRIPTION "kyle's editor" + LANGUAGES CXX + VERSION 0.0.1) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) + string(TIMESTAMP TODAY "%Y%m%d") -include(FetchContent) -FetchContent_Declare( - klib - GIT_REPOSITORY https://git.wntrmute.dev/kyle/klib - GIT_TAG master - FIND_PACKAGE_ARGS NAMES klib -) -FetchContent_MakeAvailable(klib) +#################### +### BUILD CONFIG ### +#################### -find_package(SDL2 REQUIRED) -find_package(OpenGL REQUIRED) -find_package(klib REQUIRED) -find_package(Freetype) -if (DEFINED FREETYPE_INCLUDE_DIRS) - add_definitions(-DIMGUI_ENABLE_FREETYPE) - set(FREETYPE_SOURCES - ext/imgui/misc/freetype/imgui_freetype.cpp - ext/imgui/misc/freetype/imgui_freetype.h) -endif() +# in "prod", this will be ON by default; the docstring is written this +# way as I am likely to forget to change it later. +set(BUILD_GUI OFF CACHE BOOL "Disable building the graphical version.") if(MSVC) add_compile_options("/W4" "$<$:/O2>") else() - add_compile_options("-Wall" "-Wextra" "-Werror" "$<$:-O3>") + add_compile_options( + "-Wall" + "-Wextra" + "-Werror" + "-static" + "$<$:-g>" + "$<$:-O2>") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_compile_options("-stdlib=libc++") else() @@ -36,65 +34,71 @@ else() endif() endif() -add_library(imgui STATIC - # Main Imgui files - ext/imgui/imgui.cpp - ext/imgui/imgui.h - ext/imgui/imgui_draw.cpp - ext/imgui/imgui_tables.cpp - ext/imgui/imgui_widgets.cpp - ext/imgui/imgui_demo.cpp +if(${BUILD_GUI}) +include(imgui.cmake) +endif() - ext/imgui/backends/imgui_impl_sdl2.cpp - ext/imgui/backends/imgui_impl_sdl2.h - ext/imgui/backends/imgui_impl_opengl3.cpp - ext/imgui/backends/imgui_impl_opengl3.h +##################### +### BUILD TARGETS ### +##################### - $,${FREETYPE_SOURCES},>) -add_library(imgui::imgui ALIAS imgui) -target_link_libraries(imgui - PUBLIC - OpenGL::GL - $,Freetype::Freetype,> - $ - $,SDL2::SDL2,SDL2::SDL2-static>) -target_include_directories(imgui PUBLIC - ext/imgui/ - ext/imgui/backends/ - ext/imgui/misc/freetype - $,${FREETYPE_INCLUDE_DIRS},>) - -include_directories(ext/ ${SDL2_INCLUDE_DIRS} ${KLIB_INCLUDE_DIRS}) - -configure_file(kge.desktop.in kge.desktop @ONLY) -add_executable(kge - kge.cc +set(HEADER_FILES + Defs.h + Buffer.h + File.h + Cursor.h ) -target_link_libraries(kge imgui ${KLIB_LIBRARIES}) +set(SOURCE_FILES + Defs.cc + Buffer.cc + File.cc + Cursor.cc +) + +add_executable(ke main.cc ${SOURCE_FILES} ${HEADER_FILES}) add_custom_target(manpages) -configure_file(kge.md kge.1.scdoc @ONLY) -add_custom_command(TARGET manpages COMMAND scdoc < kge.1.scdoc > kge.1 - OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/kge.1) -add_dependencies(kge manpages) +configure_file(ke.md ke.1.scdoc @ONLY) +add_custom_command(TARGET manpages COMMAND scdoc < ke.1.scdoc > ke.1 + OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/ke.1) +add_dependencies(ke manpages) -install(TARGETS kge +if(${BUILD_GUI}) + configure_file(kge.desktop.in kge.desktop @ONLY) + add_executable(kge gmain.cc ${SOURCE_FILES} ${HEADER_FILES}) + target_link_libraries(kge imgui) + + configure_file(kge.md kge.1.scdoc @ONLY) + add_custom_command(TARGET manpages COMMAND scdoc < kge.1.scdoc > kge.1 + OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/kge.1) + + add_dependencies(kge manpages) +endif() + +####################### +### INSTALL TARGETS ### +####################### + +install(TARGETS ke DESTINATION bin - COMPONENT dist) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kge.desktop - DESTINATION share/applications - COMPONENT dist) -install(FILES kge.png - DESTINATION share/${PROJECT_NAME} - COMPONENT dist) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kge.1 + COMPONENT dist COMPONENT nox) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ke.1 DESTINATION share/man/man1 - COMPONENT dist) + COMPONENT dist COMPONENT nox) -include(CMakePack.txt) +if(${BUILD_GUI}) + install(TARGETS kge + DESTINATION bin + COMPONENT dist nox) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kge.desktop + DESTINATION share/applications + COMPONENT dist) + install(FILES kge.png + DESTINATION share/${PROJECT_NAME} + COMPONENT dist) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kge.1 + DESTINATION share/man/man1 + COMPONENT dist) +endif() - get_cmake_property(_variableNames VARIABLES) - list (SORT _variableNames) - foreach (_variableName ${_variableNames}) - message(STATUS "${_variableName}=${${_variableName}}") - endforeach() \ No newline at end of file +include(packaging.cmake) diff --git a/Cursor.cc b/Cursor.cc new file mode 100644 index 0000000..69e0911 --- /dev/null +++ b/Cursor.cc @@ -0,0 +1,102 @@ +/// +/// \file Cursor.cc +/// \author kyle +/// \created 10/11/23 +/// \brief +/// +/// \section COPYRIGHT +/// Copyright 2023 K. Isom +/// +/// Permission to use, copy, modify, and/or distribute this software for +/// any purpose with or without fee is hereby granted, provided that the +/// above copyright notice and this permission notice appear in all copies. +/// +/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +/// BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +/// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +/// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +/// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +/// SOFTWARE. +/// + +#include "Cursor.h" +#include "Defs.h" + + +/// \todo kyle Can cursors be replaced with std::pair? + + +static std::pair +orderedPair(size_t a, size_t b) +{ + if (a > b) { + return {b, a}; + } + + return {a, b}; +} + + +static size_t +isqrt(size_t n) +{ + if (n < 2) { + return n; + } + + size_t start = 0; + size_t end = n / 2; + size_t result = 0; + + while (start <= end) { + auto middle = (start + end) >> 1; + result = middle * middle; + if (result == n) { + return middle; + } + + if (result < n) { + start = middle + 1; + result = middle; + } else { + end = middle - 1; + result = middle; + } + } + + return result; +} + + +Cursor Cursor::Update(const Cursor &c) +{ + Cursor prev(this->x, this->y); + this->X(c.X()); + this->Y(c.Y()); + return prev; +} + + +size_t Cursor::Distance(const Cursor &c) const +{ + auto xPair = orderedPair(this->x, c.X()); + auto yPair = orderedPair(this->y, c.Y()); + + auto x0 = xPair.second - xPair.first; + x0 *= x0; + + auto y0 = yPair.second - xPair.first; + y0 *= y0; + + auto dist = x0 + y0; + return isqrt(dist); +} + + +std::ostream &operator<<(std::ostream &os, const Cursor &cursor) +{ + os << cursor.X() << "," << cursor.Y(); + return os; +} diff --git a/Cursor.h b/Cursor.h new file mode 100644 index 0000000..ba6ba25 --- /dev/null +++ b/Cursor.h @@ -0,0 +1,56 @@ +/// +/// \file Cursor.h +/// \author kyle +/// \created 10/11/23 +/// \brief Cursor describes a position in a Buffer. +/// +/// \section COPYRIGHT +/// Copyright 2023 K. Isom +/// +/// Permission to use, copy, modify, and/or distribute this software for +/// any purpose with or without fee is hereby granted, provided that the +/// above copyright notice and this permission notice appear in all copies. +/// +/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +/// BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +/// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +/// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +/// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +/// SOFTWARE. +/// + +#ifndef KEPP__CURSOR_H_ +#define KEPP__CURSOR_H_ + + +#include +#include + + +/// Cursors represent a position in a Buffer. +class Cursor { +public: + Cursor(size_t _x, size_t _y) : x(_x), y(_y) {}; + + size_t X() const { return this->x; } + size_t Y() const { return this->y; } + void X(size_t nx) { this->x = nx; } + void Y(size_t ny) { this->y = ny; } + + void Update(size_t nx, size_t ny) { this->X(nx); this->Y(ny); } + Cursor Update(const Cursor &c); + + size_t Distance(const Cursor &c) const; + +private: + size_t x; + size_t y; +}; + + +std::ostream &operator<<(std::ostream &os, const Cursor &cursor); + + +#endif // KEPP__CURSOR_H_ diff --git a/Defs.cc b/Defs.cc new file mode 100644 index 0000000..6c12fda --- /dev/null +++ b/Defs.cc @@ -0,0 +1,24 @@ +/// +/// \file Defs.cc +/// \author kyle +/// \created 10/11/23 +/// \brief +/// +/// \section COPYRIGHT +/// Copyright 2023 K. Isom +/// +/// Permission to use, copy, modify, and/or distribute this software for +/// any purpose with or without fee is hereby granted, provided that the +/// above copyright notice and this permission notice appear in all copies. +/// +/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +/// BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +/// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +/// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +/// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +/// SOFTWARE. +/// + +#include "Defs.h" diff --git a/Defs.h b/Defs.h new file mode 100644 index 0000000..db063b7 --- /dev/null +++ b/Defs.h @@ -0,0 +1,42 @@ +/// +/// \file Defs.h +/// \author kyle +/// \created 10/11/23 +/// \brief +/// +/// \section COPYRIGHT +/// Copyright 2023 K. Isom +/// +/// Permission to use, copy, modify, and/or distribute this software for +/// any purpose with or without fee is hereby granted, provided that the +/// above copyright notice and this permission notice appear in all copies. +/// +/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +/// BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +/// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +/// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +/// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +/// SOFTWARE. +/// + +#ifndef KEPP__DEFS_H_ +#define KEPP__DEFS_H_ + +#include +#include + + +typedef std::optional OptString; + +template +T Min(T a, T b) { return a > b ? b : a; } +template size_t Min(size_t a, size_t b); + +template +T Max(T a, T b) { return a > b ? a : b; } +template size_t Max(size_t a, size_t b); + + +#endif // KEPP__DEFS_H_ diff --git a/File.cc b/File.cc new file mode 100644 index 0000000..3a8c4a7 --- /dev/null +++ b/File.cc @@ -0,0 +1,43 @@ +/// +/// \file File.cc +/// \author kyle +/// \created 10/11/23 +/// \brief +/// +/// \section COPYRIGHT +/// Copyright 2023 K. Isom +/// +/// Permission to use, copy, modify, and/or distribute this software for +/// any purpose with or without fee is hereby granted, provided that the +/// above copyright notice and this permission notice appear in all copies. +/// +/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +/// BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +/// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +/// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +/// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +/// SOFTWARE. +/// + +#include "File.h" + + +const std::string &File::Path() const +{ + return path; +} + + +void File::SetPath(const std::string &fPath) +{ + File::path = fPath; +} + + +File::File(std::string fPath) + : path(fPath), readOnly(false) +{ + +} diff --git a/File.h b/File.h new file mode 100644 index 0000000..ceb9a52 --- /dev/null +++ b/File.h @@ -0,0 +1,63 @@ +/// +/// \file File.h +/// \author kyle +/// \created 10/11/23 +/// \brief File contains configuration information for a file. +/// +/// \section COPYRIGHT +/// Copyright 2023 K. Isom +/// +/// Permission to use, copy, modify, and/or distribute this software for +/// any purpose with or without fee is hereby granted, provided that the +/// above copyright notice and this permission notice appear in all copies. +/// +/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +/// BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +/// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +/// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +/// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +/// SOFTWARE. +/// + +#ifndef KEPP__FILE_H_ +#define KEPP__FILE_H_ + + +#include +#include +#include + +#include "Defs.h" + + +static constexpr std::ios::openmode DefaultMode = + std::ios::in|std::ios::out; + + +/// A File abstracts a concrete file on disk. +class File { +public: + File(std::string fPath); + + const std::string &Path() const; + void SetPath(const std::string &fPath); + + // int Refresh(std::); + + + [[nodiscard]] bool IsReadOnly() const { return this->readOnly; }; + void MarkReadOnly() { this->readOnly = true; } + void ClearReadOnly() { this->readOnly = false; } + +private: + std::string path; + bool readOnly; + std::ios::openmode mode; +}; + + +typedef std::optional OptFile; + +#endif // KEPP__FILE_H_ diff --git a/Makefile b/Makefile index 2d78d23..6d62294 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,14 @@ all: mkdir -p build && cd build && cmake .. && make -.PHONY: deps +PHONY: deps deps: - sudo apt-get install libfreetype-dev libsdl2-dev libopengl-dev + sudo apt-get install doxygen scdoc +.PHONY: gui-deps +gui-deps: + sudo apt-get install libfreetype-dev libsdl2-dev libopengl-dev libglfw3-dev + +.PHONY: +clean: + rm -r build cmake-build-* diff --git a/kge.cc b/gmain.cc similarity index 100% rename from kge.cc rename to gmain.cc diff --git a/imgui.cmake b/imgui.cmake new file mode 100644 index 0000000..de589b7 --- /dev/null +++ b/imgui.cmake @@ -0,0 +1,39 @@ +find_package(SDL2 REQUIRED) +find_package(OpenGL REQUIRED) +find_package(Freetype) +if (DEFINED FREETYPE_INCLUDE_DIRS) + add_definitions(-DIMGUI_ENABLE_FREETYPE) + set(FREETYPE_SOURCES + ext/imgui/misc/freetype/imgui_freetype.cpp + ext/imgui/misc/freetype/imgui_freetype.h) +endif() + +add_library(imgui STATIC + # Main Imgui files + ext/imgui/imgui.cpp + ext/imgui/imgui.h + ext/imgui/imgui_draw.cpp + ext/imgui/imgui_tables.cpp + ext/imgui/imgui_widgets.cpp + ext/imgui/imgui_demo.cpp + + ext/imgui/backends/imgui_impl_sdl2.cpp + ext/imgui/backends/imgui_impl_sdl2.h + ext/imgui/backends/imgui_impl_opengl3.cpp + ext/imgui/backends/imgui_impl_opengl3.h + + $,${FREETYPE_SOURCES},>) +add_library(imgui::imgui ALIAS imgui) +target_link_libraries(imgui + PUBLIC + OpenGL::GL + $,Freetype::Freetype,> + $ + $,SDL2::SDL2,SDL2::SDL2-static>) +target_include_directories(imgui PUBLIC + ext/imgui/ + ext/imgui/backends/ + ext/imgui/misc/freetype + $,${FREETYPE_INCLUDE_DIRS},>) + +include_directories(ext/ ${SDL2_INCLUDE_DIRS}) diff --git a/install-cmake-debian.sh b/install-cmake-debian.sh new file mode 100644 index 0000000..6d64b17 --- /dev/null +++ b/install-cmake-debian.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -eu + + +source /etc/lsb-release + +preinstall () { + echo "[+] preparing to install" + sudo apt-get update + sudo apt-get install ca-certificates gpg wget +} + +do_install () { +if [ ! -f /etc/apt/sources.list.d/kitware.list ] +then + echo "[+] fetching initial keyring" + wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null + + echo "[+] adding repo to sources.list.d" + echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${DISTRIB_RELEASE} main" | \ + sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null + sudo apt-get update + + echo "[+] installing kitware keyring" + if [ -f "/usr/share/keyrings/kitware-archive-keyring.gpg" ] + then + sudo rm /usr/share/keyrings/kitware-archive-keyring.gpg + fi + sudo apt-get install kitware-archive-keyring +fi + +if [ "${USE_CMAKE_RC}" = "YES" ] +then + echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${DISTRIB_RELEASE}-rc main' | \ + sudo tee -a /etc/apt/sources.list.d/kitware.list >/dev/null + sudo apt-get update +fi +} + +sudo apt-get install cmake cmake-curses-gui cmake-extras diff --git a/install-depdendencies.sh b/install-depdendencies.sh new file mode 100644 index 0000000..c0c7578 --- /dev/null +++ b/install-depdendencies.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +set -eu + diff --git a/ke.md b/ke.md new file mode 100644 index 0000000..b4af434 --- /dev/null +++ b/ke.md @@ -0,0 +1,14 @@ +ke(1) ["@TODAY@" ["Shimmering Clarity Industries"]] + +# NAME + +ke - kyle's editor + +# SYNOPSIS + +ke files... + +# AUTHORS + +Written by Kyle Isom . Up-to-date sources can be found +at https://git.wntrmute.dev/kyle/kge. \ No newline at end of file diff --git a/main.cc b/main.cc new file mode 100644 index 0000000..709aa7a --- /dev/null +++ b/main.cc @@ -0,0 +1,63 @@ +/// +/// \file main.cc +/// \author kyle +/// \date 2023-10-10 +/// \brief kyle's editor +/// +/// \section COPYRIGHT +/// Copyright 2023 K. Isom +/// +/// Permission to use, copy, modify, and/or distribute this software for +/// any purpose with or without fee is hereby granted, provided that the +/// above copyright notice and this permission notice appear in all copies. +/// +/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +/// BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +/// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +/// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +/// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +/// SOFTWARE. +/// + +#include +#include + +#include "Buffer.h" +#include "Cursor.h" + + +static void +usage(std::ostream &os, int exitCode) +{ + os << "ke - kyle's editor ++\n"; + os << "\nUsage:\n"; + os << "\tke [files]\n"; + exit(exitCode); +} + + +void +ShowDist(Cursor a, Cursor b) +{ + std::cout << a << " -> " << b << ": " << a.Distance(b) << "\n"; +} + + +int +main(int argc, char **argv) +{ + if ((argc == 2) && (std::string(argv[1]) == "-h")) { + usage(std::cout, 0); + } + + Buffer frame; + std::cout << frame.Name() << "\n"; + + ShowDist(Cursor(0, 0), Cursor(5, 5)); + ShowDist(Cursor(2, 2), Cursor(4, 4)); + ShowDist(Cursor(32, 12), Cursor(14, 71)); + + return 0; +} diff --git a/CMakePack.txt b/packaging.cmake similarity index 84% rename from CMakePack.txt rename to packaging.cmake index de33d49..baf6ae1 100644 --- a/CMakePack.txt +++ b/packaging.cmake @@ -2,22 +2,23 @@ include(InstallRequiredSystemLibraries) set(CPACK_PACKAGE_VENDOR "Shimmering Clarity") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Kyle's Graphical Editor") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "kyle's editor") set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) # Debian settings set(CPACK_DEBIAN_PACKAGE_MAINTAINER "K. Isom") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Kyle's Graphical Editor") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "kyle's editor") set(CPACK_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION}) +if(${BUILD_GUI}) set(CPACK_DEBIAN_PACKAGE_DEPENDS -# "libc++12 (>= 3.7.0-1)" "libsdl2-2.0-0, libfreetype6 (>= 2.11.1)" ) +endif() set(CPACK_DEBIAN_PACKAGE_SECTION universe/editors) set(CPACK_DEB_COMPONENT_INSTALL ON) -set(CPACK_COMPONENTS_ALL dist) +set(CPACK_COMPONENTS_ALL dist nox) set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP) if(LINUX)