109 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			109 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名: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);
 | |
|     }
 | |
| 
 | |
|     //绘制演员
 | |
|     function DrawActor(Actor, XPos, YPos) {
 | |
|         if (!Context) error("请先刷新上下文");
 | |
|         Canvas_DrawActor(this.C_Object, Context, Actor.C_Object, XPos, YPos);
 | |
|     }
 | |
| 
 | |
|     //绘制精灵帧
 | |
|     function DrawSpriteFrame(SpriteFrame, XPos, YPos, Width = null, Height = null) {
 | |
|         if (!Context) error("请先刷新上下文");
 | |
|         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);
 | |
|     }
 | |
| 
 | |
|     //设置填充画刷
 | |
|     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);
 | |
|     }
 | |
| } |