formating; alyson licence; Camera2D

This commit is contained in:
n0ffie 2025-02-07 01:10:15 +01:00
parent 04d7c97e93
commit 39abfaa978
6 changed files with 85 additions and 49 deletions

View file

@ -1,4 +1,3 @@
#include <alyson.hpp>
#include <raylib.h>
#include <iostream>
@ -16,31 +15,42 @@ int main(int argc, char *argv[]) {
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;
}
Camera2D camera = { 0 };
camera.target = (Vector2){ 0, 0 };
camera.offset = (Vector2){ 0, 0 };
camera.rotation = 0.0f;
camera.zoom = 1.0f;
init(0);
while (!WindowShouldClose()) {
float dt = GetFrameTime();
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, 0.f,
40.f, 5.f,
0.f, BLACK
);
BeginMode2D(camera);
ClearBackground(RAYWHITE);
camera.rotation += dt;
camera.rotation = (int)camera.rotation % 360;
ClearBackground(RAYWHITE);
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, 0.f,
40.f, 5.f,
0.f, BLACK
);
update(dt);
render(dt);
EndMode2D();
EndDrawing();
}

View file

@ -1,46 +1,46 @@
#include <rlyson.h>
#include "raylib.h"
#include "raymath.h"
void DrawTextFull(
Font font,
const char *text,
Vector2 origin,
text_orientation_t orientation,
float rotation,
float fontSize,
float spacing,
float lineSpacing,
Color tint
)
const Font font,
const char* text,
Vector2 origin,
const text_orientation_t orientation,
const float rotation,
const float fontSize,
const float spacing,
const float lineSpacing,
const Color tint
)
{
Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing);
const Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing);
DrawCircleV(origin, 10, RED);
Vector2 pos = origin;
const Vector2 pos = origin;
origin = (Vector2){0,0};
switch (orientation) {
case TEXT_ORIENTATION_LEFT:
origin.x += textSize.x;
break;
case TEXT_ORIENTATION_RIGHT:
break;
case TEXT_ORIENTATION_CENTER:
origin.x += (textSize.x / 2);
break;
default:
break;
case TEXT_ORIENTATION_LEFT:
origin.x += textSize.x;
break;
case TEXT_ORIENTATION_RIGHT:
break;
case TEXT_ORIENTATION_CENTER:
origin.x += (textSize.x / 2);
break;
default:
break;
}
origin.y += textSize.y / 2;
DrawCircleV(Vector2Add(origin, pos), 10, DARKGREEN);
SetTextLineSpacing(lineSpacing);
SetTextLineSpacing((int)lineSpacing);
DrawTextPro(font, text, pos, origin, rotation, fontSize, spacing, tint);
}