1+ #include " Color.h"
2+ #include " ../Vectors/Vector2.h"
3+ #include " ../Vectors/Rect.h"
4+
5+ #ifndef ANDROID_MENU_DRAW_H
6+ #define ANDROID_MENU_DRAW_H
7+
8+ class DrawView
9+ {
10+ private:
11+ JNIEnv *_env;
12+ jobject _cvsView;
13+ jobject _cvs;
14+
15+ public:
16+ DrawView ()
17+ {
18+ _env = nullptr ;
19+ _cvsView = nullptr ;
20+ _cvs = nullptr ;
21+ }
22+
23+ DrawView (JNIEnv *env, jobject cvsView, jobject cvs)
24+ {
25+ this ->_env = env;
26+ this ->_cvsView = cvsView;
27+ this ->_cvs = cvs;
28+ }
29+
30+ bool isValid () const
31+ {
32+ return (this ->_env != nullptr && this ->_cvsView != nullptr && this ->_cvs != nullptr );
33+ }
34+
35+ int getWidth () const
36+ {
37+ if (isValid ())
38+ {
39+ return _env->CallIntMethod (_cvs, _env->GetMethodID (_env->GetObjectClass (_cvs), " getWidth" , " ()I" ));
40+ }
41+ return 0 ;
42+ }
43+
44+ int getHeight () const
45+ {
46+ if (isValid ())
47+ {
48+ return _env->CallIntMethod (_cvs, _env->GetMethodID (_env->GetObjectClass (_cvs), " getHeight" , " ()I" ));
49+ }
50+ return 0 ;
51+ }
52+
53+ void DrawLine (Color color, float thickness, Vector2 start, Vector2 end)
54+ {
55+ if (isValid ())
56+ {
57+ _env->CallVoidMethod (_cvsView, _env->GetMethodID (_env->GetObjectClass (_cvsView), " DrawLine" , " (Landroid/graphics/Canvas;IIIIFFFFF)V" ), _cvs, (int ) color.a , (int ) color.r , (int ) color.g , (int ) color.b , thickness, start.X , start.Y , end.X , end.Y );
58+ }
59+ return ;
60+ }
61+
62+ void DrawText (Color color, const char * str, Vector2 pos, float size)
63+ {
64+ if (isValid ())
65+ {
66+ _env->CallVoidMethod (_cvsView, _env->GetMethodID (_env->GetObjectClass (_cvsView), " DrawText" , " (Landroid/graphics/Canvas;IIIIFLjava/lang/String;FFF)V" ), _cvs, (int ) color.a , (int ) color.r , (int ) color.g , (int ) color.b , 0 .6f , _env->NewStringUTF (str), pos.X , pos.Y , size);
67+ }
68+ return ;
69+ }
70+
71+ void DrawCircle (Color color, float stroke, Vector2 pos, float radius)
72+ {
73+ if (isValid ())
74+ {
75+ _env->CallVoidMethod (_cvsView, _env->GetMethodID (_env->GetObjectClass (_cvsView), " DrawCircle" , " (Landroid/graphics/Canvas;IIIIFFFF)V" ), _cvs, (int ) color.a , (int ) color.r , (int ) color.g , (int ) color.b , stroke, pos.X , pos.Y , radius);
76+ }
77+ return ;
78+ }
79+
80+ void DrawRoundRect (Color color, float stroke, int cx, int cy, Rect rect)
81+ {
82+ if (isValid ())
83+ {
84+ _env->CallVoidMethod (_cvsView, _env->GetMethodID (_env->GetObjectClass (_cvsView), " DrawRoundRect" , " (Landroid/graphics/Canvas;IIIIFIIFFFF)V" ), _cvs, (int ) color.a , (int ) color.r , (int ) color.g , (int ) color.b , stroke, cx,cy, rect.x , rect.y , rect.w , rect.h );
85+ }
86+ return ;
87+ }
88+
89+ void DrawTextRect (Color color, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, Vector2 pos)
90+ {
91+ if (isValid ())
92+ {
93+ _env->CallVoidMethod (_cvsView, _env->GetMethodID (_env->GetObjectClass (_cvsView), " DrawTextRect" , " (Landroid/graphics/Canvas;IIIIIIIIIIIIFF)V" ), _cvs, (int ) color.a , (int ) color.r ,(int ) color.g , (int ) color.b , a1, a2, a3, a4, a5, a6, a7, a8, pos.X , pos.Y );
94+ }
95+ return ;
96+ }
97+
98+ void DrawFilledBox (Color color, Rect rect)
99+ {
100+ if (isValid ())
101+ {
102+ _env->CallVoidMethod (_cvsView, _env->GetMethodID (_env->GetObjectClass (_cvsView), " DrawFilledRect" , " (Landroid/graphics/Canvas;IIIIFFFF)V" ), _cvs, (int ) atoi (" 157" ), (int ) color.r , (int ) color.g , (int ) color.b , rect.x , rect.y , rect.w , rect.h );
103+ }
104+ return ;
105+ }
106+
107+ void DrawFilledRect (Color color, Rect rect)
108+ {
109+ if (isValid ())
110+ {
111+ _env->CallVoidMethod (_cvsView, _env->GetMethodID (_env->GetObjectClass (_cvsView), " DrawFilledRect" , " (Landroid/graphics/Canvas;IIIIFFFF)V" ), _cvs, (int ) color.a , (int ) color.r ,(int ) color.g , (int ) color.b , rect.x , rect.y , rect.w , rect.h );
112+ }
113+ return ;
114+ }
115+
116+ void DrawFilledCircle (Color color, Vector2 pos, float radius)
117+ {
118+ if (isValid ())
119+ {
120+ _env->CallVoidMethod (_cvsView, _env->GetMethodID (_env->GetObjectClass (_cvsView), " DrawFilledCircle" , " (Landroid/graphics/Canvas;IIIIFFF)V" ), _cvs, (int ) color.a , (int ) color.r , (int ) color.g , (int ) color.b , pos.X , pos.Y , radius);
121+ }
122+ return ;
123+ }
124+
125+ void DrawBox (Color color, float stroke, Rect rect)
126+ {
127+ Vector2 v1 = Vector2 (rect.x , rect.y );
128+ Vector2 v2 = Vector2 (rect.x + rect.w , rect.y );
129+ Vector2 v3 = Vector2 (rect.x + rect.w , rect.y + rect.h );
130+ Vector2 v4 = Vector2 (rect.x , rect.y + rect.h );
131+
132+ DrawLine (color, stroke, v1, v2); // LINE UP
133+ DrawLine (color, stroke, v2, v3); // LINE RIGHT
134+ DrawLine (color, stroke, v3, v4); // LINE DOWN
135+ DrawLine (color, stroke, v4, v1); // LINE LEFT
136+ }
137+
138+ void DrawCornerBox (Color color, float stroke, Rect rect, int cx, int cy)
139+ {
140+ DrawLine (color, stroke, Vector2 (rect.x , rect.y ), Vector2 (rect.x + (rect.w / cx), rect.y ));
141+ DrawLine (color, stroke, Vector2 (rect.x , rect.y ), Vector2 (rect.x , rect.y + (rect.h / cy)));
142+
143+ DrawLine (color, stroke, Vector2 (rect.x + rect.w , rect.y ), Vector2 (rect.x + rect.w - (rect.w / cx), rect.y ));
144+ DrawLine (color, stroke, Vector2 (rect.x + rect.w , rect.y ), Vector2 (rect.x + rect.w , rect.y + (rect.h / cy)));
145+
146+ DrawLine (color, stroke, Vector2 (rect.x , rect.y + rect.h ), Vector2 (rect.x + (rect.w / cx), rect.y + rect.h ));
147+ DrawLine (color, stroke, Vector2 (rect.x , rect.y + rect.h ), Vector2 (rect.x , rect.y + rect.h - (rect.h / cy)));
148+
149+ DrawLine (color, stroke, Vector2 (rect.x + rect.w , rect.y + rect.h ), Vector2 (rect.x + rect.w - (rect.w / cx), rect.y + rect.h ));
150+ DrawLine (color, stroke, Vector2 (rect.x + rect.w , rect.y + rect.h ), Vector2 (rect.x + rect.w , rect.y + rect.h - (rect.h / cy)));
151+ }
152+ };
153+
154+ #endif
0 commit comments