Skip to content

Commit

Permalink
new way to handle window and events
Browse files Browse the repository at this point in the history
documentation category dropdowns now work
  • Loading branch information
durkisneer1 committed Dec 4, 2024
1 parent 6e0286a commit acab7a3
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 503 deletions.
6 changes: 0 additions & 6 deletions docs/_static/css/algolia.css

This file was deleted.

5 changes: 0 additions & 5 deletions docs/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -1905,8 +1905,3 @@ p + .classref-constant {
padding: 3px 5px;
}
}

/* Giscus */
#godot-giscus {
margin-bottom: 1em;
}
434 changes: 21 additions & 413 deletions docs/_static/js/custom.js

Large diffs are not rendered by default.

49 changes: 20 additions & 29 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
import subprocess

breathe_projects = {'KrakenEngine': 'xml'}
breathe_default_project = 'KrakenEngine'
breathe_projects = {"KrakenEngine": "xml"}
breathe_default_project = "KrakenEngine"

needs_sphinx = "7.1"

extensions = [
'breathe',
'sphinx.ext.autosectionlabel',
'notfound.extension',
"breathe",
"sphinx.ext.autosectionlabel",
"notfound.extension",
]

notfound_context = {
Expand All @@ -35,22 +35,22 @@

on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if on_rtd:
subprocess.call('doxygen', shell=True)
subprocess.call("doxygen", shell=True)
else:
notfound_urls_prefix = ''

templates_path = ["_templates"]

source_suffix = '.rst'
source_suffix = ".rst"
source_encoding = "utf-8-sig"

master_doc = 'index'
master_doc = "index"

project = 'Kraken Engine'
copyright = '2024, Derrick Martinez'
author = 'Derrick Martinez'
project = "Kraken Engine"
copyright = "2024, Derrick Martinez"
author = "Derrick Martinez"

version = os.getenv("READTHEDOCS_VERSION", "0.0.3")
version = os.getenv("READTHEDOCS_VERSION", "0.0.6")
release = version

exclude_patterns = ["_build"]
Expand All @@ -66,7 +66,6 @@
html_theme_options = {
"logo_only": True,
"collapse_navigation": False,
"display_version": False,
}

html_title = f"Kraken Engine ({version}) documentation in English"
Expand All @@ -75,33 +74,25 @@
"display_github": True, # Integrate GitHub
"github_user": "durkisneer1", # Username
"github_repo": "Kraken-Engine", # Repo name
"github_version": "0.0.3", # Version
"conf_py_path": "/", # Path in the checkout to the docs root
"github_version": "main", # Version
"conf_py_path": "/docs/", # Path in the checkout to the docs root
"kraken_docs_title": html_title,
"kraken_docs_basepath": "https://kraken-engine.readthedocs.io/",
"kraken_docs_suffix": ".html",
"kraken_default_lang": "en",
"kraken_canonical_version": "stable",
# Set this to `True` when in the `latest` branch to clearly indicate to the reader
# that they are not reading the `stable` documentation.
"kraken_is_latest": False,
"kraken_version": "0.0.3",
"kraken_is_latest": True,
"kraken_version": "0.0.6",
# Enables a banner that displays the up-to-date status of each article.
"kraken_show_article_status": True,
}

html_logo = "_static/kraken-engine-banner.png"
html_static_path = ['_static']

html_css_files = [
'css/algolia.css',
'https://cdn.jsdelivr.net/npm/@docsearch/css@3',
"css/custom.css",
]

html_js_files = [
"js/custom.js",
]
html_static_path = ["_static"]
html_css_files = ["css/custom.css"]
html_js_files = ["js/custom.js"]

file_insertion_enabled = False

Expand All @@ -110,4 +101,4 @@

gettext_compact = False

epub_tocscope = 'includehidden'
epub_tocscope = "includehidden"
17 changes: 7 additions & 10 deletions docs/getting_started/create_window.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Creating a Window
=================

After following the :doc:`installation` guide, you are ready for your first Kraken Engine program.
The following code creates a window and keeps it open until the user closes it.

.. code-block:: c++
:linenos:
Expand All @@ -11,21 +12,17 @@ After following the :doc:`installation` guide, you are ready for your first Krak
int main()
{
kn::window::init({800, 600});
kn::time::Clock clock;

bool done = false;
while (!done)
kn::Event event;
while (kn::window::isOpen())
{
clock.tick();
kn::window::pollEvent(event);
if (event.type == kn::QUIT)
kn::window::close();

for (const auto &event : kn::window::getEvents())
if (event.type == kn::QUIT)
done = true;

kn::window::clear();
kn::window::flip();
}

kn::window::quit();

return EXIT_SUCCESS;
}
20 changes: 18 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,40 @@ We look forward to seeing the incredible games you create with the Kraken Engine
.. toctree::
:hidden:
:maxdepth: 1
:caption: Getting Started

