Adding outdated source code into master

This commit is contained in:
IlushaShurupov 2023-08-20 11:27:47 +03:00
parent 5cf467a421
commit 2810e06b3e
27 changed files with 6854 additions and 0 deletions

View file

@ -0,0 +1,19 @@
#pragma once
#include "env.h"
#ifdef ENV_OS_ANDROID
#include <EGL/egl.h>
#include <GLES3/gl32.h>
#else
#include "GL/glew.h"
#endif
#ifdef ENV_OS_ANDROID
#define GLW_CONTEXT_DEPTH_BITS 16
#define GLW_CONTEXT_DEPTH_COMPONENT GL_DEPTH_COMPONENT16
#else
#define GLW_CONTEXT_DEPTH_BITS 32
#define GLW_CONTEXT_DEPTH_COMPONENT GL_DEPTH_COMPONENT32
#endif

View file

@ -0,0 +1,53 @@
#pragma once
#include "rect.h"
#include "color.h"
namespace tp {
namespace glw {
extern bool gInTransition;
struct AnimValue {
halnf mValPrev = 0;
halnf mVal = 0;
time_ms mTimeStart = 0;
halni mTimeAnim = 250;
halnf interpolate() const;
AnimValue();
AnimValue(halnf val);
halnf prev() { return mValPrev; }
void set(halnf val);
void setNoTransition(halnf);
void setAnimTime(halni time);
halnf get() const;
halnf getTarget() const;
bool inTransition() const;
explicit operator halnf() const;
void operator=(halnf val);
};
struct AnimRect : rect<AnimValue> {
AnimRect() {
set({ 0, 0, 0, 0 });
setAnimTime(450);
}
rectf get() const;
rectf getTarget() const;
void setNoTransition(rectf);
void set(const rectf&);
void setAnimTime(halni time_ms);
};
struct AnimColor {
AnimRect mColor;
rgba get() const;
void set(const rgba&);
};
};
};

View file

@ -0,0 +1,84 @@
#pragma once
#include "stringt.h"
#include "fbuffer.h"
namespace tp {
namespace glw {
class Canvas {
typedef rectf Rect;
typedef vec2f Vec2;
typedef rgba Col;
typedef tp::halnf Val;
Col mColorPrimary;
Col mColorSecondary;
void* mCtx = NULL;
tp::halnf mDpmm = 1;
tp::halnf mUIScale = 1;
public:
Rect mClamping;
Rect mVieport;
enum Align : uint4 {
LEFT = 1 << 0, // Default, horizontally to left.
CENTER = 1 << 1, // horizontally to center.
RIGHT = 1 << 2, // horizontally to right.
TOP = 1 << 3, // vertically to top.
MIDDLE = 1 << 4, // vertically to middle.
BOTTOM = 1 << 5, // vertically to bottom.
BASELINE = 1 << 6, // Default, vertically to baseline.
CENTER_MIDDLE = CENTER | MIDDLE,
LEFT_MIDDLE = LEFT | MIDDLE,
};
Canvas();
Val& convert2pxls(Val&);
Rect& convert2pxls(Rect&);
Vec2& convert2pxls(Vec2&);
Val as2pxls(Val);
// Canvas Manipulation
void beginDraw(Rect viewport, tp::halnf dpmm, tp::halnf uiscale);
void clear(Col color = 0);
void endDraw();
void setClamping(Rect rec);
void resetViewport();
// Params control
void setCol1(const Col& col);
void setCol2(const Col& col);
// Shapes
void rect(Rect rec, halnf rounding = 0, halnf borders = 0);
void circle(Vec2 rec, halnf radius, halnf borders = 0);
void trig(Vec2 p1, Vec2 p2, Vec2 p3);
void line(Vec2 p1, Vec2 p2, halnf thikness = 2);
// Text
void text(const string text, Rect rec, halnf size, Align align = Align::CENTER_MIDDLE);
void text(const char* start, const char* end, Rect rec, halnf size, Align align = Align::CENTER_MIDDLE);
void drawColorwheel(Rect rec, const rgb& col);
// image
struct ImageHandle {
halni mId = NULL;
void createFromBuff(glw::fbuffer* buff, Canvas* drawer);
void free(Canvas* drawer);
~ImageHandle();
};
void drawImage(Rect rec, ImageHandle* image, halnf angle = 0.f, halnf alpha = 1.f, halnf rounding = 0.f);
~Canvas();
};
};
};

View file

@ -0,0 +1,48 @@
#include "window.h"
namespace ImGui {
bool SubMenuBegin(const char* desc, int level);
void SubMenuEnd(int level);
void ToolTip(const char* desc);
struct PopupData {
bool opened = false;
bool ishovered = false;
tp::vec2f p1 = 0;
tp::vec2f p2 = 0;
operator bool() {
return opened;
}
};
PopupData HoverPopupBeginButton(const char* id, tp::vec2f butsize = 200, tp::vec2f popupsize = 200);
PopupData HoverPopupBegin(const char* id, tp::vec2f size = 200, tp::vec2f pos = -1, int flags = 0);
void HoverPopupEnd(PopupData& in);
void ApplyStyle(tp::halnf dpmm, float font_size_mm = 5, float ui_scale = 1);
};
namespace tp {
namespace glw {
typedef void (DebugUiDrawCallBack)(void* cd);
struct DebugUI {
tp::halnf mDPMM = 1;
tp::halnf mFontSizeMM = 3;
tp::halnf mUIScale = 1;
DebugUiDrawCallBack* cb = NULL;
void* cd = NULL;
struct DebugUiInternalContext* mCtx = NULL;
DebugUI(Window& window, DebugUiDrawCallBack* acb, void* acd);
void drawDebugUI(tp::halnf dpmm);
~DebugUI();
};
};
};

View file

@ -0,0 +1,40 @@
#pragma once
#include "rect.h"
#include "color.h"
namespace tp {
namespace glw {
class fbuffer {
uint4 mFrameBufferID = 0; // regroups 0, 1, or more textures, and 0 or 1 depth buffer.
uint4 mTextureId = 0; // texture we're going to render to ( colour attachement #0 )
uint4 mDepthBufferID = 0;
uint4 mDrawBuffers[1];
vec2f mSize;
public:
rgba mClearCol = 0.f;
fbuffer(const vec2f& size);
fbuffer(const vec2f& size, tp::uint1 samples);
void beginDraw();
void setViewport(const rectf& viewport);
void clear();
void endDraw();
uint4 texId() const;
uint4 buffId() const;
const vec2f& getSize() const;
uhalni sizeAllocatedMem() const;
uhalni sizeUsedMem() const;
~fbuffer();
};
};
};

View file

