comparison window/picture.cc @ 65:4416cfac86ae

Convert EUC-JP files to UTF8
author Thibaut Girka <thib@sitedethib.com>
date Fri, 26 Nov 2010 10:53:15 +0100
parents e16e13d8cd68
children 1fd20d231376
comparison
equal deleted inserted replaced
64:045ca45f9610 65:4416cfac86ae
43 43
44 /* render.cc */ 44 /* render.cc */
45 void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect); 45 void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect);
46 void DSurfaceBlitAdd(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect, unsigned char alpha); 46 void DSurfaceBlitAdd(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect, unsigned char alpha);
47 void DSurfaceBlitMultiply(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect); 47 void DSurfaceBlitMultiply(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect);
48 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a=0xff); // ꥢ 48 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a=0xff); // クリア
49 #if 0 /* DEBUG */ 49 #if 0 /* DEBUG */
50 #include<sys/types.h> 50 #include<sys/types.h>
51 #include<sys/time.h> 51 #include<sys/time.h>
52 #define dprintf printf 52 #define dprintf printf
53 static struct timeval tv; 53 static struct timeval tv;
99 } 99 }
100 if (surface_back != NULL) root->DeleteSurface(surface_back); 100 if (surface_back != NULL) root->DeleteSurface(surface_back);
101 if (surface_own != NULL && (attribute & SURFACE_FREE)) root->DeleteSurface(surface_own); 101 if (surface_own != NULL && (attribute & SURFACE_FREE)) root->DeleteSurface(surface_own);
102 if (surface_alpha != NULL && (attribute & ALPHA_FREE)) delete surface_alpha; 102 if (surface_alpha != NULL && (attribute & ALPHA_FREE)) delete surface_alpha;
103 iterator it; 103 iterator it;
104 if (parent) { // ʬƤ 104 if (parent) { // 自分を親から削除
105 parent->children.remove(this); 105 parent->children.remove(this);
106 // root update 󤫤鼫ʬ 106 // root の update 情報から自分を削除
107 parent->Root().DeleteUpdatePic(this); 107 parent->Root().DeleteUpdatePic(this);
108 // ʬΰľ 108 // 自分の領域を書き直す
109 Rect old_ppos = rel_pos; 109 Rect old_ppos = rel_pos;
110 parent->QueryAbsPos(old_ppos); 110 parent->QueryAbsPos(old_ppos);
111 parent->ReBlit(old_ppos); 111 parent->ReBlit(old_ppos);
112 } 112 }
113 } 113 }
114 114
115 void PicBase::Blit(const Rect& rpos_orig) { 115 void PicBase::Blit(const Rect& rpos_orig) {
116 // ºݤ褹ΰ 116 // 実際に描画する領域を得る
117 Rect rpos = rpos_orig; 117 Rect rpos = rpos_orig;
118 // widgetꤵ줿clip area ꤹ 118 // 親widget上に設定されたclip area 内に描画を限定する
119 if (clip_area.width() != 0) { 119 if (clip_area.width() != 0) {
120 Rect clip = clip_area; 120 Rect clip = clip_area;
121 clip = child_pos(clip, this); 121 clip = child_pos(clip, this);
122 rpos.intersect(clip); 122 rpos.intersect(clip);
123 } 123 }
124 Rect apos = QueryAbsPos(rpos); 124 Rect apos = QueryAbsPos(rpos);
125 if (rpos.empty()) return; 125 if (rpos.empty()) return;
126 // ɬפ˱¸ 126 // 必要に応じて保存、描画
127 if (attribute & CACHE_BACK) root->BlitSurface(root->surface, apos, surface_back, rpos); 127 if (attribute & CACHE_BACK) root->BlitSurface(root->surface, apos, surface_back, rpos);
128 if (! (attribute & NO_PICTURE)) { 128 if (! (attribute & NO_PICTURE)) {
129 rpos.rmove(surface_x, surface_y); 129 rpos.rmove(surface_x, surface_y);
130 if (surface_w >= 0 && surface_h >= 0) { 130 if (surface_w >= 0 && surface_h >= 0) {
131 Rect clip(surface_x, surface_y, surface_x+surface_w, surface_y+surface_h); 131 Rect clip(surface_x, surface_y, surface_x+surface_w, surface_y+surface_h);
132 rpos.intersect(clip); 132 rpos.intersect(clip);
133 } 133 }
134 //if (apos.ty < 200) fprintf(stderr,"Blit: %p : (%d,%d,%d,%d) -> (%d,%d,%d,%d)\n",surface_own,rpos_orig.lx,rpos_orig.ty,rpos_orig.rx,rpos_orig.by,apos.lx,apos.ty,apos.rx,apos.by); 134 //if (apos.ty < 200) fprintf(stderr,"Blit: %p : (%d,%d,%d,%d) -> (%d,%d,%d,%d)\n",surface_own,rpos_orig.lx,rpos_orig.ty,rpos_orig.rx,rpos_orig.by,apos.lx,apos.ty,apos.rx,apos.by);
135 root->BlitSurface(surface_own, rpos, surface_alpha, surface_alpha_rect, root->surface, apos, attribute); 135 root->BlitSurface(surface_own, rpos, surface_alpha, surface_alpha_rect, root->surface, apos, attribute);
136 rpos.rmove(-surface_x, -surface_y); 136 rpos.rmove(-surface_x, -surface_y);
137 } else if (parent == 0) { // ƤʤʤطʾõǤ 137 } else if (parent == 0) { // 親がいないなら背景消去の責任をもつ
138 DSurfaceFill(root->surface, apos, 0, 0, 0); 138 DSurfaceFill(root->surface, apos, 0, 0, 0);
139 } 139 }
140 PicContainer* cur = dynamic_cast<PicContainer*>(this); 140 PicContainer* cur = dynamic_cast<PicContainer*>(this);
141 if (cur && (!cur->children.empty())) { 141 if (cur && (!cur->children.empty())) {
142 cur->BlitChildren(rpos); 142 cur->BlitChildren(rpos);
143 } 143 }
144 } 144 }
145 145
146 void PicBase::SimpleBlit(Surface* screen) { 146 void PicBase::SimpleBlit(Surface* screen) {
147 // ºݤ褹ΰ 147 // 実際に描画する領域を得る
148 Rect rpos(0, 0, rel_pos.width(), rel_pos.height()); 148 Rect rpos(0, 0, rel_pos.width(), rel_pos.height());
149 Rect apos = QueryAbsPos(rpos); 149 Rect apos = QueryAbsPos(rpos);
150 if (rpos.empty()) return; 150 if (rpos.empty()) return;
151 rpos.rmove(surface_x, surface_y); 151 rpos.rmove(surface_x, surface_y);
152 if (surface_w >= 0 && surface_h >= 0) { 152 if (surface_w >= 0 && surface_h >= 0) {
160 Rect PicBase::QueryAbsPos(Rect& rpos) { 160 Rect PicBase::QueryAbsPos(Rect& rpos) {
161 rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height())); 161 rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height()));
162 if (parent == NULL) { // root container 162 if (parent == NULL) { // root container
163 return rpos; 163 return rpos;
164 } 164 }
165 // ƤκɸѴ塢Query 165 // 親の座標に変換後、Query する
166 Rect ppos = parent_pos(rpos); 166 Rect ppos = parent_pos(rpos);
167 Rect apos = parent->QueryAbsPos(ppos); 167 Rect apos = parent->QueryAbsPos(ppos);
168 rpos = child_pos(ppos, this); 168 rpos = child_pos(ppos, this);
169 return apos; 169 return apos;
170 } 170 }
198 return; 198 return;
199 } else if (move_to && move_to->parent != parent) { 199 } else if (move_to && move_to->parent != parent) {
200 fprintf(stderr,"Error: PicBase::ZMove was called with a no-brother picture\n"); 200 fprintf(stderr,"Error: PicBase::ZMove was called with a no-brother picture\n");
201 return; 201 return;
202 } 202 }
203 // move_to zpos Τ picture 񤭤ʤɬפ 203 // move_to と zpos のうち、後ろの方の picture から書きなおす必要がある
204 iterator redraw_zpos = z_pos; redraw_zpos++; 204 iterator redraw_zpos = z_pos; redraw_zpos++;
205 if (move_to == ZMOVE_BOTTOM) { // ̤ 205 if (move_to == ZMOVE_BOTTOM) { // 最背面へ
206 parent->children.erase(z_pos); 206 parent->children.erase(z_pos);
207 parent->children.push_front(this); 207 parent->children.push_front(this);
208 z_pos = parent->children.begin(); 208 z_pos = parent->children.begin();
209 redraw_zpos = parent->children.begin(); 209 redraw_zpos = parent->children.begin();
210 } else if (move_to == ZMOVE_TOP) { // ̤ 210 } else if (move_to == ZMOVE_TOP) { // 最前面へ
211 redraw_zpos = z_pos; redraw_zpos++; 211 redraw_zpos = z_pos; redraw_zpos++;
212 parent->children.erase(z_pos); 212 parent->children.erase(z_pos);
213 parent->children.push_back(this); 213 parent->children.push_back(this);
214 z_pos = parent->children.end(); z_pos--; 214 z_pos = parent->children.end(); z_pos--;
215 } else { 215 } else {
222 z_pos = move_to->z_pos; z_pos++; 222 z_pos = move_to->z_pos; z_pos++;
223 } 223 }
224 if (! is_hidden_now) { 224 if (! is_hidden_now) {
225 is_cached = false; 225 is_cached = false;
226 ReBlit(); 226 ReBlit();
227 /* @@@ parent->Blit() Blit() ΰ㤤ʬʤΤǽ 06/12/02 227 /* @@@ parent->Blit() と Blit() の違いが分からないので修正 06/12/02
228 Rect ppos = rel_pos; 228 Rect ppos = rel_pos;
229 parent->QueryAbsPos(ppos); 229 parent->QueryAbsPos(ppos);
230 parent->ReBlit(ppos); 230 parent->ReBlit(ppos);
231 */ 231 */
232 } 232 }
270 if (parent == to) return true; 270 if (parent == to) return true;
271 return parent->IsParent(to); 271 return parent->IsParent(to);
272 } 272 }
273 273
274 void PicBase::show(void) { 274 void PicBase::show(void) {
275 /* ʬοƤ٤ shown */ 275 /* 自分の親がすべて shown か? */
276 PicContainer* cur; 276 PicContainer* cur;
277 for (cur = parent; cur != 0; cur = cur->parent) 277 for (cur = parent; cur != 0; cur = cur->parent)
278 if (cur->is_hidden) break; 278 if (cur->is_hidden) break;
279 if (cur != NULL) { // ƤƤΤɽϤʤ 279 if (cur != NULL) { // 親が隠れているので表示はしない
280 is_hidden = false; 280 is_hidden = false;
281 is_hidden_now = true; 281 is_hidden_now = true;
282 return; 282 return;
283 } 283 }
284 if (is_hidden == false) return; // ǤɽƤΤǤʤˤ⤷ʤ 284 if (is_hidden == false) return; // すでに表示されているのでなにもしない
285 if (widget != NULL) { 285 if (widget != NULL) {
286 widget->activate(); 286 widget->activate();
287 } 287 }
288 is_hidden = false; 288 is_hidden = false;
289 is_hidden_now = false; 289 is_hidden_now = false;
328 if (!is_hidden) ReBlit(); 328 if (!is_hidden) ReBlit();
329 } 329 }
330 330
331 void PicBase::SetSurfaceAlphaFile(const char* file) { 331 void PicBase::SetSurfaceAlphaFile(const char* file) {
332 332
333 /* ե򸵤 alpha */ 333 /* ファイルを元に alpha 画像を作成する */
334 /* ե롧 ѥե 'fil' ե */ 334 /* ファイル: パルフェの 'fil' ファイル */
335 ARCINFO* info = FileSearcher::GetInstance()->Find(FileSearcher::PDT, file,"fil"); 335 ARCINFO* info = FileSearcher::GetInstance()->Find(FileSearcher::PDT, file,"fil");
336 if (info == NULL) return; 336 if (info == NULL) return;
337 char* new_alpha = info->CopyRead(); 337 char* new_alpha = info->CopyRead();
338 int alpha_size = info->Size(); 338 int alpha_size = info->Size();
339 delete info; 339 delete info;
347 sr = Rect(*surface_own); 347 sr = Rect(*surface_own);
348 w = sr.width(); 348 w = sr.width();
349 h = sr.height(); 349 h = sr.height();
350 if (alpha_size < w*h) goto err_ret; 350 if (alpha_size < w*h) goto err_ret;
351 int i,j; 351 int i,j;
352 if ( ((SDL_Surface*)surface_own)->format->Amask == 0) { // mask surface ˷ 352 if ( ((SDL_Surface*)surface_own)->format->Amask == 0) { // mask を surface に繰り込む
353 Surface* dest = root->NewSurface(w,h, ALPHA_MASK); 353 Surface* dest = root->NewSurface(w,h, ALPHA_MASK);
354 for (i=0; i<h; i++) { 354 for (i=0; i<h; i++) {
355 char* a = new_alpha + w*i; 355 char* a = new_alpha + w*i;
356 char* s = (char*)((SDL_Surface*)surface_own)->pixels + ((SDL_Surface*)surface_own)->pitch*i; 356 char* s = (char*)((SDL_Surface*)surface_own)->pixels + ((SDL_Surface*)surface_own)->pitch*i;
357 char* d = (char*)((SDL_Surface*)dest)->pixels + ((SDL_Surface*)dest)->pitch*i; 357 char* d = (char*)((SDL_Surface*)dest)->pixels + ((SDL_Surface*)dest)->pitch*i;
369 } 369 }
370 delete new_alpha; 370 delete new_alpha;
371 root->DeleteSurface(surface_own); 371 root->DeleteSurface(surface_own);
372 surface_own = dest; 372 surface_own = dest;
373 SetSurfaceAlpha(0, Rect(0,0)); 373 SetSurfaceAlpha(0, Rect(0,0));
374 } else { // ˥ޥ 374 } else { // 外部にマスク作成
375 /* ޥΤ0xff Ǥ٤ʬȽ̡ѹ */ 375 /* マスクのうち、0xff であるべき部分を画像から判別、変更する */
376 for (i=0; i<h; i++) { 376 for (i=0; i<h; i++) {
377 char* a = new_alpha + w*i; 377 char* a = new_alpha + w*i;
378 char* s = (char*)((SDL_Surface*)surface_own)->pixels + ((SDL_Surface*)surface_own)->pitch*i; 378 char* s = (char*)((SDL_Surface*)surface_own)->pixels + ((SDL_Surface*)surface_own)->pitch*i;
379 int bpp = ((SDL_Surface*)surface_own)->format->BytesPerPixel; 379 int bpp = ((SDL_Surface*)surface_own)->format->BytesPerPixel;
380 for (j=0; j<w; j++) { 380 for (j=0; j<w; j++) {
404 surface_y = y; 404 surface_y = y;
405 surface_w = -1; 405 surface_w = -1;
406 surface_h = -1; 406 surface_h = -1;
407 407
408 if (attribute & FIT_SURFACE) { 408 if (attribute & FIT_SURFACE) {
409 // surface 礭˼ʬ礭ѹ 409 // surface の大きさに自分の大きさを変更
410 parent->ReBlit(rel_pos); 410 parent->ReBlit(rel_pos);
411 if (surface_own == 0) { 411 if (surface_own == 0) {
412 rel_pos = Rect(rel_pos.lx, rel_pos.ty); 412 rel_pos = Rect(rel_pos.lx, rel_pos.ty);
413 } else { 413 } else {
414 Rect r(*surface_own); 414 Rect r(*surface_own);
486 486
487 PicContainer::~PicContainer() { 487 PicContainer::~PicContainer() {
488 iterator end = children.end(); 488 iterator end = children.end();
489 for (iterator it = children.begin(); it != end; ) { 489 for (iterator it = children.begin(); it != end; ) {
490 iterator it_next = it; it_next++; 490 iterator it_next = it; it_next++;
491 if ((*it)->widget != NULL) delete (*it)->widget; // picture widget °Ƥʤ顢delete 491 if ((*it)->widget != NULL) delete (*it)->widget; // picture にwidget が付属しているなら、そちらをdelete
492 else delete (*it); 492 else delete (*it);
493 it = it_next; 493 it = it_next;
494 } 494 }
495 } 495 }
496 496
500 iterator end = children.end(), begin = children.begin(); 500 iterator end = children.end(), begin = children.begin();
501 iterator it = begin; 501 iterator it = begin;
502 502
503 Rect ppos = parent_pos(rpos); 503 Rect ppos = parent_pos(rpos);
504 if (is_hidden_now) goto parent_redraw; 504 if (is_hidden_now) goto parent_redraw;
505 // cache Ƥΰõ 505 // cache されている領域を探す
506 // zȤå夷ƤСǽλ 506 // z自身がキャッシュしていれば、ここで終了
507 if ( ((*z)->attribute & CACHE_BACK) && ( (*z)->is_cached) && (*z)->rel_pos.is_inner(rpos)) { 507 if ( ((*z)->attribute & CACHE_BACK) && ( (*z)->is_cached) && (*z)->rel_pos.is_inner(rpos)) {
508 Rect cpos = child_pos(rpos, *z); 508 Rect cpos = child_pos(rpos, *z);
509 Rect apos = (*z)->QueryAbsPos(cpos); 509 Rect apos = (*z)->QueryAbsPos(cpos);
510 root->BlitSurface( (*z)->surface_back, cpos, root->surface, apos); 510 root->BlitSurface( (*z)->surface_back, cpos, root->surface, apos);
511 return; 511 return;
512 } 512 }
513 // z 겼λҤå塢뤤 SOLID Ǥʤ 513 // z より下の子がキャッシュ、あるいは SOLID 描画できないか?
514 for (it = z; it != begin;) { // ҤcontainerξΥåϾά 514 for (it = z; it != begin;) { // 子がcontainerの場合のチェックは省略
515 it--; 515 it--;
516 if ( (*it)->is_hidden_now) continue; 516 if ( (*it)->is_hidden_now) continue;
517 if ( (*it)->rel_pos.is_crossed(rpos)) { 517 if ( (*it)->rel_pos.is_crossed(rpos)) {
518 if ( ((*it)->attribute & CACHE_BACK) && ((*it)->is_cached) && (*it)->rel_pos.is_inner(rpos)) { 518 if ( ((*it)->attribute & CACHE_BACK) && ((*it)->is_cached) && (*it)->rel_pos.is_inner(rpos)) {
519 Rect cpos = child_pos(rpos, *it); 519 Rect cpos = child_pos(rpos, *it);
524 if ( (*it)->rel_solid_area.is_inner(rpos)) { 524 if ( (*it)->rel_solid_area.is_inner(rpos)) {
525 goto children_redraw; 525 goto children_redraw;
526 } 526 }
527 } 527 }
528 } 528 }
529 // ʬȤå塢뤤 SOLID Ǥʤ 529 // 自分自身がキャッシュ、あるいは SOLID 描画できないか?
530 if (rel_solid_area.is_inner(ppos)) { 530 if (rel_solid_area.is_inner(ppos)) {
531 goto self_redraw; 531 goto self_redraw;
532 } 532 }
533 if ( (attribute & CACHE_BACK) && is_cached) { 533 if ( (attribute & CACHE_BACK) && is_cached) {
534 Rect cpos = child_pos(rpos, *z); 534 Rect cpos = child_pos(rpos, *z);
542 Rect ppos = parent_pos(rpos); 542 Rect ppos = parent_pos(rpos);
543 parent->BlitBack(z_pos, ppos); 543 parent->BlitBack(z_pos, ppos);
544 } 544 }
545 if (is_hidden_now) return; 545 if (is_hidden_now) return;
546 self_redraw: 546 self_redraw:
547 BlitSelf(rpos); // Ҥ褻ʬ 547 BlitSelf(rpos); // 子は描画せず、自分だけ描画
548 children_redraw: 548 children_redraw:
549 for (; it != z; it++) { 549 for (; it != z; it++) {
550 if ( (*it)->is_hidden_now) continue; 550 if ( (*it)->is_hidden_now) continue;
551 if ( (*it)->rel_pos.is_crossed(rpos)) { 551 if ( (*it)->rel_pos.is_crossed(rpos)) {
552 Rect cpos = child_pos(rpos, *it); 552 Rect cpos = child_pos(rpos, *it);
584 parent->BlitFront(z_pos, ppos); 584 parent->BlitFront(z_pos, ppos);
585 } 585 }
586 } 586 }
587 587
588 void PicContainer::BlitSelf(Rect rpos) { 588 void PicContainer::BlitSelf(Rect rpos) {
589 // ºݤ褹ΰ 589 // 実際に描画する領域を得る
590 rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height())); 590 rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height()));
591 if (rpos.empty()) return; 591 if (rpos.empty()) return;
592 Rect apos = QueryAbsPos(rpos); 592 Rect apos = QueryAbsPos(rpos);
593 // ɬפ˱¸ 593 // 必要に応じて保存、描画
594 if (attribute & CACHE_BACK) root->BlitSurface(root->surface, apos, surface_back, rpos); 594 if (attribute & CACHE_BACK) root->BlitSurface(root->surface, apos, surface_back, rpos);
595 if (! (attribute & NO_PICTURE)) { 595 if (! (attribute & NO_PICTURE)) {
596 rpos.rmove(surface_x, surface_y); 596 rpos.rmove(surface_x, surface_y);
597 if (surface_w >= 0 && surface_h >= 0) { 597 if (surface_w >= 0 && surface_h >= 0) {
598 Rect clip(0, 0, surface_w, surface_h); 598 Rect clip(0, 0, surface_w, surface_h);
599 clip.rmove(rpos.lx, rpos.ty); 599 clip.rmove(rpos.lx, rpos.ty);
600 rpos.intersect(clip); 600 rpos.intersect(clip);
601 } 601 }
602 root->BlitSurface(surface_own, rpos, surface_alpha, surface_alpha_rect, root->surface, apos, attribute); 602 root->BlitSurface(surface_own, rpos, surface_alpha, surface_alpha_rect, root->surface, apos, attribute);
603 } else if (parent == NULL) { // ƤʤʤطʾõǤ 603 } else if (parent == NULL) { // 親がいないなら背景消去の責任をもつ
604 DSurfaceFill(root->surface, apos, 0, 0, 0); 604 DSurfaceFill(root->surface, apos, 0, 0, 0);
605 } 605 }
606 } 606 }
607 607
608 void PicContainer::set_showflag(void) { 608 void PicContainer::set_showflag(void) {
626 PicContainer* next = dynamic_cast<PicContainer*>(*it); 626 PicContainer* next = dynamic_cast<PicContainer*>(*it);
627 if (next && (!next->children.empty())) next->set_nowhiddenflag(is_hide); 627 if (next && (!next->children.empty())) next->set_nowhiddenflag(is_hide);
628 } 628 }
629 } 629 }
630 630
631 void PicContainer::RMove(int add_x, int add_y) { // event widget ΰưΤǻҤˤĤƤRMoveƤӽФ 631 void PicContainer::RMove(int add_x, int add_y) { // event widget の移動があり得るので子についてもRMoveを呼び出す
632 PicBase::RMove(add_x, add_y); 632 PicBase::RMove(add_x, add_y);
633 iterator end = children.end(); 633 iterator end = children.end();
634 for (iterator it = children.begin(); it != end; it++) { 634 for (iterator it = children.begin(); it != end; it++) {
635 (*it)->RMove(0,0); 635 (*it)->RMove(0,0);
636 } 636 }
722 bool Free(Surface* s); 722 bool Free(Surface* s);
723 }; 723 };
724 724
725 FileToSurface::FileToSurface(const PicRoot& _root) : root(_root) { 725 FileToSurface::FileToSurface(const PicRoot& _root) : root(_root) {
726 count = 0; 726 count = 0;
727 count_max = 32; // å̡ʷǤ 727 count_max = 32; // キャッシュ量(決め打ち)
728 }; 728 };
729 729
730 FileToSurface::~FileToSurface() { 730 FileToSurface::~FileToSurface() {
731 qiterator it; 731 qiterator it;
732 for (it=queue.begin(); it != queue.end(); it++) { 732 for (it=queue.begin(); it != queue.end(); it++) {
759 } 759 }
760 mem = (char*)malloc(conv->Width() * conv->Height() * 4 + 1024); 760 mem = (char*)malloc(conv->Width() * conv->Height() * 4 + 1024);
761 Surface* s = NULL; 761 Surface* s = NULL;
762 if (conv->Read(mem)) { 762 if (conv->Read(mem)) {
763 MaskType is_mask = conv->IsMask() ? ALPHA_MASK : NO_MASK; 763 MaskType is_mask = conv->IsMask() ? ALPHA_MASK : NO_MASK;
764 if (is_mask == ALPHA_MASK) { // alpha ٤ 0xff ʤޥ̵Ȥ 764 if (is_mask == ALPHA_MASK) { // alpha がすべて 0xff ならマスク無しとする
765 int len = conv->Width()*conv->Height(); 765 int len = conv->Width()*conv->Height();
766 unsigned int* d = (unsigned int*)mem; 766 unsigned int* d = (unsigned int*)mem;
767 int i; for (i=0; i<len; i++) { 767 int i; for (i=0; i<len; i++) {
768 if ( (*d&0xff000000) != 0xff000000) break; 768 if ( (*d&0xff000000) != 0xff000000) break;
769 d++; 769 d++;
785 } 785 }
786 char* mem; 786 char* mem;
787 Surface* surface = LoadSurface(name, mem); 787 Surface* surface = LoadSurface(name, mem);
788 if (surface == NULL) return NULL; 788 if (surface == NULL) return NULL;
789 789
790 while (count >= count_max) { // count_max ʾΥǡǽʤ 790 while (count >= count_max) { // count_max 以上のデータを可能なら削除する
791 qiterator it; 791 qiterator it;
792 for (it=queue.begin(); it != queue.end(); it++) { 792 for (it=queue.begin(); it != queue.end(); it++) {
793 if (DeleteData(*it)) break; 793 if (DeleteData(*it)) break;
794 } 794 }
795 if (it == queue.end()) break; // ǡʤ齪λ 795 if (it == queue.end()) break; // 全データが使用中なら終了
796 } 796 }
797 SurfaceIndex* new_index = new SurfaceIndex; 797 SurfaceIndex* new_index = new SurfaceIndex;
798 new_index->filename = name; 798 new_index->filename = name;
799 new_index->surface = surface; 799 new_index->surface = surface;
800 findex[name] = new_index; 800 findex[name] = new_index;
847 height = surface->h; 847 height = surface->h;
848 return; 848 return;
849 } 849 }
850 850
851 PicRoot::~PicRoot() { 851 PicRoot::~PicRoot() {
852 // if (surface) DeleteSurfaceImpl(surface); // SDL_GetVideoSurface() surface ϳɬפʤ餷 852 // if (surface) DeleteSurfaceImpl(surface); // SDL_GetVideoSurface() した surface は開放の必要がないらしい
853 surface = NULL; 853 surface = NULL;
854 delete root; 854 delete root;
855 delete ftosurface; 855 delete ftosurface;
856 } 856 }
857 857
875 } 875 }
876 return; 876 return;
877 } 877 }
878 878
879 void PicRoot::ExecUpdate(void) { 879 void PicRoot::ExecUpdate(void) {
880 /* ̤ΰõ */ 880 /* 共通する領域を消去する */
881 sort(update_rects.begin(), update_rects.end(), UpdateItem::less); 881 sort(update_rects.begin(), update_rects.end(), UpdateItem::less);
882 vector<UpdateItem>::iterator it; 882 vector<UpdateItem>::iterator it;
883 vector<UpdateItem>::iterator end = update_rects.end(); 883 vector<UpdateItem>::iterator end = update_rects.end();
884 884
885 for (it=update_rects.begin(); it != end; it++) { 885 for (it=update_rects.begin(); it != end; it++) {
889 PicBase* pic = it->pic; 889 PicBase* pic = it->pic;
890 890
891 vector<UpdateItem>::iterator jt = it; jt++; 891 vector<UpdateItem>::iterator jt = it; jt++;
892 for (; jt != end; jt++) { 892 for (; jt != end; jt++) {
893 if (apos.is_inner(jt->apos)) { 893 if (apos.is_inner(jt->apos)) {
894 if (jt->pic == pic || jt->pic->IsParent(pic)) { // Ƥ̡ΰⶦ 894 if (jt->pic == pic || jt->pic->IsParent(pic)) { // 親が共通、かつ領域も共通
895 jt->rpos = Rect(0,0); // empty rect 򥻥å 895 jt->rpos = Rect(0,0); // empty rect をセット
896 jt->apos = Rect(0,0); 896 jt->apos = Rect(0,0);
897 } 897 }
898 } else if (jt->apos.is_inner(apos)) { // ˼ʬޤ 898 } else if (jt->apos.is_inner(apos)) { // 相手に自分が包含される
899 if (jt->pic == pic || jt->pic->IsParent(pic)) { // Ƥ̡ΰⶦ 899 if (jt->pic == pic || jt->pic->IsParent(pic)) { // 親が共通、かつ領域も共通
900 it->rpos = Rect(0,0); 900 it->rpos = Rect(0,0);
901 it->apos = Rect(0,0); 901 it->apos = Rect(0,0);
902 break; 902 break;
903 } 903 }
904 } 904 }
953 Surface* s = ftosurface->Load(f); 953 Surface* s = ftosurface->Load(f);
954 if (s == NULL) return NULL; 954 if (s == NULL) return NULL;
955 if (with_mask == COLOR_MASK) { 955 if (with_mask == COLOR_MASK) {
956 SDL_SetColorKey( (SDL_Surface*)s, SDL_SRCCOLORKEY, *(Uint32*)s->pixels); 956 SDL_SetColorKey( (SDL_Surface*)s, SDL_SRCCOLORKEY, *(Uint32*)s->pixels);
957 } 957 }
958 /* xkanon λij */ 958 /* xkanon の残骸 */
959 if (strcmp(f, "grdat") == 0) 959 if (strcmp(f, "grdat") == 0)
960 SDL_SetColorKey(s, SDL_SRCCOLORKEY, 0x55aa66); 960 SDL_SetColorKey(s, SDL_SRCCOLORKEY, 0x55aa66);
961 return s; 961 return s;
962 } 962 }
963 963
1037 #include <X11/Xutil.h> 1037 #include <X11/Xutil.h>
1038 #endif /* USE_X11 */ 1038 #endif /* USE_X11 */
1039 void PicRoot::SetWindowCaption(const char* caption) { 1039 void PicRoot::SetWindowCaption(const char* caption) {
1040 #if USE_X11 1040 #if USE_X11
1041 // SDL_WM_SetCaption(caption, 0); 1041 // SDL_WM_SetCaption(caption, 0);
1042 // SDLδؿǤ2Хʸ򥵥ݡȤƤʤΤǡƱƤ˽ 1042 // SDLの関数では2バイト文字をサポートしてくれないので、同等の内容に修正
1043 SDL_SysWMinfo info; 1043 SDL_SysWMinfo info;
1044 memset(&info,0,sizeof(info)); 1044 memset(&info,0,sizeof(info));
1045 SDL_VERSION(&(info.version)); 1045 SDL_VERSION(&(info.version));
1046 if (SDL_GetWMInfo(&info) == 1) { 1046 if (SDL_GetWMInfo(&info) == 1) {
1047 Display* display = info.info.x11.display; 1047 Display* display = info.info.x11.display;