Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

Surface.cpp

Go to the documentation of this file.
00001 00006 /* 00007 Copyright (C) 2004 Anders Hedstrom 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 00012 of the License, or (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 #include <SDL.h> 00024 #include "guitypedefs.h" 00025 #ifdef _WIN32 00026 #pragma warning(push) 00027 00028 #include <yvals.h> // warning numbers get enabled in yvals.h 00029 00030 #pragma warning(disable: 4251) 00031 #pragma warning(disable: 4786) // identifier was truncated to 'number' characters in the debug information 00032 00033 // BUG: C4786 Warning Is Not Disabled with #pragma Warning 00034 // STATUS: Microsoft has confirmed this to be a bug in the Microsoft product. This warning can be ignored. 00035 // This occured only in the <map> container. 00036 00037 #include <sge.h> 00038 00039 #pragma warning(pop) 00040 #else 00041 #include <sge.h> 00042 #endif 00043 //#include <iotm/Mutex.h> 00044 00045 //#include "TimerThread.h" 00046 #include "SDLControl.h" 00047 #include "SurfaceHelper.h" 00048 #include "TTFont.h" 00049 #include "GuiEvent.h" 00050 #include "Xml.h" 00051 #include "Surface.h" 00052 #include "Button.h" 00053 #include "Hotspot.h" 00054 #include "Dialog.h" 00055 #include "Edit.h" 00056 #include "MenuItem.h" 00057 #include "Menu.h" 00058 #include "PopupMenuItem.h" 00059 #include "SeparatorMenuItem.h" 00060 #include "Output.h" 00061 #include "Progress.h" 00062 #include "Static.h" 00063 00064 using util::Xml; 00065 00066 00067 namespace gui 00068 { 00069 unsigned long Surface::m_unique_id = 0; 00070 00071 Surface::Surface(SDLControl *pclControl,coord_t x,coord_t y,coord_t w,coord_t h,SurfaceHelper *pclHelper) 00072 :m_screen(NULL) 00073 ,m_temp_screen(NULL) 00074 ,m_id(m_unique_id++) 00075 ,m_local_id(0) 00076 ,m_pclParent(NULL) 00077 ,m_pclControl(pclControl) 00078 ,m_pclHelper(pclHelper) 00079 ,m_x(x) 00080 ,m_y(y) 00081 ,m_w(w) 00082 ,m_h(h) 00083 ,m_x_absolute(0) 00084 ,m_y_absolute(0) 00085 ,m_bBgColorIsSet(false) 00086 ,m_bFgColorIsSet(false) 00087 ,m_bFrameColorIsSet(false) 00088 ,m_pclTTFont(NULL) 00089 ,m_nAlpha(0) 00090 ,m_bAlphaIsSet(0) 00091 ,m_nFrameWidth(0) 00092 ,m_bFrameWidthIsSet(false) 00093 //,m_strName("") 00094 //,m_style(0) 00095 ,m_bVisible(true) 00096 ,m_bChildrenVisible(true) 00097 ,m_bInverted(false) 00098 ,m_bTransparent(false) 00099 ,m_bMoveable(false) 00100 ,m_bDirty(true) 00101 ,m_bResizeArea(false) 00102 ,m_bAnchorRight(false) 00103 ,m_bAnchorDown(false) 00104 ,m_bMustBeDeleted(false) 00105 ,m_bClickable(false) 00106 ,m_bUseTemporaryScreen(false) 00107 ,m_text("") 00108 ,m_bRedrawTemporary(false) 00109 ,m_pclBond(NULL) 00110 ,m_uicommand(UICOMMAND_NONE) 00111 { 00112 coord_t fw = GetFrameWidth(); 00113 00114 m_screen = CreateSDLSurface(true); 00115 00116 m_clientRect.x = fw; 00117 m_clientRect.y = fw; 00118 m_clientRect.w = m_w - fw * 2; 00119 m_clientRect.h = m_h - fw * 2; 00120 m_absoluteRect.x = 0; 00121 m_absoluteRect.y = 0; 00122 m_absoluteRect.w = m_w; 00123 m_absoluteRect.h = m_h; 00124 } 00125 00126 00127 Surface::Surface(Surface *pclParent,coord_t x,coord_t y,coord_t w,coord_t h,SurfaceHelper *pclHelper) 00128 :m_screen(NULL) 00129 ,m_temp_screen(NULL) 00130 ,m_id(m_unique_id++) 00131 ,m_local_id(0) 00132 ,m_pclParent(pclParent) 00133 ,m_pclControl(NULL) 00134 ,m_pclHelper(pclHelper) 00135 ,m_x(x) 00136 ,m_y(y) 00137 ,m_w(w) 00138 ,m_h(h) 00139 ,m_x_absolute(0) 00140 ,m_y_absolute(0) 00141 ,m_bBgColorIsSet(false) 00142 ,m_bFgColorIsSet(false) 00143 ,m_bFrameColorIsSet(false) 00144 ,m_pclTTFont(NULL) 00145 ,m_nAlpha(0) 00146 ,m_bAlphaIsSet(0) 00147 ,m_nFrameWidth(0) 00148 ,m_bFrameWidthIsSet(false) 00149 //,m_strName("") 00150 //,m_style(0) 00151 ,m_bVisible(true) 00152 ,m_bChildrenVisible(true) 00153 ,m_bInverted(false) 00154 ,m_bTransparent(false) 00155 ,m_bMoveable(false) 00156 ,m_bDirty(true) 00157 ,m_bResizeArea(false) 00158 ,m_bAnchorRight(false) 00159 ,m_bAnchorDown(false) 00160 ,m_bMustBeDeleted(false) 00161 ,m_bClickable(false) 00162 ,m_bUseTemporaryScreen(false) 00163 ,m_text("") 00164 ,m_bRedrawTemporary(false) 00165 ,m_pclBond(NULL) 00166 ,m_uicommand(UICOMMAND_NONE) 00167 { 00168 coord_t fw = GetFrameWidth(); 00169 00170 m_screen = CreateSDLSurface(true); 00171 00172 m_clientRect.x = fw; 00173 m_clientRect.y = fw; 00174 m_clientRect.w = m_w - fw * 2; 00175 m_clientRect.h = m_h - fw * 2; 00176 m_absoluteRect.x = 0; 00177 m_absoluteRect.y = 0; 00178 m_absoluteRect.w = m_w; 00179 m_absoluteRect.h = m_h; 00180 } 00181 00182 00183 Surface::Surface(Surface *pclParent,SurfaceHelper *pclHelper) 00184 :m_screen(NULL) 00185 ,m_temp_screen(NULL) 00186 ,m_id(m_unique_id++) 00187 ,m_local_id(0) 00188 ,m_pclParent(pclParent) 00189 ,m_pclControl(NULL) 00190 ,m_pclHelper(pclHelper) 00191 ,m_x(0) 00192 ,m_y(0) 00193 ,m_w(0) 00194 ,m_h(0) 00195 ,m_x_absolute(0) 00196 ,m_y_absolute(0) 00197 ,m_bBgColorIsSet(false) 00198 ,m_bFgColorIsSet(false) 00199 ,m_bFrameColorIsSet(false) 00200 ,m_pclTTFont(NULL) 00201 ,m_nAlpha(0) 00202 ,m_bAlphaIsSet(0) 00203 ,m_nFrameWidth(0) 00204 ,m_bFrameWidthIsSet(false) 00205 //,m_strName("") 00206 //,m_style(0) 00207 ,m_bVisible(true) 00208 ,m_bChildrenVisible(true) 00209 ,m_bInverted(false) 00210 ,m_bTransparent(false) 00211 ,m_bMoveable(false) 00212 ,m_bDirty(true) 00213 ,m_bResizeArea(false) 00214 ,m_bAnchorRight(false) 00215 ,m_bAnchorDown(false) 00216 ,m_bMustBeDeleted(false) 00217 ,m_bClickable(false) 00218 ,m_bUseTemporaryScreen(false) 00219 ,m_text("") 00220 ,m_bRedrawTemporary(false) 00221 ,m_pclBond(NULL) 00222 ,m_uicommand(UICOMMAND_NONE) 00223 { 00224 } 00225 00226 00227 Surface::~Surface() 00228 { 00229 surfacevector_t::iterator it; 00230 00231 // unlink bonds 00232 if (GetBond()) 00233 { 00234 GetBond() -> Unbond(this); 00235 } 00236 for (it = m_bonds.begin(); it != m_bonds.end(); it++) 00237 { 00238 (*it) -> SetBond(NULL); 00239 } 00240 // unlink parent stuff 00241 if (GetParent()) 00242 { 00243 GetParent() -> Remove(this); 00244 } 00245 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00246 { 00247 Surface *pclSurface = *it; 00248 if (pclSurface -> MustBeDeleted()) 00249 { 00250 delete pclSurface; 00251 } 00252 } 00253 // delete screens 00254 if (m_screen) 00255 { 00256 SDL_FreeSurface(m_screen); 00257 } 00258 if (m_temp_screen) 00259 { 00260 SDL_FreeSurface(m_temp_screen); 00261 } 00262 } 00263 00264 00265 SDL_Surface *Surface::CreateSDLSurface(bool bAlpha) 00266 { 00267 Uint32 rmask, gmask, bmask, amask; 00268 SDLControl *pcl = GetSDLControl(); 00269 SDL_Surface *pclSurf = pcl -> GetScreen(); 00270 int depth = pcl -> GetBpp(); 00271 00272 rmask = pclSurf -> format -> Rmask; 00273 gmask = pclSurf -> format -> Gmask; 00274 bmask = pclSurf -> format -> Bmask; 00275 amask = pclSurf -> format -> Amask; 00276 if (0 && !amask) 00277 { 00278 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 00279 amask = 0x000000ff; 00280 #else 00281 amask = 0xff000000; 00282 #endif 00283 } 00284 00285 // SDL interprets each pixel as a 32-bit number, so our masks must depend 00286 // on the endianness (byte order) of the machine 00287 if (bAlpha) 00288 { 00289 depth = 32; 00290 switch (depth) 00291 { 00292 case 24: 00293 rmask = 0x0000003f; 00294 gmask = 0x00000fc0; 00295 bmask = 0x0003f000; 00296 amask = 0x00fc0000; 00297 break; 00298 case 32: 00299 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 00300 rmask = 0xff000000; 00301 gmask = 0x00ff0000; 00302 bmask = 0x0000ff00; 00303 amask = 0x000000ff; 00304 #else 00305 rmask = 0x000000ff; 00306 gmask = 0x0000ff00; 00307 bmask = 0x00ff0000; 00308 amask = 0xff000000; 00309 #endif 00310 break; 00311 default: 00312 rmask = gmask = bmask = amask = 0; 00313 } 00314 } // if (bAlpha) 00315 00316 DEB( 00317 printf("CreateSDLSurface() depth = %d\n", depth); 00318 printf(" rmask = %08x\n", rmask); 00319 printf(" gmask = %08x\n", gmask); 00320 printf(" bmask = %08x\n", bmask); 00321 printf(" amask = %08x\n", amask); 00322 ) 00323 00324 SDL_Surface *screen; 00325 if (!(screen = SDL_CreateRGBSurface(SDL_SWSURFACE, m_w, m_h, depth, rmask, gmask, bmask, amask))) 00326 { 00327 fprintf(stderr, "CreateRGBSurface failed: %s", SDL_GetError()); 00328 // exit(1); 00329 } 00330 return screen; 00331 } 00332 00333 00334 void Surface::AddChild(Surface *pclChild) 00335 { 00336 m_ChildList.insert(m_ChildList.end(), pclChild); 00337 pclChild -> SetLocalID( m_ChildList.size() ); 00338 pclChild -> SetParent( this ); 00339 CalculateAbsolute(); 00340 } 00341 00342 00343 void Surface::BringToTop(Surface *pclChild) 00344 { 00345 surfacevector_t::iterator it; 00346 00347 if (pclChild != GetChildOnTop()) 00348 { 00349 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00350 { 00351 if (*it == pclChild) 00352 { 00353 m_ChildList.erase(it); 00354 break; 00355 } 00356 } 00357 if (it != m_ChildList.end()) 00358 { 00359 m_ChildList.insert(m_ChildList.end(), pclChild); 00360 } 00361 } 00362 } 00363 00364 00365 void Surface::BringToTop() 00366 { 00367 Surface *pclParent = GetParent(); 00368 00369 if (pclParent) 00370 { 00371 pclParent -> BringToTop(this); 00372 } 00373 } 00374 00375 00376 Surface *Surface::GetChildOnTop() 00377 { 00378 surfacevector_t::iterator it; 00379 Surface *pclTemp = NULL; 00380 00381 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00382 { 00383 pclTemp = *it; 00384 } 00385 return pclTemp; 00386 } 00387 00388 00389 void Surface::Remove(Surface *pclChild) 00390 { 00391 surfacevector_t::iterator it; 00392 00393 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00394 { 00395 Surface *pclSurface = *it; 00396 if (pclSurface == pclChild) 00397 { 00398 m_ChildList.erase(it); 00399 break; 00400 } 00401 } 00402 if (pclChild -> MustBeDeleted()) 00403 { 00404 delete pclChild; 00405 } 00406 } 00407 00408 00409 Surface *Surface::FindSurface(coord_t xpos,coord_t ypos,coord_t X,coord_t Y) 00410 { 00411 surfacevector_t::iterator it; 00412 Surface *pclFound = NULL; 00413 00414 if (m_bChildrenVisible) 00415 { 00416 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00417 { 00418 Surface *pclTemp = *it; 00419 if (pclTemp -> IsVisible()) 00420 { 00421 if (xpos >= pclTemp -> GetAbsoluteX() && 00422 xpos < pclTemp -> GetAbsoluteX() + pclTemp -> GetW() && 00423 ypos >= pclTemp -> GetAbsoluteY() && 00424 ypos < pclTemp -> GetAbsoluteY() + pclTemp -> GetH() ) 00425 /* 00426 if (xpos > X + pclTemp -> GetX() && 00427 xpos < X + pclTemp -> GetX() + pclTemp -> GetW() && 00428 ypos > Y + pclTemp -> GetY() && 00429 ypos < Y + pclTemp -> GetY() + pclTemp -> GetH()) 00430 */ 00431 { 00432 pclFound = pclTemp; 00433 } 00434 } 00435 } 00436 } 00437 if (pclFound) 00438 return pclFound -> FindSurface(xpos,ypos); // ,X + pclFound -> GetX(),Y + pclFound -> GetY()); 00439 else 00440 return this; 00441 } 00442 00443 00444 void Surface::CalculateAbsolute() 00445 { 00446 surfacevector_t::iterator it; 00447 00448 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00449 { 00450 Surface *pclTemp = *it; 00451 coord_t fw = GetFrameWidth(); 00452 coord_t x = GetAbsoluteX() + pclTemp -> GetX() + fw; 00453 coord_t y = GetAbsoluteY() + pclTemp -> GetY() + fw; 00454 pclTemp -> SetAbsoluteX(x); 00455 pclTemp -> SetAbsoluteY(y); 00456 pclTemp -> CalculateAbsolute(); 00457 } 00458 } 00459 00460 00461 /* 00462 void Surface::Clip(SDL_Rect *dst) 00463 { 00464 coord_t xmax = GetSDLControl() -> GetScreen() -> w; 00465 coord_t ymax = GetSDLControl() -> GetScreen() -> h; 00466 00467 // kontroll utanfor ytan 00468 if (dst -> x + dst -> w > xmax) 00469 { 00470 dst -> w -= dst -> x + dst -> w - xmax; 00471 } 00472 if (dst -> y + dst -> h > ymax) 00473 { 00474 dst -> h -= dst -> y + dst -> h - ymax; 00475 } 00476 // 00477 } 00478 */ 00479 00480 00481 void Surface::RecreateSurfaces() 00482 { 00483 int xrel = 0; 00484 int yrel = 0; 00485 bool event = false; 00486 00487 if (UseTemporaryScreen()) 00488 { 00489 if (m_temp_screen) 00490 { 00491 FreeSurface(m_temp_screen); 00492 } 00493 } 00494 if (m_screen) 00495 { 00496 xrel = GetScreen() -> w; 00497 yrel = GetScreen() -> h; 00498 event = true; 00499 FreeSurface(m_screen); 00500 } 00501 00502 m_screen = CreateSDLSurface(true); 00503 if (UseTemporaryScreen()) 00504 { 00505 CreateTemporaryScreen(); 00506 } 00507 00508 if (event) 00509 { 00510 surfacevector_t::iterator it; 00511 xrel = GetScreen() -> w - xrel; 00512 yrel = GetScreen() -> h - yrel; 00513 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00514 { 00515 (*it) -> OnSize(*GetClientRectPtr(), xrel, yrel); 00516 } 00517 } 00518 00519 // GetParent() -> CalculateAbsolute(); 00520 // DrawAll(); 00521 // DrawTemporaryScreen(); 00522 SetDirty(true); 00523 } 00524 00525 00526 void Surface::FreeSurface(SDL_Surface *pclSurface) 00527 { 00528 SDL_FreeSurface(pclSurface); 00529 } 00530 00531 00532 void Surface::InvalidateEv() 00533 { 00534 SDL_Event e; 00535 00536 e.type = SDL_USEREVENT; 00537 e.user.code = SDL_USEREVENT_INVALIDATE; 00538 e.user.data1 = this; 00539 e.user.data2 = NULL; 00540 SDL_PushEvent(&e); 00541 } 00542 00543 00544 void Surface::InvalidateRectEv(SDL_Rect &a) 00545 { 00546 SDL_Event e; 00547 long xy = a.x * 0x10000 + a.y; 00548 long wh = a.w * 0x10000 + a.h; 00549 00550 e.type = SDL_USEREVENT; 00551 e.user.code = SDL_USEREVENT_INVALIDATERECT; 00552 memmove(&e.user.data1, &xy, 4); 00553 memmove(&e.user.data2, &wh, 4); 00554 SDL_PushEvent(&e); 00555 } 00556 00557 00558 void Surface::FillRectEv(SDL_Rect &a) 00559 { 00560 SDL_Event e; 00561 long xy = a.x * 0x10000 + a.y; 00562 long wh = a.w * 0x10000 + a.h; 00563 00564 e.type = SDL_USEREVENT; 00565 e.user.code = SDL_USEREVENT_FILLRECT; 00566 memmove(&e.user.data1, &xy, 4); 00567 memmove(&e.user.data2, &wh, 4); 00568 SDL_PushEvent(&e); 00569 } 00570 00571 00572 void Surface::ResetFillRectsEv() 00573 { 00574 SDL_Event e; 00575 00576 e.type = SDL_USEREVENT; 00577 e.user.code = SDL_USEREVENT_RESETFILLRECTS; 00578 e.user.data1 = NULL; 00579 e.user.data2 = NULL; 00580 SDL_PushEvent(&e); 00581 } 00582 00583 00584 /* 00585 void Surface::RedrawEv() 00586 { 00587 SDL_Event e; 00588 // long l = SDL_GetTicks(); 00589 00590 e.type = SDL_USEREVENT; 00591 e.user.code = SDL_USEREVENT_REDRAWSURFACE; 00592 e.user.data1 = this; 00593 e.user.data2 = NULL; 00594 // memmove(&e.user.data2,&l,4); 00595 SDL_PushEvent(&e); 00596 } 00597 */ 00598 00599 00600 /* 00601 void Surface::Invalidate() 00602 { 00603 SDLControl *pcl = GetSDLControl(); 00604 SDL_Rect a; 00605 Surface *root = GetRoot(); 00606 Surface *parent = GetParent(); 00607 00608 if (parent) 00609 { 00610 parent -> DrawTemporaryScreen(); 00611 } 00612 00613 pcl -> lockSurface(); 00614 a = GetAbsoluteRect(); 00615 root -> BlitAbsolute(&a); 00616 pcl -> unlockSurface(); 00617 SDL_UpdateRects(pcl -> GetScreen(), 1, &a); 00618 00619 // SDL_WarpMouse(GuiEvent::m_x, GuiEvent::m_y); 00620 } 00621 00622 00623 void Surface::InvalidateRect(SDL_Rect &a) 00624 { 00625 SDLControl *pcl = GetSDLControl(); 00626 Surface *root = GetRoot(); 00627 Surface *parent = GetParent(); 00628 00629 if (parent) 00630 { 00631 parent -> DrawTemporaryScreen(); 00632 } 00633 00634 pcl -> lockSurface(); 00635 root -> BlitAbsolute(&a); 00636 pcl -> unlockSurface(); 00637 SDL_UpdateRects(pcl -> GetScreen(), 1, &a); 00638 00639 // SDL_WarpMouse(GuiEvent::m_x, GuiEvent::m_y); 00640 } 00641 */ 00642 00643 00644 void Surface::Draw() 00645 { 00646 } 00647 00648 00649 void Surface::DrawAll() 00650 { 00651 surfacevector_t::iterator it; 00652 00653 if (IsDirty()) 00654 { 00655 Draw(); 00656 DrawFrame(GetScreen(), GetFrameWidth(), GetFrameColor()); 00657 Surface *pclParent = this; //GetParent(); 00658 while (pclParent) 00659 { 00660 if (pclParent -> UseTemporaryScreen()) 00661 { 00662 pclParent -> DrawTemporaryScreen(); 00663 } 00664 pclParent = pclParent -> GetParent(); 00665 } 00666 SetDirty(false); 00667 } 00668 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00669 { 00670 (*it) -> DrawAll(); 00671 } 00672 // if (UseTemporaryScreen()) 00673 // { 00674 // DrawTemporaryScreen(); 00675 // } 00676 } 00677 00678 00679 void Surface::DrawFrame(SDL_Surface *screen,coord_t fw,Uint32 color) 00680 { 00681 SDL_Rect rect; 00682 00683 rect.x = 0; 00684 rect.y = 0; 00685 rect.w = m_w; 00686 rect.h = fw; 00687 SDL_FillRect(screen, &rect, color); 00688 00689 rect.x = 0; 00690 rect.y = 0; 00691 rect.w = fw; 00692 rect.h = m_h; 00693 SDL_FillRect(screen, &rect, color); 00694 00695 rect.x = m_w - fw; 00696 rect.y = 0; 00697 rect.w = fw; 00698 rect.h = m_h; 00699 SDL_FillRect(screen, &rect, color); 00700 00701 rect.x = 0; 00702 rect.y = m_h - fw; 00703 rect.w = m_w; 00704 rect.h = fw; 00705 SDL_FillRect(screen, &rect, color); 00706 00707 } 00708 00709 00710 void Surface::Blit(coord_t X,coord_t Y,SDL_Surface *s) 00711 { 00712 SDL_Surface *pclSDLSurface = s ? s : GetSDLControl() -> GetScreen(); 00713 coord_t xmax = pclSDLSurface->w; 00714 coord_t ymax = pclSDLSurface->h; 00715 00716 if (m_bVisible || m_bRedrawTemporary) 00717 { 00718 SDL_Rect src; 00719 SDL_Rect dst; 00720 coord_t fw = GetParent() ? GetParent() -> GetFrameWidth() : 0; 00721 src.x = src.y = 0; 00722 dst.x = X + m_x + fw; 00723 dst.y = Y + m_y + fw; 00724 src.w = dst.w = m_w; 00725 src.h = dst.h = m_h; 00726 // kontroll utanfor ytan 00727 if (dst.x + dst.w > xmax) 00728 { 00729 dst.w -= dst.x + dst.w - xmax; 00730 src.w = dst.w; 00731 } 00732 if (dst.y + dst.h > ymax) 00733 { 00734 dst.h -= dst.y + dst.h - ymax; 00735 src.h = dst.h; 00736 } 00737 // 00738 if (UseTemporaryScreen()) 00739 { 00740 SDL_BlitSurface(GetTemporaryScreen(), &src, pclSDLSurface, &dst); 00741 } 00742 else 00743 { 00744 if (!IsTransparent()) 00745 { 00746 SDL_BlitSurface(GetScreen(), &src, pclSDLSurface, &dst); 00747 } 00748 if (m_bChildrenVisible) 00749 { 00750 surfacevector_t::iterator it; 00751 00752 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00753 { 00754 (*it) -> Blit(X + m_x + fw, Y + m_y + fw, pclSDLSurface); 00755 } 00756 } 00757 } 00758 } 00759 } 00760 00761 00762 #define MIN(x,y) (x<y)?x:y 00763 #define MAX(x,y) (x>y)?x:y 00764 00765 void Surface::BlitAbsolute(SDL_Rect *pclRect,SDL_Surface *s) 00766 { 00767 SDL_Surface *pclSDLSurface = s ? s : GetSDLControl() -> GetScreen(); 00768 coord_t xmax = pclSDLSurface->w; 00769 coord_t ymax = pclSDLSurface->h; 00770 00771 if (m_bVisible) // || UseTemporaryScreen()) 00772 { 00773 SDL_Rect dst; 00774 SDL_Rect *area = GetAbsoluteRectPtr(); 00775 coord_t r; 00776 coord_t b; 00777 coord_t w; 00778 coord_t h; 00779 dst.x = MAX(pclRect -> x,area -> x); 00780 dst.y = MAX(pclRect -> y,area -> y); 00781 r = MIN(pclRect -> x + pclRect -> w,area -> x + area -> w); 00782 b = MIN(pclRect -> y + pclRect -> h,area -> y + area -> h); 00783 w = r - dst.x; 00784 h = b - dst.y; 00785 if (w > 0 && h > 0) 00786 { 00787 SDL_Rect src; 00788 src.x = dst.x - area -> x; 00789 src.y = dst.y - area -> y; 00790 src.w = dst.w = w; 00791 src.h = dst.h = h; 00792 // kontroll utanfor ytan 00793 if (dst.x + dst.w > xmax) 00794 { 00795 dst.w -= dst.x + dst.w - xmax; 00796 src.w = dst.w; 00797 } 00798 if (dst.y + dst.h > ymax) 00799 { 00800 dst.h -= dst.y + dst.h - ymax; 00801 src.h = dst.h; 00802 } 00803 // 00804 if (UseTemporaryScreen()) 00805 { 00806 SDL_BlitSurface(GetTemporaryScreen(), &src, pclSDLSurface, &dst); 00807 } 00808 else 00809 { 00810 if (!m_bTransparent) 00811 { 00812 SDL_BlitSurface(GetScreen(), &src, pclSDLSurface, &dst); 00813 } 00814 00815 if (m_bChildrenVisible) 00816 { 00817 surfacevector_t::iterator it; 00818 00819 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00820 { 00821 (*it) -> BlitAbsolute(pclRect, pclSDLSurface); 00822 } 00823 } 00824 } // UseTemporaryScreen 00825 } 00826 } 00827 } 00828 00829 00830 /* 00831 void Surface::Update8bitPalette() 00832 { 00833 surfacevector_t::iterator it; 00834 00835 // SDL_SetColors(m_screen, gui::Color::m_palette, 0, gui::Color::m_qcolors); 00836 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 00837 { 00838 (*it) -> Update8bitPalette(); 00839 } 00840 } 00841 */ 00842 00843 00844 void Surface::Move(Surface *pclRootSurface,coord_t xrel,coord_t yrel) 00845 { 00846 coord_t x = GetX() + xrel; 00847 coord_t y = GetY() + yrel; 00848 coord_t wmax = GetParent() -> GetW(); 00849 coord_t hmax = GetParent() -> GetH(); 00850 00851 x = (x < 0) ? 0 : x; 00852 y = (y < 0) ? 0 : y; 00853 x = (x + GetW() > wmax) ? wmax - GetW() : x; 00854 y = (y + GetH() > hmax) ? hmax - GetH() : y; 00855 00856 SDL_Rect a = GetAbsoluteRect(); 00857 pclRootSurface -> InvalidateRectEv(a); 00858 SetX(x); 00859 SetY(y); 00860 GetParent() -> CalculateAbsolute(); 00861 InvalidateEv(); 00862 00863 for (surfacevector_t::iterator it = m_bonds.begin(); it != m_bonds.end(); it++) 00864 { 00865 (*it) -> Move(pclRootSurface,xrel,yrel); 00866 } 00867 } 00868 00869 00870 void Surface::MoveTo(Surface *pclRootSurface,coord_t x,coord_t y,bool bVisible) 00871 { 00872 int xrel = x - GetX(); 00873 int yrel = y - GetY(); 00874 coord_t wmax = GetParent() -> GetW(); 00875 coord_t hmax = GetParent() -> GetH(); 00876 00877 x = (x < 0) ? 0 : x; 00878 y = (y < 0) ? 0 : y; 00879 x = (x + GetW() > wmax) ? wmax - GetW() : x; 00880 y = (y + GetH() > hmax) ? hmax - GetH() : y; 00881 00882 if (IsVisible()) 00883 { 00884 SDL_Rect a = GetAbsoluteRect(); 00885 pclRootSurface -> InvalidateRectEv(a); 00886 } 00887 SetVisible(bVisible); 00888 for (surfacevector_t::iterator it = m_bonds.begin(); it != m_bonds.end(); it++) 00889 { 00890 (*it) -> SetVisible(bVisible); 00891 (*it) -> InvalidateEv(); 00892 } 00893 if (bVisible) 00894 { 00895 SetX(x); 00896 SetY(y); 00897 GetParent() -> CalculateAbsolute(); 00898 InvalidateEv(); 00899 00900 for (surfacevector_t::iterator it = m_bonds.begin(); it != m_bonds.end(); it++) 00901 { 00902 (*it) -> Move(pclRootSurface,xrel,yrel); 00903 } 00904 } 00905 } 00906 00907 00908 void Surface::OnEvent(surface_event_t *pstEvent) 00909 { 00910 Surface *pclParent = GetParent(); 00911 00912 if (pclParent) 00913 { 00914 pstEvent -> id = GetID(); 00915 pstEvent -> local_id = GetLocalID(); 00916 pstEvent -> ptr = this; 00917 pclParent -> OnEvent(pstEvent); 00918 } 00919 } 00920 00921 00922 void Surface::OnMouseIn() 00923 { 00924 //DEB(printf("OnMouseIn()\n");) 00925 } 00926 00927 00928 void Surface::OnMouseOut() 00929 { 00930 //DEB(printf("OnMouseOut()\n");) 00931 } 00932 00933 00934 void Surface::OnKeyDown(SDL_keysym sym) 00935 { 00936 //DEB(printf("OnKeyDown()\n");) 00937 } 00938 00939 00940 void Surface::OnKeyUp(SDL_keysym sym) 00941 { 00942 //DEB(printf("OnKeyUp()\n");) 00943 } 00944 00945 00946 void Surface::OnButton() 00947 { 00948 //DEB(printf("OnButton()\n");) 00949 Surface *pclParent = GetParent(); 00950 if (m_uicommand != UICOMMAND_NONE) 00951 { 00952 SDL_Event e; 00953 e.type = SDL_USEREVENT; 00954 e.user.code = SDL_USEREVENT_UICOMMAND; 00955 memmove(&e.user.data1,this,4); 00956 memmove(&e.user.data2,&m_uicommand,4); 00957 SDL_PushEvent(&e); 00958 } 00959 if (pclParent) 00960 { 00961 surface_event_t e; 00962 e.type = GUI_EVENT_BUTTON; 00963 e.id = GetID(); 00964 e.local_id = GetLocalID(); 00965 e.ptr = this; 00966 pclParent -> OnEvent(&e); 00967 } 00968 } 00969 00970 00971 void Surface::OnClose() 00972 { 00973 Surface *pclParent = GetParent(); 00974 if (pclParent) 00975 { 00976 surface_event_t e; 00977 e.type = GUI_EVENT_CLOSE; 00978 e.id = GetID(); 00979 e.local_id = GetLocalID(); 00980 e.ptr = this; 00981 pclParent -> OnEvent(&e); 00982 } 00983 } 00984 00985 00986 void Surface::OnFocus() 00987 { 00988 } 00989 00990 00991 void Surface::OnLostFocus() 00992 { 00993 } 00994 00995 00996 void Surface::OnHide() 00997 { 00998 } 00999 01000 01001 void Surface::OnShow() 01002 { 01003 } 01004 01005 01006 void Surface::OnSize(SDL_Rect &r,int xrel,int yrel) 01007 { 01008 // kolla anchor, stretch 01009 if (IsAnchorRight()) 01010 { 01011 SetX(GetX() + xrel); 01012 } 01013 if (IsAnchorDown()) 01014 { 01015 SetY(GetY() + yrel); 01016 } 01017 } 01018 01019 01020 void Surface::OnMouseMove(coord_t x,coord_t y,coord_t xrel,coord_t yrel) 01021 { 01022 } 01023 01024 01025 void Surface::OnRightClick(coord_t x,coord_t y) 01026 { 01027 Surface *pclParent = GetParent(); 01028 01029 if (pclParent) 01030 { 01031 pclParent -> OnRightClick(x,y); 01032 } 01033 } 01034 01035 01036 void Surface::OnClick(coord_t x,coord_t y) 01037 { 01038 Surface *pclParent = GetParent(); 01039 01040 if (pclParent) 01041 { 01042 pclParent -> OnClick(x,y); 01043 } 01044 } 01045 01046 01047 void Surface::OnTimer(long id) 01048 { 01049 } 01050 01051 01052 /* 01053 void Surface::SetTimer(long time_ms,long id,bool bRepeating) 01054 { 01055 GetSDLControl() -> GetTimerThread() -> Add(this, time_ms, id, bRepeating); 01056 } 01057 */ 01058 01059 01060 void Surface::SetParent(Surface *s) 01061 { 01062 m_pclParent = s; 01063 } 01064 01065 01066 void Surface::SetX(coord_t x) 01067 { 01068 m_x = x; 01069 } 01070 01071 01072 void Surface::SetY(coord_t y) 01073 { 01074 m_y = y; 01075 } 01076 01077 01078 void Surface::SetW(coord_t w,bool bRealloc) 01079 { 01080 m_clientRect.w = w - GetFrameWidth() * 2; 01081 m_absoluteRect.w = w; 01082 m_w = w; 01083 01084 if (bRealloc) 01085 { 01086 RecreateSurfaces(); 01087 } 01088 } 01089 01090 01091 void Surface::SetH(coord_t h,bool bRealloc) 01092 { 01093 m_clientRect.h = h - GetFrameWidth() * 2; 01094 m_absoluteRect.h = h; 01095 m_h = h; 01096 01097 if (bRealloc) 01098 { 01099 RecreateSurfaces(); 01100 } 01101 } 01102 01103 01104 void Surface::SetAlpha(alpha_t a,bool bRecurse) 01105 { 01106 surfacevector_t::iterator it; 01107 m_nAlpha = a; 01108 m_bAlphaIsSet = true; 01109 SDL_SetAlpha(m_screen, SDL_SRCALPHA|SDL_RLEACCEL, a); 01110 if (bRecurse) 01111 { 01112 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 01113 { 01114 (*it) -> UpdateAlpha(a); 01115 } 01116 } 01117 } 01118 01119 01120 void Surface::UpdateAlpha(alpha_t a) 01121 { 01122 surfacevector_t::iterator it; 01123 if (!m_bAlphaIsSet) 01124 { 01125 m_nAlpha = a; 01126 SDL_SetAlpha(m_screen, SDL_SRCALPHA|SDL_RLEACCEL, a); 01127 } 01128 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 01129 { 01130 (*it) -> UpdateAlpha(a); 01131 } 01132 } 01133 01134 01135 void Surface::SetAbsoluteX(coord_t x) 01136 { 01137 m_absoluteRect.x = x; 01138 m_x_absolute = x; 01139 } 01140 01141 01142 void Surface::SetAbsoluteY(coord_t y) 01143 { 01144 m_absoluteRect.y = y; 01145 m_y_absolute = y; 01146 } 01147 01148 01149 void Surface::SetVisible(bool b) 01150 { 01151 surfacevector_t::iterator it; 01152 01153 if (b != m_bVisible) 01154 { 01155 m_bVisible = b; 01156 for (it = m_ChildList.begin(); it != m_ChildList.end(); it++) 01157 { 01158 if (b) 01159 { 01160 (*it) -> OnShow(); 01161 } 01162 else 01163 { 01164 (*it) -> OnHide(); 01165 } 01166 } 01167 if (!b) 01168 { 01169 } 01170 // if (b) 01171 // { 01172 // BringToTop(); 01173 // } 01174 } 01175 } 01176 01177 01178 void Surface::SetChildrenVisible(bool b) 01179 { 01180 m_bChildrenVisible = b; 01181 } 01182 01183 01184 /* 01185 void Surface::SetBgColor(color_t pclColor) 01186 { 01187 m_BgColor = pclColor; 01188 m_bBgColorIsSet = true; 01189 } 01190 */ 01191 01192 01193 void Surface::SetBgColor(Uint8 r,Uint8 g,Uint8 b,Uint8 alpha) 01194 { 01195 m_bgColor.r = r; 01196 m_bgColor.g = g; 01197 m_bgColor.b = b; 01198 m_bgColor.unused = alpha; 01199 m_bBgColorIsSet = true; 01200 } 01201 01202 01203 /* 01204 void Surface::SetFgColor(color_t pclColor) 01205 { 01206 m_FgColor = pclColor; 01207 m_bFgColorIsSet = true; 01208 } 01209 */ 01210 01211 01212 void Surface::SetFgColor(Uint8 r,Uint8 g,Uint8 b,Uint8 alpha) 01213 { 01214 m_fgColor.r = r; 01215 m_fgColor.g = g; 01216 m_fgColor.b = b; 01217 m_fgColor.unused = alpha; 01218 m_bFgColorIsSet = true; 01219 } 01220 01221 01222 void Surface::SetTTFont(TTFont *pclTTFont) 01223 { 01224 m_pclTTFont = pclTTFont; 01225 } 01226 01227 01228 void Surface::SetFrameWidth(coord_t fw) 01229 { 01230 m_nFrameWidth = fw; 01231 m_bFrameWidthIsSet = true; 01232 01233 CalculateClientRect(); 01234 } 01235 01236 01237 void Surface::CalculateClientRect() 01238 { 01239 coord_t fw = GetFrameWidth(); 01240 01241 m_clientRect.x = fw; 01242 m_clientRect.y = fw; 01243 m_clientRect.w = m_w - fw * 2; 01244 m_clientRect.h = m_h - fw * 2; 01245 01246 for (surfacevector_t::iterator it = m_ChildList.begin(); it != m_ChildList.end(); it++) 01247 { 01248 (*it) -> CalculateClientRect(); 01249 } 01250 } 01251 01252 01253 /* 01254 void Surface::SetFrameColor(color_t pclColor) 01255 { 01256 m_FrameColor = pclColor; 01257 m_bFrameColorIsSet = true; 01258 } 01259 */ 01260 01261 01262 void Surface::SetFrameColor(Uint8 r,Uint8 g,Uint8 b,Uint8 alpha) 01263 { 01264 m_frameColor.r = r; 01265 m_frameColor.g = g; 01266 m_frameColor.b = b; 01267 m_frameColor.unused = alpha; 01268 m_bFrameColorIsSet = true; 01269 } 01270 01271 01272 SDL_Surface *Surface::GetScreen() 01273 { 01274 return m_screen; 01275 } 01276 01277 01278 Surface *Surface::GetParent() 01279 { 01280 return m_pclParent; 01281 } 01282 01283 01284 Surface *Surface::GetRoot() 01285 { 01286 return m_pclParent ? m_pclParent -> GetRoot() : this; 01287 } 01288 01289 01290 color_t Surface::GetBgColor() 01291 { 01292 if (IsInverted()) 01293 { 01294 if (m_bFgColorIsSet) 01295 { 01296 return SDL_MapRGBA(m_screen->format, m_fgColor.r, m_fgColor.g, m_fgColor.b, m_fgColor.unused); 01297 } 01298 if (m_pclParent) 01299 { 01300 return m_pclParent -> GetFgColor(); 01301 } 01302 return 0; 01303 } 01304 else 01305 { 01306 if (m_bBgColorIsSet) 01307 { 01308 return SDL_MapRGBA(m_screen->format, m_bgColor.r, m_bgColor.g, m_bgColor.b, m_bgColor.unused); 01309 } 01310 } 01311 if (m_pclParent) 01312 { 01313 return m_pclParent -> GetBgColor(); 01314 } 01315 return 0; 01316 } 01317 01318 01319 void Surface::GetBgColor(SDL_Color &color) 01320 { 01321 if (IsInverted()) 01322 { 01323 if (m_bFgColorIsSet) 01324 { 01325 color = m_fgColor; 01326 return; 01327 } 01328 if (m_pclParent) 01329 { 01330 m_pclParent -> GetFgColor(color); 01331 } 01332 } 01333 else 01334 { 01335 if (m_bBgColorIsSet) 01336 { 01337 color = m_bgColor; 01338 return; 01339 } 01340 if (m_pclParent) 01341 { 01342 m_pclParent -> GetBgColor(color); 01343 } 01344 } 01345 } 01346 01347 01348 color_t Surface::GetFgColor() 01349 { 01350 if (IsInverted()) 01351 { 01352 if (m_bBgColorIsSet) 01353 { 01354 return SDL_MapRGBA(m_screen->format, m_bgColor.r, m_bgColor.g, m_bgColor.b, m_bgColor.unused); 01355 } 01356 if (m_pclParent) 01357 { 01358 return m_pclParent -> GetBgColor(); 01359 } 01360 return 0; 01361 } 01362 else 01363 { 01364 if (m_bFgColorIsSet) 01365 { 01366 return SDL_MapRGBA(m_screen->format, m_fgColor.r, m_fgColor.g, m_fgColor.b, m_fgColor.unused); 01367 } 01368 } 01369 if (m_pclParent) 01370 { 01371 return m_pclParent -> GetFgColor(); 01372 } 01373 return 0; 01374 } 01375 01376 01377 void Surface::GetFgColor(SDL_Color &color) 01378 { 01379 if (IsInverted()) 01380 { 01381 if (m_bBgColorIsSet) 01382 { 01383 color = m_bgColor; 01384 return; 01385 } 01386 if (m_pclParent) 01387 { 01388 m_pclParent -> GetBgColor(color); 01389 } 01390 } 01391 else 01392 { 01393 if (m_bFgColorIsSet) 01394 { 01395 color = m_fgColor; 01396 return; 01397 } 01398 if (m_pclParent) 01399 { 01400 m_pclParent -> GetFgColor(color); 01401 } 01402 } 01403 } 01404 01405 01406 TTFont *Surface::GetTTFont() 01407 { 01408 return m_pclTTFont ? m_pclTTFont : (m_pclParent ? m_pclParent -> GetTTFont() : NULL); 01409 } 01410 01411 01412 alpha_t Surface::GetAlpha() 01413 { 01414 if (m_bAlphaIsSet) 01415 { 01416 return m_nAlpha; 01417 } 01418 if (m_pclParent) 01419 { 01420 return m_pclParent -> GetAlpha(); 01421 } 01422 return 0; 01423 } 01424 01425 01426 coord_t Surface::GetFrameWidth() 01427 { 01428 if (m_bFrameWidthIsSet) 01429 { 01430 return m_nFrameWidth; 01431 } 01432 if (m_pclParent) 01433 { 01434 return m_pclParent -> GetFrameWidth(); 01435 } 01436 return 0; 01437 } 01438 01439 01440 color_t Surface::GetFrameColor() 01441 { 01442 if (m_bFrameColorIsSet) 01443 { 01444 return SDL_MapRGBA(m_screen->format, m_frameColor.r, m_frameColor.g, m_frameColor.b, m_frameColor.unused); 01445 } 01446 if (m_pclParent) 01447 { 01448 return m_pclParent -> GetFrameColor(); 01449 } 01450 return 0; 01451 } 01452 01453 01454 void Surface::GetFrameColor(SDL_Color &color) 01455 { 01456 if (m_bFrameColorIsSet) 01457 { 01458 color = m_frameColor; 01459 return; 01460 } 01461 if (m_pclParent) 01462 { 01463 m_pclParent -> GetFrameColor(color); 01464 } 01465 } 01466 01467 01468 SDL_Rect *Surface::GetClientRectPtr() 01469 { 01470 return &m_clientRect; 01471 } 01472 01473 01474 SDL_Rect Surface::GetClientRect() 01475 { 01476 return m_clientRect; 01477 } 01478 01479 01480 SDL_Rect *Surface::GetAbsoluteRectPtr() 01481 { 01482 return &m_absoluteRect; 01483 } 01484 01485 01486 SDL_Rect Surface::GetAbsoluteRect() 01487 { 01488 return m_absoluteRect; 01489 } 01490 01491 01492 SDLControl *Surface::GetSDLControl() 01493 { 01494 return m_pclControl ? m_pclControl : (m_pclParent ? m_pclParent -> GetSDLControl() : NULL); 01495 } 01496 01497 01498 void Surface::SetLocalID(unsigned long l) 01499 { 01500 m_local_id = l; 01501 } 01502 01503 01504 unsigned long Surface::GetID() 01505 { 01506 return m_id; 01507 } 01508 01509 01510 unsigned long Surface::GetLocalID() 01511 { 01512 return m_local_id; 01513 } 01514 01515 01516 /* 01517 void Surface::SetName(const string &str) 01518 { 01519 m_strName = str; 01520 } 01521 01522 01523 const char *Surface::GetName() 01524 { 01525 return m_strName.c_str(); 01526 } 01527 */ 01528 01529 01530 coord_t Surface::GetX() 01531 { 01532 return m_x; 01533 } 01534 01535 01536 coord_t Surface::GetY() 01537 { 01538 return m_y; 01539 } 01540 01541 01542 bool Surface::IsVisible() 01543 { 01544 return m_bVisible; 01545 } 01546 01547 01548 coord_t Surface::GetW() 01549 { 01550 return m_w; 01551 } 01552 01553 01554 coord_t Surface::GetH() 01555 { 01556 return m_h; 01557 } 01558 01559 01560 coord_t Surface::GetAbsoluteX() 01561 { 01562 return m_x_absolute; 01563 } 01564 01565 01566 coord_t Surface::GetAbsoluteY() 01567 { 01568 return m_y_absolute; 01569 } 01570 01571 01572 void Surface::SetInverted(bool b) 01573 { 01574 m_bInverted = b; 01575 } 01576 01577 01578 bool Surface::IsInverted() 01579 { 01580 return m_bInverted; 01581 } 01582 01583 01584 void Surface::SetTransparent(bool b) 01585 { 01586 m_bTransparent = b; 01587 } 01588 01589 01590 bool Surface::IsTransparent() 01591 { 01592 return m_bTransparent; 01593 } 01594 01595 01596 /* 01597 void Surface::SetStyle(style_t b) 01598 { 01599 m_style = b; 01600 } 01601 01602 01603 style_t Surface::GetStyle() 01604 { 01605 return m_style; 01606 } 01607 */ 01608 01609 01610 void Surface::SetMoveable(bool b) 01611 { 01612 m_bMoveable = b; 01613 } 01614 01615 01616 bool Surface::IsMoveable() 01617 { 01618 return m_bMoveable; 01619 } 01620 01621 01622 void Surface::SetDirty(bool b,bool bInvalidate) 01623 { 01624 if (b && !m_bDirty && bInvalidate) 01625 { 01626 m_bDirty = b; 01627 InvalidateEv(); 01628 } 01629 else 01630 { 01631 m_bDirty = b; 01632 } 01633 } 01634 01635 01636 bool Surface::IsDirty() 01637 { 01638 return m_bDirty; 01639 } 01640 01641 01642 void Surface::CreateTemporaryScreen() 01643 { 01644 m_temp_screen = CreateSDLSurface(false); 01645 SetUseTemporaryScreen(true); 01646 SDL_SetAlpha(m_temp_screen, SDL_SRCALPHA|SDL_RLEACCEL, 192); //SDL_ALPHA_OPAQUE); 01647 } 01648 01649 01650 void Surface::DrawTemporaryScreen() 01651 { 01652 if (UseTemporaryScreen() && m_temp_screen) 01653 { 01654 SetUseTemporaryScreen(false); 01655 m_bRedrawTemporary = true; 01656 Blit(-GetX(),-GetY(),m_temp_screen); 01657 SetUseTemporaryScreen(true); 01658 m_bRedrawTemporary = false; 01659 } 01660 } 01661 01662 01663 void Surface::SetUseTemporaryScreen(bool b) 01664 { 01665 m_bUseTemporaryScreen = b; 01666 } 01667 01668 01669 bool Surface::UseTemporaryScreen() 01670 { 01671 return m_bUseTemporaryScreen; 01672 } 01673 01674 01675 SDL_Surface *Surface::GetTemporaryScreen() 01676 { 01677 return m_temp_screen; 01678 } 01679 01680 01681 void Surface::SetText(const string &str) 01682 { 01683 m_text = str; 01684 SetDirty(true); 01685 } 01686 01687 01688 const char *Surface::GetText() 01689 { 01690 return m_text.c_str(); 01691 } 01692 01693 01694 void Surface::SetResizeArea(bool b) 01695 { 01696 m_bResizeArea = b; 01697 } 01698 01699 01700 bool Surface::IsResizeArea() 01701 { 01702 return m_bResizeArea; 01703 } 01704 01705 01706 void Surface::SetAnchorRight(bool b) 01707 { 01708 m_bAnchorRight = b; 01709 } 01710 01711 01712 bool Surface::IsAnchorRight() 01713 { 01714 return m_bAnchorRight; 01715 } 01716 01717 01718 void Surface::SetAnchorDown(bool b) 01719 { 01720 m_bAnchorDown = b; 01721 } 01722 01723 01724 bool Surface::IsAnchorDown() 01725 { 01726 return m_bAnchorDown; 01727 } 01728 01729 01730 void Surface::SetMustBeDeleted(bool b) 01731 { 01732 m_bMustBeDeleted = b; 01733 } 01734 01735 01736 bool Surface::MustBeDeleted() 01737 { 01738 return m_bMustBeDeleted; 01739 } 01740 01741 01742 void Surface::SetClickable(bool b) 01743 { 01744 m_bClickable = b; 01745 } 01746 01747 01748 bool Surface::IsClickable() 01749 { 01750 return m_bClickable; 01751 } 01752 01753 01754 void Surface::Bond(Surface *s) 01755 { 01756 surfacevector_t::iterator it; 01757 01758 for (it = m_bonds.begin(); it != m_bonds.end(); it++) 01759 { 01760 if (*it == s) 01761 { 01762 return; 01763 } 01764 } 01765 m_bonds.insert(m_bonds.end(), s); 01766 s -> SetBond(this); 01767 } 01768 01769 01770 void Surface::Unbond(Surface *s) 01771 { 01772 surfacevector_t::iterator it; 01773 01774 for (it = m_bonds.begin(); it != m_bonds.end(); it++) 01775 { 01776 if (*it == s) 01777 { 01778 m_bonds.erase(it); 01779 s -> SetBond(NULL); 01780 return; 01781 } 01782 } 01783 } 01784 01785 01786 void Surface::SetBond(Surface *s) 01787 { 01788 m_pclBond = s; 01789 } 01790 01791 01792 Surface *Surface::GetBond() 01793 { 01794 return m_pclBond; 01795 } 01796 01797 01798 void Surface::RemoveAllBonds() 01799 { 01800 SetBond(NULL); 01801 while (m_bonds.size() > 0) 01802 { 01803 surfacevector_t::iterator it = m_bonds.begin(); 01804 (*it) -> RemoveAllBonds(); 01805 m_bonds.erase(it); 01806 } 01807 } 01808 01809 01810 void Surface::CloseAll() 01811 { 01812 surfacevector_t::iterator it; 01813 01814 OnClose(); 01815 for (it = m_bonds.begin(); it != m_bonds.end(); it++) 01816 { 01817 (*it) -> CloseAll(); 01818 } 01819 } 01820 01821 01822 void Surface::GetExtents(SDL_Rect &r) 01823 { 01824 SDL_Rect a = GetAbsoluteRect(); 01825 coord_t right = a.x + a.w; 01826 coord_t bottom = a.y + a.h; 01827 01828 r.x = a.x < r.x ? a.x : r.x; 01829 r.y = a.y < r.y ? a.y : r.y; 01830 r.w = right > r.w ? right : r.w; 01831 r.h = bottom> r.h ? bottom: r.w; 01832 01833 for (surfacevector_t::iterator it = m_bonds.begin(); it != m_bonds.end(); it++) 01834 { 01835 (*it) -> GetExtents(r); 01836 } 01837 } 01838 01839 01840 void Surface::SetUICommand(long id) 01841 { 01842 m_uicommand = id; 01843 } 01844 01845 01846 long Surface::GetUICommand() 01847 { 01848 return m_uicommand; 01849 } 01850 01851 01852 void Surface::Dump(FILE *fil) 01853 { 01854 string tag; 01855 if (dynamic_cast<Button *>(this)) 01856 { 01857 tag = "Button"; 01858 } 01859 else 01860 if (dynamic_cast<Dialog *>(this)) 01861 { 01862 tag = "Dialog"; 01863 } 01864 else 01865 if (dynamic_cast<Edit *>(this)) 01866 { 01867 tag = "Edit"; 01868 } 01869 else 01870 if (dynamic_cast<Hotspot *>(this)) 01871 { 01872 tag = "Hotspot"; 01873 } 01874 else 01875 if (dynamic_cast<Menu *>(this)) 01876 { 01877 tag = "Menu"; 01878 } 01879 else 01880 if (dynamic_cast<MenuItem *>(this)) 01881 { 01882 tag = "MenuItem"; 01883 } 01884 else 01885 if (dynamic_cast<Output *>(this)) 01886 { 01887 tag = "Output"; 01888 } 01889 else 01890 if (dynamic_cast<PopupMenuItem *>(this)) 01891 { 01892 tag = "PopupMenuItem"; 01893 } 01894 else 01895 if (dynamic_cast<Progress *>(this)) 01896 { 01897 tag = "Progress"; 01898 } 01899 else 01900 if (dynamic_cast<SeparatorMenuItem *>(this)) 01901 { 01902 tag = "SeparatorMenuItem"; 01903 } 01904 else 01905 if (dynamic_cast<Static *>(this)) 01906 { 01907 tag = "Static"; 01908 } 01909 else 01910 { 01911 tag = "no_cast"; 01912 } 01913 01914 fprintf(fil,"<%s>\n",tag.c_str()); 01915 DumpMembers(fil); 01916 for (surfacevector_t::iterator it = m_ChildList.begin(); it != m_ChildList.end(); it++) 01917 { 01918 (*it) -> Dump(fil); 01919 } 01920 fprintf(fil,"</%s>\n",tag.c_str()); 01921 } 01922 01923 01924 /* 01925 coord_t m_x; ok 01926 coord_t m_y; ok 01927 coord_t m_w; ok 01928 coord_t m_h; ok 01929 coord_t m_x_absolute; - 01930 coord_t m_y_absolute; - 01931 SDL_Color m_bgColor; ok 01932 bool m_bBgColorIsSet; ok 01933 SDL_Color m_fgColor; ok 01934 bool m_bFgColorIsSet; ok 01935 SDL_Color m_frameColor; ok 01936 bool m_bFrameColorIsSet; ok 01937 TTFont * m_pclTTFont; ? 01938 alpha_t m_nAlpha; ok 01939 bool m_bAlphaIsSet; ok 01940 coord_t m_nFrameWidth; ok 01941 bool m_bFrameWidthIsSet; ok 01942 SDL_Rect m_clientRect; - 01943 string m_strName; ? rensas? 01944 SDL_Rect m_absoluteRect; - 01945 style_t m_style; ? rensas? 01946 // flags 01947 bool m_bVisible; ok 01948 bool m_bChildrenVisible; ok 01949 bool m_bInverted; - 01950 bool m_bTransparent; ok 01951 bool m_bMoveable; ok 01952 bool m_bDirty; - 01953 bool m_bResizeArea; ok 01954 bool m_bAnchorRight; ok 01955 bool m_bAnchorDown; ok 01956 bool m_bMustBeDeleted; - 01957 bool m_bClickable; ok 01958 // end of flags 01959 bool m_bUseTemporaryScreen; ok 01960 string m_text; ok 01961 bool m_bRedrawTemporary; - 01962 surfacevector_t m_bonds; - 01963 Surface *m_pclBond; - 01964 long m_uicommand; ok 01965 */ 01966 void Surface::DumpMembers(FILE *fil) 01967 { 01968 Xml xml(fil); 01969 01970 xml.Write("TEXT",m_text); 01971 if (m_uicommand != UICOMMAND_NONE) 01972 { 01973 xml.Write("UICOMMAND",m_uicommand); 01974 } 01975 xml.Write("X", (long)m_x); 01976 xml.Write("Y", (long)m_y); 01977 xml.Write("WIDTH", (long)m_w); 01978 xml.Write("HEIGHT", (long)m_h); 01979 xml.Write("BGCOLORISSET",m_bBgColorIsSet); 01980 if (m_bBgColorIsSet) 01981 { 01982 xml.Write("BGCOLOR",m_bgColor); 01983 } 01984 xml.Write("FGCOLORISSET",m_bFgColorIsSet); 01985 if (m_bFgColorIsSet) 01986 { 01987 xml.Write("FGCOLOR",m_fgColor); 01988 } 01989 xml.Write("FRAMECOLORISSET",m_bFrameColorIsSet); 01990 if (m_bFrameColorIsSet) 01991 { 01992 xml.Write("FRAMECOLOR",m_frameColor); 01993 } 01994 xml.Write("ALPHAISSET",m_bAlphaIsSet); 01995 if (m_bAlphaIsSet) 01996 { 01997 xml.Write("ALPHA", (long)m_nAlpha); 01998 } 01999 xml.Write("FRAMEWIDTHISSET",m_bFrameWidthIsSet); 02000 if (m_bFrameWidthIsSet) 02001 { 02002 xml.Write("FRAMEWIDTH", (long)m_nFrameWidth); 02003 } 02004 xml.Write("VISIBLE",m_bVisible); 02005 xml.Write("CHILDRENVISIBLE",m_bChildrenVisible); 02006 xml.Write("TRANSPARENT",m_bTransparent); 02007 xml.Write("MOVEABLE",m_bMoveable); 02008 xml.Write("RESIZEAREA",m_bResizeArea); 02009 xml.Write("ANCHORRIGHT",m_bAnchorRight); 02010 xml.Write("ANCHORDOWN",m_bAnchorDown); 02011 xml.Write("CLICKABLE",m_bClickable); 02012 xml.Write("USETEMPORARYSCREEN",m_bUseTemporaryScreen); 02013 } 02014 02015 02016 void Surface::SaveDialogs() 02017 { 02018 if (dynamic_cast<Dialog *>(this)) 02019 { 02020 FILE *fil; 02021 char fn[200]; 02022 02023 sprintf(fn,"%s.xml",GetText()); 02024 if (strlen(fn) > 4) 02025 { 02026 if ((fil = fopen(fn,"wt")) != NULL) 02027 { 02028 fprintf(fil,"<?xml version=\"1.0\"?>\n"); 02029 Dump(fil); 02030 fclose(fil); 02031 } 02032 } 02033 } 02034 for (surfacevector_t::iterator it = m_ChildList.begin(); it != m_ChildList.end(); it++) 02035 { 02036 (*it) -> SaveDialogs(); 02037 } 02038 } 02039 02040 02041 } // namespace

Generated for My SDL C++ Gui by doxygen 1.3.6

www.TV-friendship.com
The matchmaking service with an all new twist.

Quantum 'Teleportation'
Some thoughts
Page, code, and content Copyright (C) 2004 by Anders Hedström