switching to cmake; alyson setup
This commit is contained in:
parent
9504620227
commit
23a40216de
20 changed files with 307 additions and 125300 deletions
27
alyson/CMakeLists.txt
Normal file
27
alyson/CMakeLists.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
project(alyson
|
||||
VERSION 0.0.1
|
||||
LANGUAGES C CXX
|
||||
)
|
||||
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
include(../cmake/utils.cmake)
|
||||
|
||||
add_library(alyson)
|
||||
target_include_directories(alyson PUBLIC includes)
|
||||
|
||||
target_link_libraries(alyson PUBLIC raylib)
|
||||
target_link_libraries(alyson PUBLIC flecs::flecs_static)
|
||||
|
||||
target_compile_definitions(alyson PRIVATE ASSETS_PATH="${ASSETS_PATH}")
|
||||
|
||||
# Add alyson files
|
||||
find_files(alyson_src src cpp hpp cxx hxx c h)
|
||||
target_sources(alyson PRIVATE ${alyson_src})
|
||||
|
||||
# set(ALYSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/alyson/include)
|
||||
|
17
alyson/includes/alyson.hpp
Normal file
17
alyson/includes/alyson.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
#ifndef ALYSON_HPP
|
||||
#define ALYSON_HPP
|
||||
|
||||
#ifndef ASSETS_PATH
|
||||
#define ASSETS_PATH "./assets/"
|
||||
#endif
|
||||
|
||||
#define MANGLE_RES_PATH(path) ASSETS_PATH "/" path
|
||||
|
||||
int init();
|
||||
|
||||
void update(float dt);
|
||||
|
||||
void render(float dt);
|
||||
|
||||
#endif // ALYSON_HPP
|
42
alyson/includes/rlyson.h
Normal file
42
alyson/includes/rlyson.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#ifndef RLYSON_HPP
|
||||
#define RLYSON_HPP
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
|
||||
/*
|
||||
the following functions are not part of the raylib API,
|
||||
but are used by alyson and can be used by other projects using alyson
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
TEXT_ORIENTATION_LEFT,
|
||||
TEXT_ORIENTATION_RIGHT,
|
||||
TEXT_ORIENTATION_CENTER
|
||||
} text_orientation_t;
|
||||
|
||||
/*
|
||||
* Draws a text with all possible parameters
|
||||
* @function DrawTextFull
|
||||
* @param font Font to use
|
||||
* @param text Text to draw
|
||||
* @param origin Position to draw the text from
|
||||
* @param orientation Text orientation
|
||||
* @param fontSize Font size
|
||||
* @param spacing Spacing between letters
|
||||
* @param lineSpacing Line spacing
|
||||
* @param tint Tint of the text
|
||||
*/
|
||||
void DrawTextFull(
|
||||
Font font,
|
||||
const char *text,
|
||||
Vector2 origin,
|
||||
text_orientation_t orientation,
|
||||
float fontSize,
|
||||
float spacing,
|
||||
float lineSpacing,
|
||||
Color tint
|
||||
);
|
||||
|
||||
|
||||
#endif // RLYSON_HPP
|
43
alyson/src/alyson.cpp
Normal file
43
alyson/src/alyson.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
|
||||
#include <alyson.hpp>
|
||||
#include <raylib.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <rlyson.h>
|
||||
|
||||
#define WINDOW_TITLE "Alyson Engine"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
InitWindow(900, 500, WINDOW_TITLE " -- 900x500");
|
||||
|
||||
|
||||
Texture2D logo = LoadTexture(MANGLE_RES_PATH("Raylib_logo.png"));
|
||||
|
||||
std::cout << "alyson: init" << std::endl;
|
||||
|
||||
int g = init();
|
||||
if(g != 0) {
|
||||
std::cout << "alyson: init failed with error code " << g << std::endl;
|
||||
return g;
|
||||
}
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
if (IsWindowResized()) {
|
||||
SetWindowTitle((std::string(WINDOW_TITLE) + " -- " + std::to_string(GetScreenWidth()) + "x" + std::to_string(GetScreenHeight())).c_str());
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
DrawTexture(logo, GetScreenWidth() / 2 - logo.width / 2, GetScreenHeight() / 2 - logo.height / 2, WHITE);
|
||||
DrawTextFull(GetFontDefault(), WINDOW_TITLE, { GetScreenWidth() / 2.f, GetScreenHeight() - 60.f }, TEXT_ORIENTATION_CENTER, 40.f, 0.f, 0.f, WHITE);
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
UnloadTexture(logo);
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
28
alyson/src/rlyson.c
Normal file
28
alyson/src/rlyson.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <rlyson.h>
|
||||
|
||||
void DrawTextFull(
|
||||
Font font,
|
||||
const char *text,
|
||||
Vector2 origin,
|
||||
text_orientation_t orientation,
|
||||
float fontSize,
|
||||
float spacing,
|
||||
float lineSpacing,
|
||||
Color tint
|
||||
)
|
||||
{
|
||||
Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing);
|
||||
|
||||
switch (orientation) {
|
||||
case TEXT_ORIENTATION_LEFT:
|
||||
origin.x -= textSize.x;
|
||||
break;
|
||||
case TEXT_ORIENTATION_RIGHT:
|
||||
origin.x += textSize.x;
|
||||
break;
|
||||
case TEXT_ORIENTATION_CENTER:
|
||||
origin.x -= textSize.x / 2;
|
||||
break;
|
||||
}
|
||||
DrawTextPro(font, text, textSize, origin, 0, spacing, lineSpacing, tint);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue