-
Notifications
You must be signed in to change notification settings - Fork 0
/
monkyyydraw.d
90 lines (82 loc) · 2.77 KB
/
monkyyydraw.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// TODO: wait on named arguments templates or find out how to extract the infomation
// rn it will break when you try to bring the pieces together natively
import raylib;
import monkyyycolor;
import staticabstractions;
//export sanity; todo
void draw_(T...)(T args)=>draw(args,color:color);//todo make smart
void drawH(T...)(T args)=>draw(args,color:highlight);
void drawB(T...)(T args)=>draw(args,color:background);
void drawA(T...)(T args)=>draw(args,color:allcolors);
//void draw(T...)(Vector2 vec2,T args)=>draw(x:cast(int)vec2.x,y:cast(int)vec2.y,args);
struct gradent{}
import staticabstractions;
//void draw(gradent g,alias A,int low,size_t high,T...)(stickyindex!(A,low,high) color,T args)=>draw(color1:color++,color2:color--,args);
alias draw=raylib.DrawCircle;
alias draw=raylib.DrawCircleV;
alias draw=raylib.DrawCircleGradient;
alias draw=raylib.DrawPixel;
alias draw=raylib.DrawRectangle;
alias draw=raylib.DrawRectangleGradientH;
//alias draw=
//alias draw=
/*
TODO:
figure out how named agruments work with overload sets and expand this to allot of functions
right now im getting nonsense errors, and shit
I stuggle with 3 layers of recersion
*/
void drawtext(/*T,*/I,J=int,C=typeof(text),C2=typeof(highlight))
(string text_,I x,I y,J textsize=weak!J(16),C color=weak!(C,text),C2 color2=weak!(C2,highlight)){
if(text_.length==0){return;}
void assertcstring(T)(char* s,T len){
assert(s[len]==0,"is not a c string");
}
//string t=text_;
char* t_=cast(char*)&(text_[0]);
assertcstring(t_,text_.length);
int x_=cast(int)x;
int y_=cast(int)y;
int size=cast(int)textsize;
int width=MeasureText(t_,size);
if(x_<0){
x_=-x_;
x_-=width;
}
if(y_<0){
y_=-y_;
y_-=size;
}
draw(x_,y_,width,size,color2);
DrawText(t_,x_,y_,size,color);
}
auto loadspritesheet(string sheet_,int width,int height)(){
struct spritesheet{
Texture baseimage;
size_t i;
auto init(){
baseimage=LoadTexture(sheet_);
return this;
}
auto __get(int x,int y,float scale=1.0,float rotation=0){
auto count=baseimage.width/width;//TODO: ughhhhh rotation and orgin are limitmented navively on raylibs side here, and the math to fix it is.... allot, rotate will behave wierd
DrawTexturePro(baseimage,Rectangle((i%count)*width,(i/count)*height,width,height), Rectangle(x,y,width*scale,height*scale), /*Vector2((width/2)*scale,(height/2)*scale)*/ Vector2(0,0),rotation, Color(255,255,255,255));
}
alias opCall=__get;
auto opIndex(size_t j){
auto count=baseimage.width/width;
auto county=baseimage.height/height;
if(j>count*county){return this;}
i=j;
return this;
}
auto opIndex(size_t x,size_t y){
auto count=baseimage.width/width;
auto county=baseimage.height/height;
if(x>count||y>county){return this;}
return this[x+y*count];
}
}
spritesheet foo;
return foo.init;
}