getting_started/installation
getting_started/create_window

.. toctree::
:hidden:
:maxdepth: 1
:caption: Manual

tutorials/index

.. toctree::
:hidden:
:maxdepth: 1
:caption: Contributing

contributing/how_to_contribute

.. toctree::
:hidden:
:maxdepth: 1

reference/index
:caption: API Reference

reference/animation_controller
reference/font
reference/rect
reference/sound
reference/texture
reference/tile_map
reference/constants
reference/draw
reference/input
reference/math
reference/music
reference/time
reference/window
5 changes: 4 additions & 1 deletion docs/reference/animation_controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ What the AnimationController class does **NOT** do is provide a draw function.
This design decision is to give users the flexibility to draw the current frame in a desired position and size.

Usage
-------------
-----

.. code-block:: cpp
Expand All @@ -33,5 +33,8 @@ Usage
// Draw the current frame texture at position (50, 50) and size (16, 16).
kn::window::blit(*frame.tex, {50, 50, 16, 16}, frame.rect);
Members
-------

.. doxygenclass:: kn::AnimationController
:members:
3 changes: 3 additions & 0 deletions docs/reference/font.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ Usage
// Draw the text texture at position (50, 50).
kn::window::blit(text, {50, 50});
Members
-------

.. doxygenclass:: kn::Font
:members:
20 changes: 0 additions & 20 deletions docs/reference/index.rst

This file was deleted.

3 changes: 3 additions & 0 deletions docs/reference/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Usage
kn::math::Vec2 inputDir = kn::input::getVector(left, right, up, down);
Functions
---------

.. doxygenfunction:: kn::input::getMousePos

.. doxygenfunction:: kn::input::isMouseButtonPressed
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/music.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Usage
// Fade out the music over 2 seconds.
kn::music::fadeOut(2000);
Functions
---------

.. doxygenfunction:: kn::music::load

.. doxygenfunction:: kn::music::unload
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/sound.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ Usage
// Play the sound 3 times after it fades in over 2 seconds.
sound.play(2, -1, 2000);
Members
-------

.. doxygenclass:: kn::Sound
:members:
2 changes: 2 additions & 0 deletions docs/reference/texture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Usage
kn::window::blit(imageTexture, {50, 50});
kn::window::blit(colorTexture, {100, 100});
Members
-------

.. doxygenclass:: kn::Texture
:members:
3 changes: 3 additions & 0 deletions docs/reference/tile_map.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Usage
tileMap.drawMap();
tileMap.drawLayer("walls");
Members
-------

.. doxygenstruct:: kn::Tile
:members:
:undoc-members:
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ Usage
// Get the time since Kraken was initialized.
double elapsedTime = kn::time::getTicks();
Members
-------

.. doxygenclass:: kn::time::Clock
:members:

Functions
---------

.. doxygenfunction:: kn::time::getTicks
15 changes: 9 additions & 6 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ int main()

Player player(tileMap);

bool done = false;
while (!done)
kn::Event event;
while (kn::window::isOpen())
{
const double dt = clock.tick();

for (const auto& event : kn::window::getEvents())
if (event.type == kn::QUIT ||
(event.type == kn::KEYDOWN && event.key.keysym.sym == kn::K_ESCAPE))
done = true;
kn::window::pollEvent(event);
if (event.type == kn::QUIT ||
(event.type == kn::KEYDOWN && event.key.keysym.sym == kn::K_ESCAPE))
kn::window::close();
if (event.type == kn::MOUSEMOTION)
if (event.type == kn::MOUSEBUTTONDOWN)
std::cout << "yes\n";

kn::window::clear({21, 18, 37});

Expand Down
18 changes: 15 additions & 3 deletions include/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ namespace window
*/
void init(const math::Vec2& resolution, const std::string& title = "Kraken Window", int scale = 1);

/**
* @brief Get whether the window is open.
*
* @return Whether the window is open.
*/
bool isOpen();

/**
* @brief Close the window.
*/
void close();

/**
* @brief Clear the screen.
*
Expand Down Expand Up @@ -66,11 +78,11 @@ void blit(const Texture& texture, const math::Vec2& position = {});
SDL_Renderer* getRenderer();

/**
* @brief Get user events.
* @brief Populate an event with the next window events.
*
* @return The user events.
* @param event The event to poll.
*/
const std::vector<Event>& getEvents();
void pollEvent(Event& event);

/**
* @brief Get whether the window is fullscreen or not.
Expand Down
Loading

0 comments on commit acab7a3

Please sign in to comment.