| 
									
										
										
										
											2025-01-04 20:03:17 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 文件名:CanvasObject.nut | 
					
						
							|  |  |  | 路径:Core/BaseClass/CanvasObject.nut | 
					
						
							|  |  |  | 创建日期:2025-01-05	21:43 | 
					
						
							|  |  |  | 文件用途:画布类 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | class CL_CanvasObject extends CL_BaseObject { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //宽 | 
					
						
							|  |  |  |     CanvasWidth = 0; | 
					
						
							|  |  |  |     //高 | 
					
						
							|  |  |  |     CanvasHeight = 0; | 
					
						
							|  |  |  |     //上下文 | 
					
						
							|  |  |  |     Context = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function _typeof() { | 
					
						
							|  |  |  |         return "canvas"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(...) { | 
					
						
							|  |  |  |         local C_Object; | 
					
						
							|  |  |  |         //创建空精灵 | 
					
						
							|  |  |  |         if (vargv.len() == 0) { | 
					
						
							|  |  |  |             C_Object = Canvas_Create(); | 
					
						
							|  |  |  |             base.constructor(C_Object); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         //通过精灵指针创建 | 
					
						
							|  |  |  |         else if (vargv.len() == 1) { | 
					
						
							|  |  |  |             C_Object = vargv[0]; | 
					
						
							|  |  |  |             base.constructor(C_Object, true); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //重设大小并清空 | 
					
						
							|  |  |  |     function ResizeAndClear(W, H) { | 
					
						
							|  |  |  |         CanvasWidth = W; | 
					
						
							|  |  |  |         CanvasHeight = H; | 
					
						
							|  |  |  |         Canvas_ResizeAndClear(this.C_Object, W, H); | 
					
						
							|  |  |  |         RefreshContext(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //清空画布 | 
					
						
							|  |  |  |     function Clear() { | 
					
						
							|  |  |  |         Canvas_ResizeAndClear(this.C_Object, CanvasWidth, CanvasHeight); | 
					
						
							|  |  |  |         RefreshContext(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //刷新上下文 | 
					
						
							|  |  |  |     function RefreshContext() { | 
					
						
							|  |  |  |         Context = Canvas_GetContext2D(this.C_Object); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //开始绘制 | 
					
						
							|  |  |  |     function BeginDraw() { | 
					
						
							|  |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							|  |  |  |         Canvas_BeginDraw(Context); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //结束绘制 | 
					
						
							|  |  |  |     function EndDraw() { | 
					
						
							|  |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							|  |  |  |         Canvas_EndDraw(Context); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //绘制演员 | 
					
						
							| 
									
										
										
										
											2025-01-08 13:49:58 +08:00
										 |  |  |     function DrawActor(Actor, XPos = 0, YPos = 0) { | 
					
						
							| 
									
										
										
										
											2025-01-04 20:03:17 +08:00
										 |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							|  |  |  |         Canvas_DrawActor(this.C_Object, Context, Actor.C_Object, XPos, YPos); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-08 13:49:58 +08:00
										 |  |  |     //绘制精灵 | 
					
						
							|  |  |  |     function DrawSprite(Actor, XPos = 0, YPos = 0) { | 
					
						
							|  |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							|  |  |  |         Canvas_DrawSprite(this.C_Object, Context, Actor.C_Object, XPos, YPos); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-04 20:03:17 +08:00
										 |  |  |     //绘制精灵帧 | 
					
						
							| 
									
										
										
										
											2025-01-06 21:10:06 +08:00
										 |  |  |     function DrawSpriteFrame(SpriteFrame, XPos, YPos, Width = null, Height = null) { | 
					
						
							| 
									
										
										
										
											2025-01-04 20:03:17 +08:00
										 |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							| 
									
										
										
										
											2025-01-06 21:10:06 +08:00
										 |  |  |         local Size = SpriteFrame.GetSize(); | 
					
						
							|  |  |  |         if (Width == null) Width = Size.w; | 
					
						
							|  |  |  |         if (Height == null) Height = Size.h; | 
					
						
							|  |  |  |         Canvas_DrawSpriteFrame(Context, SpriteFrame.C_Object, XPos, YPos, Width, Height); | 
					
						
							| 
									
										
										
										
											2025-01-04 20:03:17 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //设置填充画刷 | 
					
						
							|  |  |  |     function SetFillBrush(Color) { | 
					
						
							|  |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							|  |  |  |         Canvas_SetFillBrush(Context, Color); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //设置轮廓画刷 | 
					
						
							|  |  |  |     function SetStrokeBrush(Color) { | 
					
						
							|  |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							|  |  |  |         Canvas_SetStrokeBrush(Context, Color); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //画线段 | 
					
						
							|  |  |  |     function DrawLine(X1, Y1, X2, Y2) { | 
					
						
							|  |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							|  |  |  |         Canvas_DrawLine(Context, X1, Y1, X2, Y2); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //画圆 | 
					
						
							|  |  |  |     function DrawCircle(X, Y, R) { | 
					
						
							|  |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							|  |  |  |         Canvas_DrawCircle(Context, X, Y, R); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //画矩形 | 
					
						
							|  |  |  |     function DrawRect(X, Y, W, H) { | 
					
						
							|  |  |  |         if (!Context) error("请先刷新上下文"); | 
					
						
							|  |  |  |         Canvas_DrawRect(Context, X, Y, W, H); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |