Key event buffer overflow crash fixed; switched draw_string over to Vec2 and returning the distance measured in deltas
This commit is contained in:
parent
258257eb45
commit
410b90d44c
|
@ -11,6 +11,7 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
#include "4coder_base_types.h"
|
||||
#include "4coder_base_types.cpp"
|
||||
#include "4coder_lib/4coder_arena.h"
|
||||
#include "4coder_lib/4coder_heap.h"
|
||||
#include "4coder_lib/4coder_string.h"
|
||||
|
|
|
@ -1,23 +1,66 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 15.05.2015
|
||||
*
|
||||
* Math functions for 4coder
|
||||
*
|
||||
* 4coder base types
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
#define C_MATH 1
|
||||
|
||||
/*
|
||||
* Scalar operators
|
||||
*/
|
||||
static i32
|
||||
ceil32(f32 v){
|
||||
return(((v)>0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)+1.f)) ):( ((i32)(v)) ));
|
||||
}
|
||||
|
||||
static i32
|
||||
floor32(f32 v){
|
||||
return(((v)<0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)-1.f)) ):( ((i32)(v)) ));
|
||||
}
|
||||
|
||||
static i32
|
||||
round32(f32 v){
|
||||
return(floor32(v + 0.5f));
|
||||
}
|
||||
|
||||
static i32
|
||||
trun32(f32 v){
|
||||
return((i32)(v));
|
||||
}
|
||||
|
||||
static i32
|
||||
div_ceil(i32 n, i32 d){
|
||||
return( ((n) % (d) != 0) + ((n) / (d)) );
|
||||
}
|
||||
|
||||
static i32
|
||||
l_round_up_i32(i32 x, i32 b){
|
||||
i32 t = x + b - 1;
|
||||
return(t - (t%b));
|
||||
}
|
||||
|
||||
static u32
|
||||
l_round_up_u32(u32 x, u32 b){
|
||||
i32 t = x + b - 1;
|
||||
return(t - (t%b));
|
||||
}
|
||||
|
||||
static u32 round_up_pot_u32(u32 x){
|
||||
--x;
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
++x;
|
||||
return(x);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
// scalars
|
||||
|
||||
#define DEG_TO_RAD (0.0174533f)
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
ABS(f32 x){
|
||||
if (x < 0) x = -x;
|
||||
return(x);
|
||||
|
@ -26,7 +69,7 @@ ABS(f32 x){
|
|||
#if C_MATH
|
||||
#include <math.h>
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
MOD(f32 x, i32 m){
|
||||
f32 whole;
|
||||
f32 frac = modff(x, &whole);
|
||||
|
@ -34,30 +77,30 @@ MOD(f32 x, i32 m){
|
|||
return(r);
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
SQRT(f32 x){
|
||||
f32 r = sqrtf(x);
|
||||
return(r);
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
SIN(f32 x_degrees){
|
||||
f32 r = sinf(x_degrees * DEG_TO_RAD);
|
||||
return(r);
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
COS(f32 x_degrees){
|
||||
f32 r = cosf(x_degrees * DEG_TO_RAD);
|
||||
return(r);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Vectors
|
||||
*/
|
||||
////////////////////////////////
|
||||
|
||||
internal Vec2
|
||||
// vectors
|
||||
|
||||
static Vec2
|
||||
V2(f32 x, f32 y){
|
||||
Vec2 result = {};
|
||||
result.x = x;
|
||||
|
@ -65,7 +108,7 @@ V2(f32 x, f32 y){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec3
|
||||
static Vec3
|
||||
V3(f32 x, f32 y, f32 z){
|
||||
Vec3 result = {};
|
||||
result.x = x;
|
||||
|
@ -74,7 +117,7 @@ V3(f32 x, f32 y, f32 z){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
V4(f32 x, f32 y, f32 z, f32 w){
|
||||
Vec4 result = {};
|
||||
result.x = x;
|
||||
|
@ -84,7 +127,37 @@ V4(f32 x, f32 y, f32 z, f32 w){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec2_i32
|
||||
static Vec2
|
||||
V2(Vec2_i32 pi){
|
||||
return(V2((f32)pi.x, (f32)pi.y));
|
||||
}
|
||||
|
||||
static Vec3
|
||||
V3(Vec3_i32 pi){
|
||||
return(V3((f32)pi.x, (f32)pi.y, (f32)pi.z));
|
||||
}
|
||||
|
||||
static Vec4
|
||||
V4(Vec4_i32 pi){
|
||||
return(V4((f32)pi.x, (f32)pi.y, (f32)pi.z, (f32)pi.w));
|
||||
}
|
||||
|
||||
static Vec2
|
||||
V2(Vec2 pi){
|
||||
return(pi);
|
||||
}
|
||||
|
||||
static Vec3
|
||||
V3(Vec3 pi){
|
||||
return(pi);
|
||||
}
|
||||
|
||||
static Vec4
|
||||
V4(Vec4 pi){
|
||||
return(pi);
|
||||
}
|
||||
|
||||
static Vec2_i32
|
||||
V2i32(i32 x, i32 y){
|
||||
Vec2_i32 result = {};
|
||||
result.x = x;
|
||||
|
@ -92,7 +165,7 @@ V2i32(i32 x, i32 y){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec3_i32
|
||||
static Vec3_i32
|
||||
V3i32(i32 x, i32 y, i32 z){
|
||||
Vec3_i32 result = {};
|
||||
result.x = x;
|
||||
|
@ -101,7 +174,7 @@ V3i32(i32 x, i32 y, i32 z){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec4_i32
|
||||
static Vec4_i32
|
||||
V4i32(i32 x, i32 y, i32 z, i32 w){
|
||||
Vec4_i32 result = {};
|
||||
result.x = x;
|
||||
|
@ -111,7 +184,37 @@ V4i32(i32 x, i32 y, i32 z, i32 w){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec2
|
||||
static Vec2_i32
|
||||
V2i32(Vec2_f32 pi){
|
||||
return(V2i32((i32)pi.x, (i32)pi.y));
|
||||
}
|
||||
|
||||
static Vec3_i32
|
||||
V3i32(Vec3_f32 pi){
|
||||
return(V3i32((i32)pi.x, (i32)pi.y, (i32)pi.z));
|
||||
}
|
||||
|
||||
static Vec4_i32
|
||||
V4i32(Vec4_f32 pi){
|
||||
return(V4i32((i32)pi.x, (i32)pi.y, (i32)pi.z, (i32)pi.w));
|
||||
}
|
||||
|
||||
static Vec2_i32
|
||||
V2i32(Vec2_i32 pi){
|
||||
return(pi);
|
||||
}
|
||||
|
||||
static Vec3_i32
|
||||
V3i32(Vec3_i32 pi){
|
||||
return(pi);
|
||||
}
|
||||
|
||||
static Vec4_i32
|
||||
V4i32(Vec4_i32 pi){
|
||||
return(pi);
|
||||
}
|
||||
|
||||
static Vec2
|
||||
operator+(Vec2 a, Vec2 b){
|
||||
Vec2 result;
|
||||
result.x = a.x + b.x;
|
||||
|
@ -119,7 +222,7 @@ operator+(Vec2 a, Vec2 b){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec3
|
||||
static Vec3
|
||||
operator+(Vec3 a, Vec3 b){
|
||||
Vec3 result;
|
||||
result.x = a.x + b.x;
|
||||
|
@ -128,7 +231,7 @@ operator+(Vec3 a, Vec3 b){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
operator+(Vec4 a, Vec4 b){
|
||||
Vec4 result;
|
||||
result.x = a.x + b.x;
|
||||
|
@ -138,7 +241,7 @@ operator+(Vec4 a, Vec4 b){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec2
|
||||
static Vec2
|
||||
operator-(Vec2 a, Vec2 b){
|
||||
Vec2 result;
|
||||
result.x = a.x - b.x;
|
||||
|
@ -146,7 +249,7 @@ operator-(Vec2 a, Vec2 b){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec3
|
||||
static Vec3
|
||||
operator-(Vec3 a, Vec3 b){
|
||||
Vec3 result;
|
||||
result.x = a.x - b.x;
|
||||
|
@ -155,7 +258,7 @@ operator-(Vec3 a, Vec3 b){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
operator-(Vec4 a, Vec4 b){
|
||||
Vec4 result;
|
||||
result.x = a.x - b.x;
|
||||
|
@ -165,7 +268,7 @@ operator-(Vec4 a, Vec4 b){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec2
|
||||
static Vec2
|
||||
operator*(Vec2 a, f32 k){
|
||||
Vec2 result;
|
||||
result.x = a.x * k;
|
||||
|
@ -173,7 +276,7 @@ operator*(Vec2 a, f32 k){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec3
|
||||
static Vec3
|
||||
operator*(Vec3 a, f32 k){
|
||||
Vec3 result;
|
||||
result.x = a.x * k;
|
||||
|
@ -182,7 +285,7 @@ operator*(Vec3 a, f32 k){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
operator*(Vec4 a, f32 k){
|
||||
Vec4 result;
|
||||
result.x = a.x * k;
|
||||
|
@ -192,7 +295,7 @@ operator*(Vec4 a, f32 k){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec2
|
||||
static Vec2
|
||||
operator*(f32 k, Vec2 a){
|
||||
Vec2 result;
|
||||
result.x = a.x * k;
|
||||
|
@ -200,7 +303,7 @@ operator*(f32 k, Vec2 a){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec3
|
||||
static Vec3
|
||||
operator*(f32 k, Vec3 a){
|
||||
Vec3 result;
|
||||
result.x = a.x * k;
|
||||
|
@ -209,7 +312,7 @@ operator*(f32 k, Vec3 a){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
operator*(f32 k, Vec4 a){
|
||||
Vec4 result;
|
||||
result.x = a.x * k;
|
||||
|
@ -218,142 +321,142 @@ operator*(f32 k, Vec4 a){
|
|||
result.w = a.w * k;
|
||||
return(result);}
|
||||
|
||||
internal Vec2&
|
||||
static Vec2&
|
||||
operator+=(Vec2 &a, Vec2 b){
|
||||
a = (a + b);
|
||||
return a;
|
||||
}
|
||||
|
||||
internal Vec3&
|
||||
static Vec3&
|
||||
operator+=(Vec3 &a, Vec3 b){
|
||||
a = (a + b);
|
||||
return a;
|
||||
}
|
||||
|
||||
internal Vec4&
|
||||
static Vec4&
|
||||
operator+=(Vec4 &a, Vec4 b){
|
||||
a = (a + b);
|
||||
return a;
|
||||
}
|
||||
|
||||
internal Vec2&
|
||||
static Vec2&
|
||||
operator-=(Vec2 &a, Vec2 b){
|
||||
a = (a - b);
|
||||
return a;
|
||||
}
|
||||
|
||||
internal Vec3&
|
||||
static Vec3&
|
||||
operator-=(Vec3 &a, Vec3 b){
|
||||
a = (a - b);
|
||||
return a;
|
||||
}
|
||||
|
||||
internal Vec4&
|
||||
static Vec4&
|
||||
operator-=(Vec4 &a, Vec4 b){
|
||||
a = (a - b);
|
||||
return a;
|
||||
}
|
||||
|
||||
internal Vec2&
|
||||
static Vec2&
|
||||
operator*=(Vec2 &a, f32 k){
|
||||
a = (a*k);
|
||||
return a;
|
||||
}
|
||||
|
||||
internal Vec3&
|
||||
static Vec3&
|
||||
operator*=(Vec3 &a, f32 k){
|
||||
a = (a*k);
|
||||
return a;
|
||||
}
|
||||
|
||||
internal Vec4&
|
||||
static Vec4&
|
||||
operator*=(Vec4 &a, f32 k){
|
||||
a = (a*k);
|
||||
return a;
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator==(Vec2 a, Vec2 b){
|
||||
return(a.x == b.x && a.y == b.y);
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator!=(Vec2 a, Vec2 b){
|
||||
return(!(a.x == b.x && a.y == b.y));
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator==(Vec3 a, Vec3 b){
|
||||
return(a.x == b.x && a.y == b.y && a.z == b.z);
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator!=(Vec3 a, Vec3 b){
|
||||
return(!(a.x == b.x && a.y == b.y && a.z == b.z));
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator==(Vec4 a, Vec4 b){
|
||||
return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w);
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator!=(Vec4 a, Vec4 b){
|
||||
return(!(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w));
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator==(Vec2_i32 a, Vec2_i32 b){
|
||||
return(a.x == b.x && a.y == b.y);
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator!=(Vec2_i32 a, Vec2_i32 b){
|
||||
return(!(a.x == b.x && a.y == b.y));
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator==(Vec3_i32 a, Vec3_i32 b){
|
||||
return(a.x == b.x && a.y == b.y && a.z == b.z);
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator!=(Vec3_i32 a, Vec3_i32 b){
|
||||
return(!(a.x == b.x && a.y == b.y && a.z == b.z));
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator==(Vec4_i32 a, Vec4_i32 b){
|
||||
return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w);
|
||||
}
|
||||
|
||||
internal b32
|
||||
static b32
|
||||
operator!=(Vec4_i32 a, Vec4_i32 b){
|
||||
return(!(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w));
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
dot(Vec2 a, Vec2 b){
|
||||
f32 result;
|
||||
result = a.x*b.x + a.y*b.y;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
dot(Vec3 a, Vec3 b){
|
||||
f32 result;
|
||||
result = a.x*b.x + a.y*b.y + a.z*b.z;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
dot(Vec4 a, Vec4 b){
|
||||
f32 result;
|
||||
result = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal Vec3
|
||||
static Vec3
|
||||
cross(Vec3 a, Vec3 b){
|
||||
Vec3 result;
|
||||
result.x = a.y*b.z - b.y*a.z;
|
||||
|
@ -362,14 +465,14 @@ cross(Vec3 a, Vec3 b){
|
|||
return result;
|
||||
}
|
||||
|
||||
internal Vec2
|
||||
static Vec2
|
||||
hadamard(Vec2 a, Vec2 b){
|
||||
a.x *= b.x;
|
||||
a.y *= b.y;
|
||||
return(a);
|
||||
}
|
||||
|
||||
internal Vec3
|
||||
static Vec3
|
||||
hadamard(Vec3 a, Vec3 b){
|
||||
a.x *= b.x;
|
||||
a.y *= b.y;
|
||||
|
@ -377,7 +480,7 @@ hadamard(Vec3 a, Vec3 b){
|
|||
return(a);
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
hadamard(Vec4 a, Vec4 b){
|
||||
a.x *= b.x;
|
||||
a.y *= b.y;
|
||||
|
@ -386,17 +489,17 @@ hadamard(Vec4 a, Vec4 b){
|
|||
return(a);
|
||||
}
|
||||
|
||||
internal Vec2
|
||||
static Vec2
|
||||
perp(Vec2 v){
|
||||
return(V2(-v.y, v.x));
|
||||
}
|
||||
|
||||
internal Vec2
|
||||
static Vec2
|
||||
polar_to_cartesian(f32 theta_degrees, f32 length){
|
||||
return(V2(COS(theta_degrees), SIN(theta_degrees))*length);
|
||||
}
|
||||
|
||||
internal Vec2
|
||||
static Vec2
|
||||
rotate(Vec2 v, f32 theta_degrees){
|
||||
f32 c = COS(theta_degrees);
|
||||
f32 s = SIN(theta_degrees);
|
||||
|
@ -404,36 +507,34 @@ rotate(Vec2 v, f32 theta_degrees){
|
|||
v.x*s + v.y*c));
|
||||
}
|
||||
|
||||
/*
|
||||
*Lerps, Clamps, Thresholds, Etc
|
||||
*/
|
||||
////////////////////////////////
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
lerp(f32 a, f32 t, f32 b){
|
||||
return(a + (b-a)*t);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
lerp(i32 a, f32 t, i32 b){
|
||||
return((i32)(lerp((f32)a, t, (f32)b)));
|
||||
}
|
||||
|
||||
internal Vec2
|
||||
static Vec2
|
||||
lerp(Vec2 a, f32 t, Vec2 b){
|
||||
return(a + (b-a)*t);
|
||||
}
|
||||
|
||||
internal Vec3
|
||||
static Vec3
|
||||
lerp(Vec3 a, f32 t, Vec3 b){
|
||||
return(a + (b-a)*t);
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
lerp(Vec4 a, f32 t, Vec4 b){
|
||||
return(a + (b-a)*t);
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
unlerp(f32 a, f32 x, f32 b){
|
||||
f32 r = x;
|
||||
if (b != a){
|
||||
|
@ -442,7 +543,7 @@ unlerp(f32 a, f32 x, f32 b){
|
|||
return(r);
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
clamp(f32 a, f32 n, f32 z){
|
||||
if (n < a){
|
||||
n = a;
|
||||
|
@ -453,7 +554,7 @@ clamp(f32 a, f32 n, f32 z){
|
|||
return(n);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
clamp(i32 a, i32 n, i32 z){
|
||||
if (n < a){
|
||||
n = a;
|
||||
|
@ -464,7 +565,7 @@ clamp(i32 a, i32 n, i32 z){
|
|||
return(n);
|
||||
}
|
||||
|
||||
internal i64
|
||||
static i64
|
||||
clamp(i64 a, i64 n, i64 z){
|
||||
if (n < a){
|
||||
n = a;
|
||||
|
@ -475,7 +576,7 @@ clamp(i64 a, i64 n, i64 z){
|
|||
return(n);
|
||||
}
|
||||
|
||||
internal u32
|
||||
static u32
|
||||
clamp(u32 a, u32 n, u32 z){
|
||||
if (n < a){
|
||||
n = a;
|
||||
|
@ -486,7 +587,7 @@ clamp(u32 a, u32 n, u32 z){
|
|||
return(n);
|
||||
}
|
||||
|
||||
internal u64
|
||||
static u64
|
||||
clamp(u64 a, u64 n, u64 z){
|
||||
if (n < a){
|
||||
n = a;
|
||||
|
@ -497,15 +598,12 @@ clamp(u64 a, u64 n, u64 z){
|
|||
return(n);
|
||||
}
|
||||
|
||||
#define clamp_top(a,b) Min(a,b)
|
||||
#define clamp_bottom(a,b) Max(a,b)
|
||||
////////////////////////////////
|
||||
|
||||
/*
|
||||
*Color
|
||||
*/
|
||||
// color
|
||||
|
||||
// TODO(allen): Convert colors to Vec4
|
||||
internal u32
|
||||
static u32
|
||||
color_blend(u32 a, f32 t, u32 b){
|
||||
union{
|
||||
u8 byte[4];
|
||||
|
@ -523,7 +621,7 @@ color_blend(u32 a, f32 t, u32 b){
|
|||
return R.comp;
|
||||
}
|
||||
|
||||
internal Vec3
|
||||
static Vec3
|
||||
unpack_color3(u32 color){
|
||||
Vec3 result;
|
||||
result.r = ((color >> 16) & 0xFF) / 255.f;
|
||||
|
@ -532,7 +630,7 @@ unpack_color3(u32 color){
|
|||
return result;
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
unpack_color4(u32 color){
|
||||
Vec4 result;
|
||||
result.a = ((color >> 24) & 0xFF) / 255.f;
|
||||
|
@ -542,7 +640,7 @@ unpack_color4(u32 color){
|
|||
return result;
|
||||
}
|
||||
|
||||
internal u32
|
||||
static u32
|
||||
pack_color4(Vec4 color){
|
||||
u32 result =
|
||||
((u8)(color.a*255) << 24) |
|
||||
|
@ -552,7 +650,7 @@ pack_color4(Vec4 color){
|
|||
return result;
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
rgba_to_hsla(Vec4 rgba){
|
||||
Vec4 hsla = {};
|
||||
f32 max, min, delta;
|
||||
|
@ -608,7 +706,7 @@ rgba_to_hsla(Vec4 rgba){
|
|||
return hsla;
|
||||
}
|
||||
|
||||
internal Vec4
|
||||
static Vec4
|
||||
hsla_to_rgba(Vec4 hsla){
|
||||
if (hsla.h >= 1.f){
|
||||
hsla.h = 0.f;
|
||||
|
@ -633,11 +731,9 @@ hsla_to_rgba(Vec4 hsla){
|
|||
return(rgba);
|
||||
}
|
||||
|
||||
//
|
||||
// Rectangle Operations
|
||||
//
|
||||
////////////////////////////////
|
||||
|
||||
internal i32_Rect
|
||||
static i32_Rect
|
||||
i32R(i32 l, i32 t, i32 r, i32 b){
|
||||
i32_Rect rect = {};
|
||||
rect.x0 = l;
|
||||
|
@ -647,12 +743,12 @@ i32R(i32 l, i32 t, i32 r, i32 b){
|
|||
return(rect);
|
||||
}
|
||||
|
||||
internal i32_Rect
|
||||
static i32_Rect
|
||||
i32R_xy_wh(i32 x, i32 y, i32 w, i32 h){
|
||||
return(i32R(x, y, x + w, y + h));
|
||||
}
|
||||
|
||||
internal i32_Rect
|
||||
static i32_Rect
|
||||
i32R(f32_Rect r){
|
||||
i32_Rect rect = {};
|
||||
rect.x0 = (i32)r.x0;
|
||||
|
@ -662,7 +758,7 @@ i32R(f32_Rect r){
|
|||
return(rect);
|
||||
}
|
||||
|
||||
internal f32_Rect
|
||||
static f32_Rect
|
||||
f32R(f32 l, f32 t, f32 r, f32 b){
|
||||
f32_Rect rect = {};
|
||||
rect.x0 = l;
|
||||
|
@ -672,7 +768,7 @@ f32R(f32 l, f32 t, f32 r, f32 b){
|
|||
return(rect);
|
||||
}
|
||||
|
||||
internal f32_Rect
|
||||
static f32_Rect
|
||||
f32R(i32_Rect r){
|
||||
f32_Rect rect = {};
|
||||
rect.x0 = (f32)r.x0;
|
||||
|
@ -682,22 +778,22 @@ f32R(i32_Rect r){
|
|||
return(rect);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
rect_equal(i32_Rect r1, i32_Rect r2){
|
||||
return(r1.x0 == r2.x0 && r1.y0 == r2.y0 && r1.x1 == r2.x1 && r1.y1 == r2.y1);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
hit_check(i32 x, i32 y, i32 x0, i32 y0, i32 x1, i32 y1){
|
||||
return(x >= x0 && x < x1 && y >= y0 && y < y1);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
hit_check(i32 x, i32 y, i32_Rect rect){
|
||||
return(hit_check(x, y, rect.x0, rect.y0, rect.x1, rect.y1));
|
||||
}
|
||||
|
||||
internal i32_Rect
|
||||
static i32_Rect
|
||||
get_inner_rect(i32_Rect outer, i32 margin){
|
||||
i32_Rect r = {};
|
||||
r.x0 = outer.x0 + margin;
|
||||
|
@ -707,7 +803,7 @@ get_inner_rect(i32_Rect outer, i32 margin){
|
|||
return(r);
|
||||
}
|
||||
|
||||
internal f32_Rect
|
||||
static f32_Rect
|
||||
get_inner_rect(f32_Rect outer, f32 margin){
|
||||
f32_Rect r = {};
|
||||
r.x0 = outer.x0 + margin;
|
||||
|
@ -717,38 +813,38 @@ get_inner_rect(f32_Rect outer, f32 margin){
|
|||
return(r);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
rect_height(i32_Rect rect){
|
||||
return(rect.y1 - rect.y0);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
rect_width(i32_Rect rect){
|
||||
return(rect.x1 - rect.x0);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
fits_inside(i32_Rect rect, i32_Rect outer){
|
||||
return(rect.x0 >= outer.x0 && rect.x1 <= outer.x1 && rect.y0 >= outer.y0 && rect.y1 <= outer.y1);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
interval_overlap(f32 a0, f32 a1, f32 b0, f32 b1){
|
||||
return(a0 < b1 && b0 < a1);
|
||||
}
|
||||
|
||||
internal i32
|
||||
static i32
|
||||
rect_overlap(f32_Rect a, f32_Rect b){
|
||||
return(interval_overlap(a.x0, a.x1, b.x0, b.x1) &&
|
||||
interval_overlap(a.y0, a.y1, b.y0, b.y1));
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
rect_height(f32_Rect rect){
|
||||
return(rect.y1 - rect.y0);
|
||||
}
|
||||
|
||||
internal f32
|
||||
static f32
|
||||
rect_width(f32_Rect rect){
|
||||
return(rect.x1 - rect.x0);
|
||||
}
|
|
@ -58,6 +58,10 @@ typedef double f64;
|
|||
#define Max(a,b) (((a)>(b))?(a):(b))
|
||||
#define Min(a,b) (((a)<(b))?(a):(b))
|
||||
|
||||
#define clamp_top(a,b) Min(a,b)
|
||||
#define clamp_bottom(a,b) Max(a,b)
|
||||
//#define clamp(a,x,b) Min(
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
struct Vec2_f32{
|
||||
|
|
|
@ -141,7 +141,7 @@ struct Application_Links;
|
|||
#define SEND_EXIT_SIGNAL_SIG(n) void n(Application_Links *app)
|
||||
#define SET_WINDOW_TITLE_SIG(n) bool32 n(Application_Links *app, String title)
|
||||
#define GET_MICROSECONDS_TIMESTAMP_SIG(n) Microsecond_Time_Stamp n(Application_Links *app)
|
||||
#define DRAW_STRING_SIG(n) float n(Application_Links *app, Face_ID font_id, String str, int32_t x, int32_t y, int_color color, uint32_t flags, float dx, float dy)
|
||||
#define DRAW_STRING_SIG(n) float n(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta)
|
||||
#define GET_STRING_ADVANCE_SIG(n) float n(Application_Links *app, Face_ID font_id, String str)
|
||||
#define DRAW_RECTANGLE_SIG(n) void n(Application_Links *app, f32_Rect rect, int_color color)
|
||||
#define DRAW_RECTANGLE_OUTLINE_SIG(n) void n(Application_Links *app, f32_Rect rect, int_color color)
|
||||
|
@ -904,7 +904,7 @@ static bool32 is_fullscreen(Application_Links *app){return(app->is_fullscreen(ap
|
|||
static void send_exit_signal(Application_Links *app){(app->send_exit_signal(app));}
|
||||
static bool32 set_window_title(Application_Links *app, String title){return(app->set_window_title(app, title));}
|
||||
static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp(app));}
|
||||
static float draw_string(Application_Links *app, Face_ID font_id, String str, int32_t x, int32_t y, int_color color, uint32_t flags, float dx, float dy){return(app->draw_string(app, font_id, str, x, y, color, flags, dx, dy));}
|
||||
static float draw_string(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string(app, font_id, str, point, color, flags, delta));}
|
||||
static float get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance(app, font_id, str));}
|
||||
static void draw_rectangle(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle(app, rect, color));}
|
||||
static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline(app, rect, color));}
|
||||
|
@ -1055,7 +1055,7 @@ static bool32 is_fullscreen(Application_Links *app){return(app->is_fullscreen_(a
|
|||
static void send_exit_signal(Application_Links *app){(app->send_exit_signal_(app));}
|
||||
static bool32 set_window_title(Application_Links *app, String title){return(app->set_window_title_(app, title));}
|
||||
static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp_(app));}
|
||||
static float draw_string(Application_Links *app, Face_ID font_id, String str, int32_t x, int32_t y, int_color color, uint32_t flags, float dx, float dy){return(app->draw_string_(app, font_id, str, x, y, color, flags, dx, dy));}
|
||||
static float draw_string(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string_(app, font_id, str, point, color, flags, delta));}
|
||||
static float get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance_(app, font_id, str));}
|
||||
static void draw_rectangle(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_(app, rect, color));}
|
||||
static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline_(app, rect, color));}
|
||||
|
|
|
@ -418,7 +418,6 @@ cpp_token_category_from_type(Cpp_Token_Type type){
|
|||
cat = CPP_TOKEN_CAT_OPERATOR;
|
||||
}break;
|
||||
|
||||
|
||||
case CPP_TOKEN_VOID:
|
||||
case CPP_TOKEN_BOOL:
|
||||
case CPP_TOKEN_CHAR:
|
||||
|
|
|
@ -4231,22 +4231,24 @@ DOC(Returns a microsecond resolution timestamp.)
|
|||
return(system->now_time());
|
||||
}
|
||||
|
||||
internal void
|
||||
draw_helper__view_space_to_screen_space(Models *models, i32 *x, i32 *y){
|
||||
internal Vec2
|
||||
draw_helper__view_space_to_screen_space(Models *models, Vec2 point){
|
||||
i32_Rect region = models->render_rect;
|
||||
*x += region.x0;
|
||||
*y += region.y0;
|
||||
point.x += (f32)region.x0;
|
||||
point.y += (f32)region.y0;
|
||||
return(point);
|
||||
}
|
||||
|
||||
internal void
|
||||
draw_helper__view_space_to_screen_space(Models *models, f32_Rect *rect){
|
||||
internal f32_Rect
|
||||
draw_helper__view_space_to_screen_space(Models *models, f32_Rect rect){
|
||||
i32_Rect region = models->render_rect;
|
||||
f32 x_corner = (f32)region.x0;
|
||||
f32 y_corner = (f32)region.y0;
|
||||
rect->x0 += x_corner;
|
||||
rect->y0 += y_corner;
|
||||
rect->x1 += x_corner;
|
||||
rect->y1 += y_corner;
|
||||
rect.x0 += x_corner;
|
||||
rect.y0 += y_corner;
|
||||
rect.x1 += x_corner;
|
||||
rect.y1 += y_corner;
|
||||
return(rect);
|
||||
}
|
||||
|
||||
// NOTE(allen): Coordinate space of draw calls:
|
||||
|
@ -4254,64 +4256,60 @@ draw_helper__view_space_to_screen_space(Models *models, f32_Rect *rect){
|
|||
// To make text scroll with the buffer users should read the view's scroll position and subtract it first.
|
||||
|
||||
API_EXPORT float
|
||||
Draw_String(Application_Links *app, Face_ID font_id, String str, int32_t x, int32_t y, int_color color, uint32_t flags, float dx, float dy)
|
||||
Draw_String(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta)
|
||||
{
|
||||
f32 result = 0.f;
|
||||
Models *models = (Models*)app->cmd_context;
|
||||
if (models->render_view == 0){
|
||||
float w = font_string_width(models->system, models->target, font_id, str);
|
||||
return(w);
|
||||
result = font_string_width(models->system, models->target, font_id, str);
|
||||
}
|
||||
Style *style = &models->styles.styles[0];
|
||||
Theme *theme_data = &style->theme;
|
||||
|
||||
draw_helper__view_space_to_screen_space(models, &x, &y);
|
||||
|
||||
u32 actual_color = finalize_color(theme_data, color);
|
||||
float w = draw_string_base(models->system, models->target, font_id, str, x, y,
|
||||
actual_color, flags, dx, dy);
|
||||
return(w);
|
||||
else{
|
||||
Style *style = &models->styles.styles[0];
|
||||
Theme *theme_data = &style->theme;
|
||||
|
||||
point = draw_helper__view_space_to_screen_space(models, point);
|
||||
|
||||
u32 actual_color = finalize_color(theme_data, color);
|
||||
result = draw_string(models->system, models->target, font_id, str, point, actual_color, flags, delta);
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
API_EXPORT float
|
||||
Get_String_Advance(Application_Links *app, Face_ID font_id, String str)
|
||||
{
|
||||
Models *models = (Models*)app->cmd_context;
|
||||
float w = font_string_width(models->system, models->target, font_id, str);
|
||||
return(w);
|
||||
return(font_string_width(models->system, models->target, font_id, str));
|
||||
}
|
||||
|
||||
API_EXPORT void
|
||||
Draw_Rectangle(Application_Links *app, f32_Rect rect, int_color color)
|
||||
{
|
||||
Models *models = (Models*)app->cmd_context;
|
||||
if (models->render_view == 0){
|
||||
return;
|
||||
if (models->render_view != 0){
|
||||
Style *style = &models->styles.styles[0];
|
||||
Theme *theme_data = &style->theme;
|
||||
|
||||
rect = draw_helper__view_space_to_screen_space(models, rect);
|
||||
|
||||
u32 actual_color = finalize_color(theme_data, color);
|
||||
draw_rectangle(models->target, rect, actual_color);
|
||||
}
|
||||
|
||||
Style *style = &models->styles.styles[0];
|
||||
Theme *theme_data = &style->theme;
|
||||
|
||||
draw_helper__view_space_to_screen_space(models, &rect);
|
||||
|
||||
u32 actual_color = finalize_color(theme_data, color);
|
||||
draw_rectangle(models->target, rect, actual_color);
|
||||
}
|
||||
|
||||
API_EXPORT void
|
||||
Draw_Rectangle_Outline(Application_Links *app, f32_Rect rect, int_color color)
|
||||
{
|
||||
Models *models = (Models*)app->cmd_context;
|
||||
if (models->render_view == 0){
|
||||
return;
|
||||
if (models->render_view != 0){
|
||||
Style *style = &models->styles.styles[0];
|
||||
Theme *theme_data = &style->theme;
|
||||
|
||||
rect = draw_helper__view_space_to_screen_space(models, rect);
|
||||
|
||||
u32 actual_color = finalize_color(theme_data, color);
|
||||
draw_rectangle_outline(models->target, rect, actual_color);
|
||||
}
|
||||
|
||||
Style *style = &models->styles.styles[0];
|
||||
Theme *theme_data = &style->theme;
|
||||
|
||||
draw_helper__view_space_to_screen_space(models, &rect);
|
||||
|
||||
u32 actual_color = finalize_color(theme_data, color);
|
||||
draw_rectangle_outline(models->target, rect, actual_color);
|
||||
}
|
||||
|
||||
API_EXPORT Face_ID
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "4coder_API/4coder_custom.h"
|
||||
|
||||
#include "4ed_defines.h"
|
||||
#include "4ed_math.h"
|
||||
//#include "4ed_math.h"
|
||||
#include "4ed_font.h"
|
||||
#include "4ed_system.h"
|
||||
|
||||
|
|
|
@ -101,47 +101,6 @@ typedef double f64;
|
|||
|
||||
#define FixSize(s) struct{ u8 __size_fixer__[s]; }
|
||||
|
||||
internal i32 ceil32(f32 v){
|
||||
return(((v)>0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)+1.f)) ):( ((i32)(v)) ));
|
||||
}
|
||||
|
||||
internal i32 floor32(f32 v){
|
||||
return(((v)<0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)-1.f)) ):( ((i32)(v)) ));
|
||||
}
|
||||
|
||||
internal i32 round32(f32 v){
|
||||
return(floor32(v + 0.5f));
|
||||
}
|
||||
|
||||
internal i32 trun32(f32 v){
|
||||
return((i32)(v));
|
||||
}
|
||||
|
||||
internal i32 div_ceil(i32 n, i32 d){
|
||||
return( ((n) % (d) != 0) + ((n) / (d)) );
|
||||
}
|
||||
|
||||
internal i32 l_round_up_i32(i32 x, i32 b){
|
||||
i32 t = x + b - 1;
|
||||
return(t - (t%b));
|
||||
}
|
||||
|
||||
internal u32 l_round_up_u32(u32 x, u32 b){
|
||||
i32 t = x + b - 1;
|
||||
return(t - (t%b));
|
||||
}
|
||||
|
||||
internal u32 round_up_pot_u32(u32 x){
|
||||
--x;
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
++x;
|
||||
return(x);
|
||||
}
|
||||
|
||||
#define DrCase(PC) case PC: goto resumespot_##PC
|
||||
#define DrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; }
|
||||
#define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); }
|
||||
|
|
|
@ -120,28 +120,33 @@ draw_font_glyph(Render_Target *target, Face_ID font_id, u32 codepoint, f32 x, f3
|
|||
render_end_push(target, h);
|
||||
}
|
||||
|
||||
// TODO(allen): do(merge draw_string_base into draw_string)
|
||||
internal Vec2
|
||||
snap_point_to_boundary(Vec2 point){
|
||||
point.x = (f32)(floor32(point.x));
|
||||
point.y = (f32)(floor32(point.y));
|
||||
return(point);
|
||||
}
|
||||
|
||||
internal f32
|
||||
draw_string_base(System_Functions *system, Render_Target *target, Face_ID font_id, String str_, i32 x_, i32 y_, u32 color,
|
||||
u32 flags, f32 dx, f32 dy){
|
||||
f32 x = 0;
|
||||
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String string, Vec2 point,
|
||||
u32 color, u32 flags, Vec2 delta){
|
||||
f32 total_delta = 0.f;
|
||||
|
||||
Font_Pointers font = system->font.get_pointers_by_id(font_id);
|
||||
if (font.valid != 0){
|
||||
f32 y = (f32)y_;
|
||||
x = (f32)x_;
|
||||
point = snap_point_to_boundary(point);
|
||||
|
||||
f32 byte_advance = font.metrics->byte_advance;
|
||||
f32 *sub_advances = font.metrics->sub_advances;
|
||||
|
||||
u8 *str = (u8*)str_.str;
|
||||
u8 *str_end = str + str_.size;
|
||||
u8 *str = (u8*)string.str;
|
||||
u8 *str_end = str + string.size;
|
||||
|
||||
Translation_State tran = {};
|
||||
Translation_Emits emits = {};
|
||||
|
||||
for (u32 i = 0; str < str_end; ++str, ++i){
|
||||
translating_fully_process_byte(system, font, &tran, *str, i, str_.size, &emits);
|
||||
translating_fully_process_byte(system, font, &tran, *str, i, string.size, &emits);
|
||||
|
||||
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
|
||||
TRANSLATION_DECL_GET_STEP(step, behavior, J, emits);
|
||||
|
@ -149,11 +154,11 @@ draw_string_base(System_Functions *system, Render_Target *target, Face_ID font_i
|
|||
if (behavior.do_codepoint_advance){
|
||||
u32 codepoint = step.value;
|
||||
if (color != 0){
|
||||
draw_font_glyph(target, font_id, codepoint, x, y, color, flags);
|
||||
draw_font_glyph(target, font_id, codepoint, point.x, point.y, color, flags);
|
||||
}
|
||||
f32 d = font_get_glyph_advance(system, font.settings, font.metrics, font.pages, codepoint);
|
||||
x += d*dx;
|
||||
y += d*dy;
|
||||
point += d*delta;
|
||||
total_delta += d;
|
||||
}
|
||||
else if (behavior.do_number_advance){
|
||||
u8 n = (u8)(step.value);
|
||||
|
@ -161,70 +166,48 @@ draw_string_base(System_Functions *system, Render_Target *target, Face_ID font_i
|
|||
u8 cs[3];
|
||||
cs[0] = '\\';
|
||||
byte_to_ascii(n, cs+1);
|
||||
|
||||
f32 xx = x;
|
||||
f32 yy = y;
|
||||
Vec2 pp = point;
|
||||
for (u32 j = 0; j < 3; ++j){
|
||||
draw_font_glyph(target, font_id, cs[j], xx, yy, color, flags);
|
||||
xx += dx*sub_advances[j];
|
||||
yy += dy*sub_advances[j];
|
||||
draw_font_glyph(target, font_id, cs[j], pp.x, pp.y, color, flags);
|
||||
pp += delta*sub_advances[j];
|
||||
}
|
||||
}
|
||||
|
||||
x += dx*byte_advance;
|
||||
y += dy*byte_advance;
|
||||
point += byte_advance*delta;
|
||||
total_delta += byte_advance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(x);
|
||||
return(total_delta);
|
||||
}
|
||||
|
||||
internal f32
|
||||
draw_string_base(System_Functions *system, Render_Target *target, Face_ID font_id, String str_, i32 x_, i32 y_, u32 color){
|
||||
f32 result = draw_string_base(system, target, font_id, str_, x_, y_, color, 0, 1.f, 0.f);
|
||||
return(result);
|
||||
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String string, Vec2 point,
|
||||
u32 color){
|
||||
return(draw_string(system, target, font_id, string, point, color, 0, V2(1.f, 0.f)));
|
||||
}
|
||||
|
||||
internal f32
|
||||
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String str, i32 x, i32 y, u32 color,
|
||||
u32 flags, f32 dx, f32 dy){
|
||||
f32 w = draw_string_base(system, target, font_id, str, x, y, color, flags, dx, dy);
|
||||
return(w);
|
||||
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, Vec2 point,
|
||||
u32 color, u32 flags, Vec2 delta){
|
||||
return(draw_string(system, target, font_id, make_string_slowly(str), point, color, flags, delta));
|
||||
}
|
||||
|
||||
internal f32
|
||||
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, i32 x, i32 y, u32 color,
|
||||
u32 flags, f32 dx, f32 dy){
|
||||
String string = make_string_slowly(str);
|
||||
f32 w = draw_string_base(system, target, font_id, string, x, y, color, flags, dx, dy);
|
||||
return(w);
|
||||
}
|
||||
|
||||
internal f32
|
||||
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String str, i32 x, i32 y, u32 color){
|
||||
f32 w = draw_string(system, target, font_id, str, x, y, color, 0, 1.f, 0.f);
|
||||
return(w);
|
||||
}
|
||||
|
||||
internal f32
|
||||
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, i32 x, i32 y, u32 color){
|
||||
f32 w = draw_string(system, target, font_id, str, x, y, color, 0, 1.f, 0.f);
|
||||
return(w);
|
||||
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, Vec2 point,
|
||||
u32 color){
|
||||
return(draw_string(system, target, font_id, make_string_slowly(str), point, color, 0, V2(1.f, 0.f)));
|
||||
}
|
||||
|
||||
internal f32
|
||||
font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, String str){
|
||||
f32 w = draw_string_base(system, target, font_id, str, 0, 0, 0);
|
||||
return(w);
|
||||
return(draw_string(system, target, font_id, str, V2(0, 0), 0, 0, V2(0, 0)));
|
||||
}
|
||||
|
||||
internal f32
|
||||
font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, char *str){
|
||||
String string = make_string_slowly(str);
|
||||
f32 w = draw_string_base(system, target, font_id, string, 0, 0, 0);
|
||||
return(w);
|
||||
return(draw_string(system, target, font_id, make_string_slowly(str), V2(0, 0), 0, 0, V2(0, 0)));
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
|
|
@ -99,10 +99,8 @@ struct Shift_Information{
|
|||
};
|
||||
|
||||
struct File_Bar{
|
||||
f32 pos_x;
|
||||
f32 pos_y;
|
||||
f32 text_shift_x;
|
||||
f32 text_shift_y;
|
||||
Vec2 pos;
|
||||
Vec2 text_shift;
|
||||
i32_Rect rect;
|
||||
Face_ID font_id;
|
||||
};
|
||||
|
|
|
@ -98,25 +98,10 @@ do_step_file_view(System_Functions *system, Models *models, View *view, i32_Rect
|
|||
|
||||
////////////////////////////////
|
||||
|
||||
internal void
|
||||
draw_text_field(System_Functions *system, Render_Target *target, View *view, Models *models, Face_ID font_id, i32_Rect rect, String p, String t){
|
||||
if (target != 0){
|
||||
Style *style = &models->styles.styles[0];
|
||||
u32 back_color = style->theme.colors[Stag_Margin];
|
||||
u32 text1_color = style->theme.colors[Stag_Default];
|
||||
u32 text2_color = style->theme.colors[Stag_Pop1];
|
||||
i32 x = rect.x0;
|
||||
i32 y = rect.y0 + 2;
|
||||
draw_rectangle(target, rect, back_color);
|
||||
x = ceil32(draw_string(system, target, font_id, p, x, y, text2_color));
|
||||
draw_string(system, target, font_id, t, x, y, text1_color);
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
intbar_draw_string(System_Functions *system, Render_Target *target, File_Bar *bar, String str, u32 char_color){
|
||||
draw_string(system, target, bar->font_id, str, (i32)(bar->pos_x + bar->text_shift_x), (i32)(bar->pos_y + bar->text_shift_y), char_color);
|
||||
bar->pos_x += font_string_width(system, target, bar->font_id, str);
|
||||
Vec2 p = bar->pos + bar->text_shift;
|
||||
bar->pos.x += draw_string(system, target, bar->font_id, str, p, char_color);
|
||||
}
|
||||
|
||||
internal void
|
||||
|
@ -133,10 +118,8 @@ draw_file_bar(System_Functions *system, Render_Target *target, View *view, Model
|
|||
|
||||
if (target != 0){
|
||||
bar.font_id = file->settings.font_id;
|
||||
bar.pos_x = (f32)bar.rect.x0;
|
||||
bar.pos_y = (f32)bar.rect.y0;
|
||||
bar.text_shift_y = 2;
|
||||
bar.text_shift_x = 0;
|
||||
bar.pos = V2(bar.rect.p0);
|
||||
bar.text_shift = V2(0.f, 2.f);
|
||||
|
||||
draw_rectangle(target, bar.rect, back_color);
|
||||
|
||||
|
@ -248,11 +231,11 @@ do_render_file_view(System_Functions *system, View *view, Models *models, GUI_Sc
|
|||
u32 back_color = style->theme.colors[Stag_Back];
|
||||
u32 text1_color = style->theme.colors[Stag_Default];
|
||||
u32 text2_color = style->theme.colors[Stag_Pop1];
|
||||
i32 x = query_bar_rect.x0;
|
||||
i32 y = query_bar_rect.y0 + 2;
|
||||
Vec2 p = V2(query_bar_rect.p0);
|
||||
p.y += 2.f;
|
||||
draw_rectangle(target, query_bar_rect, back_color);
|
||||
x = ceil32(draw_string(system, target, font_id, slot->query_bar->prompt, x, y, text2_color));
|
||||
draw_string(system, target, font_id, slot->query_bar->string, x, y, text1_color);
|
||||
p.x += draw_string(system, target, font_id, slot->query_bar->prompt, p, text2_color);
|
||||
draw_string(system, target, font_id, slot->query_bar->string, p, text1_color);
|
||||
}
|
||||
view->widget_height = (f32)bar_count*(view->line_height + 2);
|
||||
|
||||
|
@ -298,11 +281,10 @@ do_render_file_view(System_Functions *system, View *view, Models *models, GUI_Sc
|
|||
u32 margin_color = get_margin_color(style, item->activation_level);
|
||||
f32_Rect inner = get_inner_rect(item_rect, 3);
|
||||
draw_rectangle(target, inner, back);
|
||||
i32 x = (i32)inner.x0 + 3;
|
||||
i32 y = (i32)inner.y0 + line_height/2 - 1;
|
||||
x = ceil32(draw_string(system, target, font_id, item->option.string, x, y, text_color));
|
||||
x += (i32)font_string_width(system, target, font_id, " ");
|
||||
draw_string(system, target, font_id, item->option.status, x, y, pop_color);
|
||||
Vec2 p = V2(inner.p0) + V2(3.f, line_height*0.5f - 1.f);
|
||||
p.x += draw_string(system, target, font_id, item->option.string, p, text_color);
|
||||
p.x += font_string_width(system, target, font_id, make_lit_string(" "));
|
||||
draw_string(system, target, font_id, item->option.status, p, pop_color);
|
||||
draw_margin(target, item_rect, inner, margin_color);
|
||||
}break;
|
||||
|
||||
|
@ -312,11 +294,10 @@ do_render_file_view(System_Functions *system, View *view, Models *models, GUI_Sc
|
|||
u32 text1 = style->theme.colors[Stag_Default];
|
||||
u32 text2 = style->theme.colors[Stag_Pop1];
|
||||
draw_rectangle(target, item_rect, back);
|
||||
i32 x = (i32)item_rect.x0;
|
||||
i32 y = (i32)item_rect.y0 + 2;
|
||||
x = ceil32(draw_string(system, target, font_id, item->text_field.query, x, y, text2));
|
||||
x += (i32)font_string_width(system, target, font_id, " ");
|
||||
draw_string(system, target, font_id, item->text_field.string, x, y, text1);
|
||||
Vec2 p = V2(item_rect.p0) + V2(0.f, 2.f);
|
||||
p.x += draw_string(system, target, font_id, item->text_field.query, p, text2);
|
||||
p.x += font_string_width(system, target, font_id, make_lit_string(" "));
|
||||
p.x += draw_string(system, target, font_id, item->text_field.string, p, text1);
|
||||
}break;
|
||||
|
||||
case UIType_ColorTheme:
|
||||
|
@ -334,32 +315,29 @@ do_render_file_view(System_Functions *system, View *view, Models *models, GUI_Sc
|
|||
draw_margin(target, item_rect, inner, margin_color);
|
||||
draw_rectangle(target, inner, back);
|
||||
|
||||
i32 y = (i32)inner.y0;
|
||||
i32 x = (i32)inner.x0;
|
||||
Vec2 p = V2(inner.p0);
|
||||
String str = item->color_theme.string;
|
||||
if (str.str == 0){
|
||||
str = style_preview->name;
|
||||
}
|
||||
x = ceil32(draw_string(system, target, font_id, str, x, y, text_color));
|
||||
i32 font_x = (i32)(inner.x1 - font_string_width(system, target, font_id, font_name));
|
||||
if (font_x > x + 10){
|
||||
draw_string(system, target, font_id, font_name, font_x, y, text_color);
|
||||
p.x += draw_string(system, target, font_id, str, p, text_color);
|
||||
f32 font_x = inner.x1 - font_string_width(system, target, font_id, font_name);
|
||||
if (font_x > p.x + 10.f){
|
||||
draw_string(system, target, font_id, font_name, V2(font_x, p.y), text_color);
|
||||
}
|
||||
|
||||
i32 height = font.metrics->height;
|
||||
x = (i32)inner.x0;
|
||||
y += height;
|
||||
x = ceil32(draw_string(system, target, font_id, "if", x, y, keyword_color));
|
||||
x = ceil32(draw_string(system, target, font_id, "(x < ", x, y, text_color));
|
||||
x = ceil32(draw_string(system, target, font_id, "0", x, y, int_constant_color));
|
||||
x = ceil32(draw_string(system, target, font_id, ") { x = ", x, y, text_color));
|
||||
x = ceil32(draw_string(system, target, font_id, "0", x, y, int_constant_color));
|
||||
x = ceil32(draw_string(system, target, font_id, "; } ", x, y, text_color));
|
||||
x = ceil32(draw_string(system, target, font_id, "// comment", x, y, comment_color));
|
||||
p = V2(inner.x0, p.y + (f32)height);
|
||||
p.x += draw_string(system, target, font_id, "if", p, keyword_color);
|
||||
p.x += draw_string(system, target, font_id, "(x < ", p, text_color);
|
||||
p.x += draw_string(system, target, font_id, "0", p, int_constant_color);
|
||||
p.x += draw_string(system, target, font_id, ") { x = ", p, text_color);
|
||||
p.x += draw_string(system, target, font_id, "0", p, int_constant_color);
|
||||
p.x += draw_string(system, target, font_id, "; } ", p, text_color);
|
||||
p.x += draw_string(system, target, font_id, "// comment", p, comment_color);
|
||||
|
||||
x = (i32)inner.x0;
|
||||
y += height;
|
||||
draw_string(system, target, font_id, "[] () {}; * -> +-/ <>= ! && || % ^", x, y, text_color);
|
||||
p = V2(inner.x0, p.y + (f32)height);
|
||||
draw_string(system, target, font_id, "[] () {}; * -> +-/ <>= ! && || % ^", p, text_color);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@
|
|||
# include "4coder_default_bindings.cpp"
|
||||
#endif
|
||||
|
||||
#include "4ed_math.h"
|
||||
#include "4coder_base_types.cpp"
|
||||
//#include "4ed_math.h"
|
||||
|
||||
#include "4ed_font.h"
|
||||
#include "4ed_system.h"
|
||||
|
@ -1748,12 +1749,13 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
|
|||
b8 *control_keys = win32vars.input_chunk.pers.control_keys;
|
||||
i32 control_keys_size = sizeof(win32vars.input_chunk.pers.control_keys);
|
||||
|
||||
Assert(*count < KEY_INPUT_BUFFER_SIZE);
|
||||
data[*count].character = 0;
|
||||
data[*count].character_no_caps_lock = 0;
|
||||
data[*count].keycode = key;
|
||||
memcpy(data[*count].modifiers, control_keys, control_keys_size);
|
||||
++(*count);
|
||||
if (*count < KEY_INPUT_BUFFER_SIZE){
|
||||
data[*count].character = 0;
|
||||
data[*count].character_no_caps_lock = 0;
|
||||
data[*count].keycode = key;
|
||||
memcpy(data[*count].modifiers, control_keys, control_keys_size);
|
||||
++(*count);
|
||||
}
|
||||
|
||||
win32vars.got_useful_event = true;
|
||||
}
|
||||
|
@ -1792,12 +1794,13 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
|
|||
}
|
||||
}
|
||||
|
||||
Assert(*count < KEY_INPUT_BUFFER_SIZE);
|
||||
data[*count].character = character;
|
||||
data[*count].character_no_caps_lock = character_no_caps_lock;
|
||||
data[*count].keycode = character_no_caps_lock;
|
||||
memcpy(data[*count].modifiers, control_keys, control_keys_size);
|
||||
++(*count);
|
||||
if (*count < KEY_INPUT_BUFFER_SIZE){
|
||||
data[*count].character = character;
|
||||
data[*count].character_no_caps_lock = character_no_caps_lock;
|
||||
data[*count].keycode = character_no_caps_lock;
|
||||
memcpy(data[*count].modifiers, control_keys, control_keys_size);
|
||||
++(*count);
|
||||
}
|
||||
|
||||
win32vars.got_useful_event = true;
|
||||
}break;
|
||||
|
|
Loading…
Reference in New Issue