@ -0,0 +1,167 @@
#pragma once
namespace tp {
// basically copy of glfw keys
enum class Keycode {
/* Printable keys */
SPACE = 32,
APOSTROPHE = 39, /* ' */
COMMA = 44, /* , */
MINUS = 45, /* - */
PERIOD = 46, /* . */
SLASH = 0xBF, /* \ */
N0 = 48,
N1 = 49,
N2 = 50,
N3 = 51,
N4 = 52,
N5 = 53,
N6 = 54,
N7 = 55,
N8 = 56,
N9 = 57,
SEMICOLON = 59, /* ; */
EQUAL = 61, /* = */
A = 65,
B = 66,
C = 67,
D = 68,
E = 69,
F = 70,
G = 71,
H = 72,
I = 73,
J = 74,
K = 75,
L = 76,
M = 77,
N = 78,
O = 79,
P = 80,
Q = 81,
R = 82,
S = 83,
T = 84,
U = 85,
V = 86,
W = 87,
X = 88,
Y = 89,
Z = 90,
LEFT_BRACKET = 91, /* [ */
BACKSLASH = 92, /* \ */
RIGHT_BRACKET = 93, /* ] */
GRAVE_ACCENT = 96, /* ` */
WORLD_1 = 161, /* non-US #1 */
WORLD_2 = 162, /* non-US #2 */
/* function keys */
ESCAPE = 256,
ENTER = 257,
TAB = 258,
BACKSPACE = 259,
INSERT = 260,
DELETE = 261,
RIGHT = 262,
LEFT = 263,
DOWN = 264,
UP = 265,
PAGE_UP = 266,
PAGE_DOWN = 267,
HOME = 268,
END = 269,
CAPS_LOCK = 280,
SCROLL_LOCK = 281,
NUM_LOCK = 282,
PRINT_SCREEN = 283,
PAUSE = 284,
F1 = 290,
F2 = 291,
F3 = 292,
F4 = 293,
F5 = 294,
F6 = 295,
F7 = 296,
F8 = 297,
F9 = 298,
F10 = 299,
F11 = 300,
F12 = 301,
F13 = 302,
F14 = 303,
F15 = 304,
F16 = 305,
F17 = 306,
F18 = 307,
F19 = 308,
F20 = 309,
F21 = 310,
F22 = 311,
F23 = 312,
F24 = 313,
F25 = 314,
KP_0 = 320,
KP_1 = 321,
KP_2 = 322,
KP_3 = 323,
KP_4 = 324,
KP_5 = 325,
KP_6 = 326,
KP_7 = 327,
KP_8 = 328,
KP_9 = 329,
KP_DECIMAL = 330,
KP_DIVIDE = 331,
KP_MULTIPLY = 332,
KP_SUBTRACT = 333,
KP_ADD = 334,
KP_ENTER = 335,
KP_EQUAL = 336,
LEFT_SHIFT = 340,
LEFT_CONTROL = 341,
LEFT_ALT = 342,
LEFT_SUPER = 343,
RIGHT_SHIFT = 344,
RIGHT_CONTROL = 345,
RIGHT_ALT = 346,
RIGHT_SUPER = 347,
MENU = 348,
INV_SLASH = 0xDC,
BRA = 0xDB,
KET = 0xDD,
TILDA = 0xC0,
DOUBLE_DOT = 0xBA,
QUOTES = 0xDE,
MOUSE1 = 501,
MOUSE2 = 502,
MOUSE3 = 503,
MOUSE4 = 504,
MOUSE5 = 505,
MOUSE_UP = 506,
MOUSE_DOWN = 507,
};
enum class Keystate {
PRESSED,
RELEASED,
HOLD,
REPEAT,
NONE,
};
struct KeyEvent {
Keycode code;
enum class EventState {
RELEASED = 0,
PRESSED = 1,
REPEAT = 2,
} event_state;
};
};

View file

@ -0,0 +1,36 @@
#pragma once
namespace tp {
namespace glw {
class shader {
uint4 programm;
uint4 VertexShaderID;
uint4 FragmentShaderID;
uint4 GeometryShaderID;
public:
bool compile_shader(const char* ShaderCode, uint4 ShaderID);
void load(const char* vert, const char* geom, const char* frag, bool paths);
shader();
void vert_bind_source(const char* vert_src);
void frag_bind_source(const char* frag_src);
void geom_bind_source(const char* geom_src);
void compile();
shader(const char* vertid, const char* geomid, const char* fragid, bool paths = true);
void bind();
uint4 getu(const char* uid);
void unbind();
~shader();
alni sizeAllocatedMem();
alni sizeUsedMem();
};
};
};

View file

@ -0,0 +1,71 @@
#pragma once
#include "window.h"
#include "canvas.h"
#include "animations.h"
namespace tp {
namespace glw {
class WindowSimpleInputs {
enum class Mouse : uint1 { NONE, PRESSED, HOLD, RELEASED } mMouse;
enum class Move : uint1 { NONE, LEFT, RIGHT, UP, DOWN } mMove;
public:
halnf mScaleVal = 0;
vec2f mWindowSizeMM;
vec2f mCrs;
vec2f mCrsPrev;
vec2f mCrsmDelta;
halnf mPressure = 0.f;
void update(const glw::Window& window, halnf uiscale);
bool Activated();
bool Anticipating();
bool Selected();
bool MoveLeft();
bool MoveRight();
bool MoveUp();
bool MoveDown();
bool Drag();
};
struct ButtonWidget {
rectf mRect = { 0.f, 10.f };
rgba mCol = { 0.3f, 0.3f, 0.3f, 1.f };
bool mPressed = false;
AnimRect mAnimRec;
void draw(glw::Canvas& canvas);
void proc(glw::WindowSimpleInputs& inputs);
};
struct CheckBoxWidget {
rectf mRect = { 0.f, 10.f };
rgba mCol = { 0.3f, 0.3f, 0.3f, 1.f };
rgba mColActive = { 0.5f, 0.5f, 0.5f, 1.f };
bool mValue = false;
AnimRect mAnimRec;
AnimColor mAnimCol;
void draw(glw::Canvas& canvas);
void proc(glw::WindowSimpleInputs& inputs);
};
struct WindowsHeaderWidget {
rectf header_rec = { 10, 10, 50, 10 };
rgba col = { 0.13f, 0.13f, 0.13f, 0.9f };
rectf grab_rec = 0.f;
ButtonWidget mExitButton;
ButtonWidget mMaxButton;
ButtonWidget mMinButton;
CheckBoxWidget mPinButton;
void updRecs();
void draw(glw::Canvas& canvas);
void proc(glw::Window& window, glw::WindowSimpleInputs& inputs);
};
};
};

View file

@ -0,0 +1,31 @@
#pragma once
#include "array2d.h"
#include "color.h"
#include "vec.h"
namespace tp {
namespace glw {
class texture {
uint4 id;
public:
texture();
~texture();
uint4 getid();
void update(const Array2D<rgba>& buff);
void draw(const uint4& out = 0);
alni sizeAllocatedMem();
alni sizeUsedMem();
static void init();
static void deinit();
static void draw_texture(uint4 out, uint4 in);
static uint4 get_tex(const char* TexId);
static void drawCurcle(vec2f pos, double radius, rgba col);
};
};
};

View file

@ -0,0 +1,114 @@
#pragma once
#include "common.h"
#include "vec.h"
#include "rect.h"
#include "color.h"
#include "stringt.h"
#include "array.h"
#include "map.h"
#include "keycodes.h"
#include "queue.h"
namespace tp {
extern tp::ModuleManifest gModuleGlw;
namespace glw {
struct PlatformContext;
class Window {
public:
struct Device {
time_ms FrameRate = NULL; // monitor fps
vec2f Size; // size of the monitor
tp::halnf mDPMM = 1;
};
struct Events {
tp::Queue<KeyEvent> mKeysQueue;
tp::uhalni mRedraw = 2;
bool mClose = false;
vec2f mCursor = 0;
halnf mPressure = 1.f;
vec2f mCursorPrev = 0.f;
halnf mPressurePrev = 1.f;
};
struct Appearence {
vec2f mPos = { 100.f, 100.f }; // global position
vec2f mSize = { 300.f, 300.f }; // width and height of window
vec2f mSizeMin = { 100.f, 100.f }; // min size possiable
vec2f mSizeMax = { 700.f, 700.f }; // max size possiable
bool mHiden = true;
bool mMaximized = false;
bool mMinimized = false;
bool mTopZ = false;
bool mAllDesktops = false;
rgba mResizeColor = rgba(0.13f, 0.13f, 0.13f, 0.9f);
rectf mMinMaxBox;
tp::Array<rectf> mCaptionsAddArea;
tp::Array<rectf> mCaptionsRemoveArea;
};
public:
PlatformContext* mPlatformCtx = NULL;
void platformCallback();
void* platform_window() const;
struct NativeEventListenerCallback {
typedef void (call_back_func)(PlatformContext* ctx, void* cd);
call_back_func* exec_begin = NULL;
call_back_func* exec = NULL;
call_back_func* exec_end = NULL;
void* cd = NULL;
};
tp::HashMap<NativeEventListenerCallback, string> mNativeEventListeners;
private:
struct Cache {
Appearence mAppearencePrev;
vec2f mWindowSize = 0;
rectf mRectBeforResizing = 0;
bool mUserResizing = false;
bool mMinMaxHover = false;
bool mMouseTracked = false;
} mCache;
void applyAppearance();
void initialize();
public:
static Device mDevice;
Appearence mAppearence;
Events mEvents;
Window();
Window(const Appearence& aAppearence);
void pollEvents();
void beginDraw();
void endDraw();
alni sizeAllocatedMem();
alni sizeUsedMem();
~Window();
};
};
};