diff --git a/modules/NIGHTDLL/nt_msg.c b/modules/NIGHTDLL/nt_msg.c index 6b94f5a..ee9159a 100644 --- a/modules/NIGHTDLL/nt_msg.c +++ b/modules/NIGHTDLL/nt_msg.c @@ -438,50 +438,35 @@ static void hakanim(int i) { } void ntmsg_update(sprite_t *sp, MyRectangle *r) { - int sx, sy, w, h, dx, dy; - surface_t update; - - // canvas が clean のときはなにもしない - // -> 説明スプライトのように、SetShowされたときに対応できないからだめ - //if (sact.msgbufempty) return; - - update.width = r->w; - update.height = r->h; - - dx = sp->cur.x - r->x; - dy = sp->cur.y - r->y; - - w = sp->cursize.width; - h = sp->cursize.height; - - sx = 0; sy = 0; - - if (!gr_clip(sp->u.msg.canvas, &sx, &sy, &w, &h, &update, &dx, &dy)) { + SDL_Rect sp_rect = {0, 0, sp->cursize.width, sp->cursize.height}; + int sx = 0; + int sy = 0; + int dx = sp->cur.x; + int dy = sp->cur.y; + int w = sp->cursize.width; + int h = sp->cursize.height; + if (!ags_clipCopyRect(&sp_rect, r, &sx, &sy, &dx, &dy, &w, &h)) { return; } - - dx += r->x; - dy += r->y; - - gre_BlendUseAMap(sf0, dx, dy, sf0, dx, dy, sp->u.msg.canvas, sx, sy, w, h, sp->u.msg.canvas, sx, sy, sp->blendrate); - + + SDL_SetSurfaceBlendMode(sp->u.msg.canvas, SDL_BLENDMODE_BLEND); + SDL_SetSurfaceAlphaMod(sp->u.msg.canvas, sp->blendrate); + SDL_BlitSurface(sp->u.msg.canvas, &(SDL_Rect){sx, sy, w, h}, sf0->sdl_surface, &(SDL_Rect){dx, dy, w, h}); + SACT_DEBUG("do update no=%d, sx=%d, sy=%d, w=%d, h=%d, dx=%d, dy=%d", sp->no, sx, sy, w, h, dx, dy); } static void ntmsg_clear(int wNum) { sprite_t *sp = night.sp[wNum]; - surface_t *sf; - + sp->u.msg.dspcur.x = 0; sp->u.msg.dspcur.y = 0; night.msgbuf[0] = '\0'; - - // キャンバスのクリア - sf = sp->u.msg.canvas; - memset(sf->pixel, 0, sf->bytes_per_line * sf->height); - memset(sf->alpha, 0, sf->width * sf->height); - + + // Clear the canvas + SDL_FillRect(sp->u.msg.canvas, NULL, 0); + nt_sp_updateme(sp); } diff --git a/modules/NIGHTDLL/sprite.c b/modules/NIGHTDLL/sprite.c index ee2960c..91927c0 100644 --- a/modules/NIGHTDLL/sprite.c +++ b/modules/NIGHTDLL/sprite.c @@ -64,7 +64,7 @@ sprite_t *nt_sp_msg_new(int no, int x, int y, int width, int height) { sp->cursize.height = height; sp->u.msg.dspcur.x = 0; sp->u.msg.dspcur.y = 0; - sp->u.msg.canvas = sf_create_surface(width, height, sf0->depth); + sp->u.msg.canvas = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_ARGB8888); sp->update = ntmsg_update; return sp; @@ -78,7 +78,7 @@ void nt_sp_free(sprite_t *sp) { if (sp->cg3) nt_scg_deref(sp->cg3); if (sp->type == SPRITE_MSG) { - sf_free(sp->u.msg.canvas); + SDL_FreeSurface(sp->u.msg.canvas); } free(sp); diff --git a/modules/NIGHTDLL/sprite.h b/modules/NIGHTDLL/sprite.h index f9abdd8..cf48a31 100644 --- a/modules/NIGHTDLL/sprite.h +++ b/modules/NIGHTDLL/sprite.h @@ -3,7 +3,6 @@ #define __SPRITE_H__ #include "portab.h" -#include "surface.h" #include "graphics.h" #define DEFAULT_UPDATE nt_sp_draw @@ -97,7 +96,7 @@ struct _sprite { } anime; struct { - surface_t *canvas; + struct SDL_Surface *canvas; MyPoint dspcur; } msg; } u; diff --git a/modules/SACT/sact.h b/modules/SACT/sact.h index c373f11..f849238 100644 --- a/modules/SACT/sact.h +++ b/modules/SACT/sact.h @@ -190,7 +190,7 @@ struct _sprite { // メッセージスプライト struct { SList *buf; // 表示する文字のリスト - surface_t *canvas; // 文字を描画するsurface + struct SDL_Surface *canvas; MyPoint dspcur; // 現在の表示位置 } msg; } u; diff --git a/modules/SACT/sprite.c b/modules/SACT/sprite.c index 5dba24e..adebac0 100644 --- a/modules/SACT/sprite.c +++ b/modules/SACT/sprite.c @@ -216,10 +216,10 @@ void sp_new_msg(int no, int x, int y, int width, int height) { sp->cursize.height = height; sp->cur = sp->loc; sp->u.msg.buf = NULL; - - // 文字描画用キャンバス - sp->u.msg.canvas = sf_create_surface(width, height, sf0->depth); - + + // canvas for drawing text + sp->u.msg.canvas = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_ARGB8888); + // スプライト再描画用コールバック sp->update = smsg_update; } @@ -290,7 +290,7 @@ void sp_free(int no) { if (sp->type == SPRITE_MSG) { slist_free(sp->u.msg.buf); - sf_free(sp->u.msg.canvas); + SDL_FreeSurface(sp->u.msg.canvas); } sact.updatelist = slist_remove(sact.updatelist, sp); diff --git a/modules/SACT/sprite_msg.c b/modules/SACT/sprite_msg.c index 27209fc..f688f7b 100644 --- a/modules/SACT/sprite_msg.c +++ b/modules/SACT/sprite_msg.c @@ -352,24 +352,19 @@ void smsg_out(int wNum, int wSize, int wColorR, int wColorG, int wColorB, int wF @param wNum: クリアするスプライト番号 */ void smsg_clear(int wNum) { - sprite_t *sp; - surface_t *sf; - if (!is_messagesprite(wNum)) return; // 表示位置の初期化 - sp = sact.sp[wNum]; + sprite_t *sp = sact.sp[wNum]; sp->u.msg.dspcur.x = 0; sp->u.msg.dspcur.y = 0; sact.msgbuf[0] = '\0'; sact.msgbuf2[0] = '\0'; - - // キャンバスのクリア - sf = sp->u.msg.canvas; - memset(sf->pixel, 0, sf->bytes_per_line * sf->height); - memset(sf->alpha, 0, sf->width * sf->height); - + + // Clear the canvas + SDL_FillRect(sp->u.msg.canvas, NULL, 0); + sp_updateme(sp); if (sact.logging) { @@ -453,32 +448,19 @@ int smsg_keywait(int wNum1, int wNum2, int msglen) { @param sp: 再描画するスプライト */ void smsg_update(sprite_t *sp) { - int sx, sy, w, h, dx, dy; - surface_t update; - - // canvas が clean のときはなにもしない - // -> 説明スプライトのように、SetShowされたときに対応できないからだめ - //if (sact.msgbufempty) return; - - update.width = sact.updaterect.w; - update.height = sact.updaterect.h; - - dx = sp->cur.x - sact.updaterect.x; - dy = sp->cur.y - sact.updaterect.y; - - w = sp->cursize.width; - h = sp->cursize.height; - - sx = 0; sy = 0; - - if (!gr_clip(sp->u.msg.canvas, &sx, &sy, &w, &h, &update, &dx, &dy)) { + SDL_Rect sp_rect = {0, 0, sp->cursize.width, sp->cursize.height}; + int sx = 0; + int sy = 0; + int dx = sp->cur.x; + int dy = sp->cur.y; + int w = sp->cursize.width; + int h = sp->cursize.height; + if (!ags_clipCopyRect(&sp_rect, &sact.updaterect, &sx, &sy, &dx, &dy, &w, &h)) { return; } - - dx += sact.updaterect.x; - dy += sact.updaterect.y; - - gre_BlendUseAMap(sf0, dx, dy, sf0, dx, dy, sp->u.msg.canvas, sx, sy, w, h, sp->u.msg.canvas, sx, sy, sp->blendrate); + SDL_SetSurfaceBlendMode(sp->u.msg.canvas, SDL_BLENDMODE_BLEND); + SDL_SetSurfaceAlphaMod(sp->u.msg.canvas, sp->blendrate); + SDL_BlitSurface(sp->u.msg.canvas, &(SDL_Rect){sx, sy, w, h}, sf0->sdl_surface, &(SDL_Rect){dx, dy, w, h}); SACT_DEBUG("do update no=%d, sx=%d, sy=%d, w=%d, h=%d, dx=%d, dy=%d", sp->no, sx, sy, w, h, dx, dy); diff --git a/modules/lib/drawtext.c b/modules/lib/drawtext.c index 2ec5414..be2d251 100644 --- a/modules/lib/drawtext.c +++ b/modules/lib/drawtext.c @@ -69,10 +69,10 @@ int dt_drawtext(SDL_Surface *sf, int x, int y, char *buf) { SDL_Surface *glyph = ags_drawStringToSurface(buf); if (glyph == NULL) return 0; - SDL_Rect r = {x, y, glyph->w, glyph->h}; - SDL_BlitSurface(glyph, NULL, sf, &r); + SDL_Rect rect = {x, y, glyph->w, glyph->h}; + SDL_BlitSurface(glyph, NULL, sf, &rect); SDL_FreeSurface(glyph); - return glyph->w; + return rect.w; } /** @@ -88,24 +88,13 @@ int dt_drawtext(SDL_Surface *sf, int x, int y, char *buf) { * @param b: 文字色青 * @return: 実際に描画した幅 */ -int dt_drawtext_col(surface_t *sf, int x, int y, char *buf, int r, int g, int b) { - int sx, sy, sw, sh; - +int dt_drawtext_col(SDL_Surface *sf, int x, int y, char *buf, int r, int g, int b) { ags_setFont(ftype, fsize); - SDL_Surface *glyph = ags_drawStringToSurface(buf); + SDL_Surface *glyph = ags_drawStringToRGBASurface(buf, r, g, b); if (glyph == NULL) return 0; - sx = x; sy = y; - sw = glyph->w; - sh = glyph->h; - if (!gr_clip_xywh(sf, &sx, &sy, &sw, &sh)) return 0; - - // alpha map に文字そのものを描く - gr_draw_amap(sf, sx, sy, glyph->pixels, sw, sh, glyph->pitch); - - // pixel map には色情報を矩形で描く - gr_fill(sf, sx, sy, sw, sh, r, g, b); - + SDL_Rect rect = {x, y, glyph->w, glyph->h}; + SDL_BlitSurface(glyph, NULL, sf, &rect); SDL_FreeSurface(glyph); - return sw; + return rect.w; } diff --git a/modules/lib/drawtext.h b/modules/lib/drawtext.h index 75bf731..1c74903 100644 --- a/modules/lib/drawtext.h +++ b/modules/lib/drawtext.h @@ -30,6 +30,6 @@ struct SDL_Surface; void dt_setfont(FontType type, int size); int dt_drawtext(struct SDL_Surface *sf, int x, int y, char *buf); -int dt_drawtext_col(surface_t *sf, int x, int y, char *buf, int r, int g, int b); +int dt_drawtext_col(struct SDL_Surface *sf, int x, int y, char *buf, int r, int g, int b); #endif /* __DRAWTEXT_H__ */