diff --git a/include/parts.h b/include/parts.h index 8d6426c..6f0e28b 100644 --- a/include/parts.h +++ b/include/parts.h @@ -100,7 +100,15 @@ bool PE_IsExist(int parts_no); bool PE_AddCreateToPartsConstructionProcess(int parts_no, int w, int h, int state); bool PE_AddCreatePixelOnlyToPartsConstructionProcess(int parts_no, int w, int h, int state); bool PE_AddCreateCGToProcess(int parts_no, struct string *cg_name, int state); -bool PE_AddFillAlphaColorToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int r, int g, int b, int a, int state); +bool PE_AddFillToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, + int r, int g, int b, int state); +bool PE_AddFillAlphaColorToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, + int r, int g, int b, int a, int state); +bool PE_AddFillAMapToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int a, int state); +bool PE_AddDrawCutCGToPartsConstructionProcess(int parts_no, struct string *cg_name, + int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh, int interp_type, int state); +bool PE_AddCopyCutCGToPartsConstructionProcess(int parts_no, struct string *cg_name, + int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh, int interp_type, int state); bool PE_AddCopyTextToPartsConstructionProcess(int parts_no, int x, int y, struct string *text, int type, int size, int r, int g, int b, float bold_weight, int edge_r, int edge_g, int edge_b, float edge_weight, diff --git a/src/hll/GUIEngine.c b/src/hll/GUIEngine.c index 9d61b10..5897657 100644 --- a/src/hll/GUIEngine.c +++ b/src/hll/GUIEngine.c @@ -862,14 +862,14 @@ HLL_LIBRARY(GUIEngine, HLL_EXPORT(Parts_AddCreateToPartsConstructionProcess, PE_AddCreateToPartsConstructionProcess), HLL_EXPORT(Parts_AddCreatePixelOnlyToPartsConstructionProcess, PE_AddCreatePixelOnlyToPartsConstructionProcess), HLL_EXPORT(Parts_AddCreateCGToProcess, PE_AddCreateCGToProcess), - HLL_TODO_EXPORT(Parts_AddFillToPartsConstructionProcess, GUIEngine_Parts_AddFillToPartsConstructionProcess), + HLL_EXPORT(Parts_AddFillToPartsConstructionProcess, PE_AddFillToPartsConstructionProcess), HLL_EXPORT(Parts_AddFillAlphaColorToPartsConstructionProcess, PE_AddFillAlphaColorToPartsConstructionProcess), - HLL_TODO_EXPORT(Parts_AddFillAMapToPartsConstructionProcess, GUIEngine_Parts_AddFillAMapToPartsConstructionProcess), + HLL_EXPORT(Parts_AddFillAMapToPartsConstructionProcess, PE_AddFillAMapToPartsConstructionProcess), HLL_TODO_EXPORT(Parts_AddFillWithAlphaToPartsConstructionProcess, GUIEngine_Parts_AddFillWithAlphaToPartsConstructionProcess), HLL_TODO_EXPORT(Parts_AddFillGradationHorizonToPartsConstructionProcess, GUIEngine_Parts_AddFillGradationHorizonToPartsConstructionProcess), HLL_TODO_EXPORT(Parts_AddDrawRectToPartsConstructionProcess, GUIEngine_Parts_AddDrawRectToPartsConstructionProcess), - HLL_TODO_EXPORT(Parts_AddDrawCutCGToPartsConstructionProcess, GUIEngine_Parts_AddDrawCutCGToPartsConstructionProcess), - HLL_TODO_EXPORT(Parts_AddCopyCutCGToPartsConstructionProcess, GUIEngine_Parts_AddCopyCutCGToPartsConstructionProcess), + HLL_EXPORT(Parts_AddDrawCutCGToPartsConstructionProcess, PE_AddDrawCutCGToPartsConstructionProcess), + HLL_EXPORT(Parts_AddCopyCutCGToPartsConstructionProcess, PE_AddCopyCutCGToPartsConstructionProcess), HLL_TODO_EXPORT(Parts_AddGrayFilterToPartsConstructionProcess, GUIEngine_Parts_AddGrayFilterToPartsConstructionProcess), HLL_TODO_EXPORT(Parts_AddAddFilterToPartsConstructionProcess, GUIEngine_Parts_AddAddFilterToPartsConstructionProcess), HLL_TODO_EXPORT(Parts_AddMulFilterToPartsConstructionProcess, GUIEngine_Parts_AddMulFilterToPartsConstructionProcess), diff --git a/src/parts/construction.c b/src/parts/construction.c index 9ce5bc6..c64aa19 100644 --- a/src/parts/construction.c +++ b/src/parts/construction.c @@ -35,7 +35,11 @@ void parts_cp_op_free(struct parts_cp_op *op) case PARTS_CP_CREATE: case PARTS_CP_CREATE_PIXEL_ONLY: case PARTS_CP_CG: + case PARTS_CP_FILL: case PARTS_CP_FILL_ALPHA_COLOR: + case PARTS_CP_FILL_AMAP: + case PARTS_CP_DRAW_CUT_CG: + case PARTS_CP_COPY_CUT_CG: break; case PARTS_CP_DRAW_TEXT: case PARTS_CP_COPY_TEXT: @@ -99,7 +103,23 @@ bool PE_AddCreateCGToProcess(int parts_no, struct string *cg_name, int state) return true; } -bool PE_AddFillToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int r, int g, int b, int state); +bool PE_AddFillToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int r, int g, int b, int state) +{ + if (!parts_state_valid(--state)) + return false; + + struct parts_construction_process *cproc = get_cproc(parts_no, state); + struct parts_cp_op *op = xcalloc(1, sizeof(struct parts_cp_op)); + op->type = PARTS_CP_FILL; + op->fill = (struct parts_cp_fill) { + .x = x, .y = y, .w = w, .h = h, + .r = r, .g = g, .b = b, .a = 255 + }; + + parts_add_cp_op(cproc, op); + return true; + +} bool PE_AddFillAlphaColorToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int r, int g, int b, int a, int state) { @@ -109,7 +129,7 @@ bool PE_AddFillAlphaColorToPartsConstructionProcess(int parts_no, int x, int y, struct parts_construction_process *cproc = get_cproc(parts_no, state); struct parts_cp_op *op = xcalloc(1, sizeof(struct parts_cp_op)); op->type = PARTS_CP_FILL_ALPHA_COLOR; - op->fill_alpha_color = (struct parts_cp_fill_alpha_color) { + op->fill = (struct parts_cp_fill) { .x = x, .y = y, .w = w, .h = h, .r = r, .g = g, .b = b, .a = a }; @@ -118,17 +138,82 @@ bool PE_AddFillAlphaColorToPartsConstructionProcess(int parts_no, int x, int y, return true; } -bool PE_AddFillAMapToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int a, int state); +bool PE_AddFillAMapToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int a, int state) +{ + if (!parts_state_valid(--state)) + return false; + + struct parts_construction_process *cproc = get_cproc(parts_no, state); + struct parts_cp_op *op = xcalloc(1, sizeof(struct parts_cp_op)); + op->type = PARTS_CP_FILL_AMAP; + op->fill = (struct parts_cp_fill) { + .x = x, .y = y, .w = w, .h = h, + .r = 0, .g = 0, .b = 0, .a = a + }; + + parts_add_cp_op(cproc, op); + return true; +} + bool PE_AddFillWithAlphaToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int r, int g, int b, int a, int state); bool PE_AddFillGradationHorizonToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int top_r, int top_g, int top_b, int bot_r, int bot_g, int bot_b, int state); bool PE_AddDrawRectToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, int r, int g, int b, int state); + bool PE_AddDrawCutCGToPartsConstructionProcess(int parts_no, struct string *cg_name, - int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh, int interp_type, int state); + int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh, int interp_type, int state) +{ + if (!parts_state_valid(--state)) + return false; + + int cg_no; + if (!asset_exists_by_name(ASSET_CG, cg_name->text, &cg_no)) { + WARNING("Invalid CG name: %s", display_sjis0(cg_name->text)); + return false; + } + + struct parts_construction_process *cproc = get_cproc(parts_no, state); + struct parts_cp_op *op = xcalloc(1, sizeof(struct parts_cp_op)); + op->type = PARTS_CP_DRAW_CUT_CG; + op->cut_cg = (struct parts_cp_cut_cg) { + .cg_no = cg_no, + .dx = dx, .dy = dy, .dw = dw, .dh = dh, + .sx = sx, .sy = sy, .sw = sw, .sh = sh, + .interp_type = interp_type + }; + + parts_add_cp_op(cproc, op); + return true; +} + bool PE_AddCopyCutCGToPartsConstructionProcess(int parts_no, struct string *cg_name, - int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh, int interp_type, int state); + int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh, int interp_type, int state) +{ + if (!parts_state_valid(--state)) + return false; + + int cg_no; + if (!asset_exists_by_name(ASSET_CG, cg_name->text, &cg_no)) { + WARNING("Invalid CG name: %s", display_sjis0(cg_name->text)); + return false; + } + + struct parts_construction_process *cproc = get_cproc(parts_no, state); + struct parts_cp_op *op = xcalloc(1, sizeof(struct parts_cp_op)); + op->type = PARTS_CP_COPY_CUT_CG; + op->cut_cg = (struct parts_cp_cut_cg) { + .cg_no = cg_no, + .dx = dx, .dy = dy, .dw = dw, .dh = dh, + .sx = sx, .sy = sy, .sw = sw, .sh = sh, + .interp_type = interp_type + }; + + parts_add_cp_op(cproc, op); + return true; +} + bool PE_AddGrayFilterToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, bool full_size, int state); bool PE_AddAddFilterToPartsConstructionProcess(int parts_no, int x, int y, int w, int h, @@ -222,12 +307,49 @@ static void build_cg(struct parts *parts, struct parts_construction_process *cpr cg_free(cg); } -static void build_fill_alpha_color(struct parts_construction_process *cproc, - struct parts_cp_fill_alpha_color *op) +static void build_fill(struct parts_construction_process *cproc, struct parts_cp_fill *op) +{ + gfx_fill(&cproc->common.texture, op->x, op->y, op->w, op->h, op->r, op->g, op->b); +} + +static void build_fill_alpha_color(struct parts_construction_process *cproc, struct parts_cp_fill *op) { gfx_fill_alpha_color(&cproc->common.texture, op->x, op->y, op->w, op->h, op->r, op->g, op->b, op->a); } +static void build_fill_amap(struct parts_construction_process *cproc, struct parts_cp_fill *op) +{ + gfx_fill_amap(&cproc->common.texture, op->x, op->y, op->w, op->h, op->a); +} + +static void build_draw_cut_cg(struct parts_construction_process *cproc, struct parts_cp_cut_cg *op) +{ + struct cg *cg = asset_cg_load(op->cg_no); + assert(cg); + + Texture src; + gfx_init_texture_with_cg(&src, cg); + cg_free(cg); + + gfx_copy_stretch_blend_amap(&cproc->common.texture, op->dx, op->dy, op->dw, op->dh, + &src, op->sx, op->sy, op->sw, op->sh); + gfx_delete_texture(&src); +} + +static void build_copy_cut_cg(struct parts_construction_process *cproc, struct parts_cp_cut_cg *op) +{ + struct cg *cg = asset_cg_load(op->cg_no); + assert(cg); + + Texture src; + gfx_init_texture_with_cg(&src, cg); + cg_free(cg); + + gfx_copy_stretch_with_alpha_map(&cproc->common.texture, op->dx, op->dy, op->dw, op->dh, + &src, op->sx, op->sy, op->sw, op->sh); + gfx_delete_texture(&src); +} + static void build_draw_text(struct parts_construction_process *cproc, struct parts_cp_text *op) { gfx_render_text(&cproc->common.texture, op->x, op->y, op->text->text, &op->style); @@ -261,8 +383,20 @@ bool PE_BuildPartsConstructionProcess(int parts_no, int state) case PARTS_CP_CG: build_cg(parts, cproc, &op->cg); break; + case PARTS_CP_FILL: + build_fill(cproc, &op->fill); + break; case PARTS_CP_FILL_ALPHA_COLOR: - build_fill_alpha_color(cproc, &op->fill_alpha_color); + build_fill_alpha_color(cproc, &op->fill); + break; + case PARTS_CP_FILL_AMAP: + build_fill_amap(cproc, &op->fill); + break; + case PARTS_CP_DRAW_CUT_CG: + build_draw_cut_cg(cproc, &op->cut_cg); + break; + case PARTS_CP_COPY_CUT_CG: + build_copy_cut_cg(cproc, &op->cut_cg); break; case PARTS_CP_DRAW_TEXT: build_draw_text(cproc, &op->text); diff --git a/src/parts/debug.c b/src/parts/debug.c index 6efddad..a7fa254 100644 --- a/src/parts/debug.c +++ b/src/parts/debug.c @@ -84,7 +84,11 @@ static void parts_construction_process_print(struct parts_construction_process * [PARTS_CP_CREATE] = "PARTS_CP_CREATE", [PARTS_CP_CREATE_PIXEL_ONLY] = "PARTS_CP_CREATE_PIXEL_ONLY", [PARTS_CP_CG] = "PARTS_CP_CG", + [PARTS_CP_FILL] = "PARTS_CP_FILL", [PARTS_CP_FILL_ALPHA_COLOR] = "PARTS_CP_FILL_ALPHA_COLOR", + [PARTS_CP_FILL_AMAP] = "PARTS_CP_FILL_AMAP", + [PARTS_CP_DRAW_CUT_CG] = "PARTS_CP_DRAW_CUT_CG", + [PARTS_CP_COPY_CUT_CG] = "PARTS_CP_COPY_CUT_CG", [PARTS_CP_DRAW_TEXT] = "PARTS_CP_DRAW_TEXT", [PARTS_CP_COPY_TEXT] = "PARTS_CP_COPY_TEXT", }; @@ -111,13 +115,22 @@ static void parts_construction_process_print(struct parts_construction_process * case PARTS_CP_CG: indent_printf(indent, "cg.no = %d\n", op->cg.no); break; + case PARTS_CP_FILL: case PARTS_CP_FILL_ALPHA_COLOR: - indent_printf(indent, "fill_alpha_color.rect = {x=%d,y=%d,w=%d,h=%d},\n", - op->fill_alpha_color.x, op->fill_alpha_color.y, - op->fill_alpha_color.w, op->fill_alpha_color.h); - indent_printf(indent, "fill_alpha_color.color = (%d,%d,%d,%d)\n", - op->fill_alpha_color.r, op->fill_alpha_color.g, - op->fill_alpha_color.b, op->fill_alpha_color.a); + case PARTS_CP_FILL_AMAP: + indent_printf(indent, "fill.rect = {x=%d,y=%d,w=%d,h=%d},\n", + op->fill.x, op->fill.y, op->fill.w, op->fill.h); + indent_printf(indent, "fill.color = (%d,%d,%d,%d)\n", + op->fill.r, op->fill.g, op->fill.b, op->fill.a); + break; + case PARTS_CP_DRAW_CUT_CG: + case PARTS_CP_COPY_CUT_CG: + indent_printf(indent, "cut_cg.cg_no = %d,\n", op->cut_cg.cg_no); + indent_printf(indent, "cut_cg.dst = {x=%d,y=%d,w=%d,h=%d},\n", + op->cut_cg.dx, op->cut_cg.dy, op->cut_cg.dw, op->cut_cg.dh); + indent_printf(indent, "cut_cg.src = {x=%d,y=%d,w=%d,h=%d},\n", + op->cut_cg.sx, op->cut_cg.sy, op->cut_cg.sw, op->cut_cg.sh); + indent_printf(indent, "cut_cg.interp_type = %d\n", op->cut_cg.interp_type); break; case PARTS_CP_DRAW_TEXT: case PARTS_CP_COPY_TEXT: @@ -396,9 +409,21 @@ static void parts_list_print(struct parts *parts, int indent) case PARTS_CP_CG: printf(" cg"); break; + case PARTS_CP_FILL: + printf(" fill"); + break; case PARTS_CP_FILL_ALPHA_COLOR: printf(" fill-alpha-color"); break; + case PARTS_CP_FILL_AMAP: + printf(" fill-amap"); + break; + case PARTS_CP_DRAW_CUT_CG: + printf(" draw-cut-cg"); + break; + case PARTS_CP_COPY_CUT_CG: + printf(" copy-cut-cg"); + break; case PARTS_CP_DRAW_TEXT: printf(" draw-text"); break; diff --git a/src/parts/parts_internal.h b/src/parts/parts_internal.h index 1833bf1..b99f83b 100644 --- a/src/parts/parts_internal.h +++ b/src/parts/parts_internal.h @@ -137,7 +137,11 @@ enum parts_cp_op_type { PARTS_CP_CREATE, PARTS_CP_CREATE_PIXEL_ONLY, PARTS_CP_CG, + PARTS_CP_FILL, PARTS_CP_FILL_ALPHA_COLOR, + PARTS_CP_FILL_AMAP, + PARTS_CP_DRAW_CUT_CG, + PARTS_CP_COPY_CUT_CG, PARTS_CP_DRAW_TEXT, PARTS_CP_COPY_TEXT, #define PARTS_NR_CP_TYPES (PARTS_CP_COPY_TEXT+1) @@ -152,11 +156,18 @@ struct parts_cp_cg { int no; }; -struct parts_cp_fill_alpha_color { +struct parts_cp_fill { int x, y, w, h; int r, g, b, a; }; +struct parts_cp_cut_cg { + int cg_no; + int dx, dy, dw, dh; + int sx, sy, sw, sh; + int interp_type; +}; + struct parts_cp_text { struct string *text; int x, y; @@ -170,7 +181,8 @@ struct parts_cp_op { union { struct parts_cp_create create; struct parts_cp_cg cg; - struct parts_cp_fill_alpha_color fill_alpha_color; + struct parts_cp_fill fill; + struct parts_cp_cut_cg cut_cg; struct parts_cp_text text; }; };