void Thread::Join() { assert(IsDefined()); assert(!IsInside()); #ifdef HAVE_POSIX pthread_join(handle, nullptr); defined = false; #else ::WaitForSingleObject(handle, INFINITE); ::CloseHandle(handle); handle = nullptr; #endif #ifndef NDEBUG all_threads_mutex.lock(); all_threads.erase(all_threads.iterator_to(*this)); all_threads_mutex.unlock(); #endif }
unsigned CClanMemberItem::Process( unsigned uiMsg, WPARAM wParam, LPARAM lParam ) { if( !IsInside( LOWORD(lParam), HIWORD( lParam )) ) return 0; switch( uiMsg ) { case WM_LBUTTONDOWN: { CTDialog* pDlg = g_itMGR.FindDlg( DLG_TYPE_CLAN ); if( pDlg ) { CClanDlg* pClanDlg = (CClanDlg*)pDlg; pClanDlg->SetSelectedMember( m_iClanPoint ); } SetSelected(); } return GetControlID(); default: break; } return 0; }
void UIBase::Input(){ int key = InputManager::GetInstance().GetMouseMousePressKey(); Point mpos = InputManager::GetInstance().GetMouse(); if (IsInside(mpos.x,mpos.y)){ if (key != 0 && OnMousePress){ OnMousePress(this,key,mpos); } key = InputManager::GetInstance().GetMouseMouseReleaseKey(); if (key != 0 && OnMouseRelease){ OnMouseRelease(this,key,mpos); } if (!MouseInside){ if (OnMouseEnter){ OnMouseEnter(this,mpos); } MouseInside = true; } }else{ if (MouseInside){ if (OnMouseLeave){ OnMouseLeave(this,mpos); } MouseInside = false; } } key = InputManager::GetInstance().IsAnyKeyPressed(); if (key != -1 && OnKeyPress){ OnKeyPress(this,key); } /*for (unsigned i = 0; i < Components.size(); ++i) { if (!Components[i]->IsDead()){ Components[i]->Input(); } }*/ }
WMSG_RESULT CUIPortal::OnLButtonDown( UINT16 x, UINT16 y ) { if (m_bHide) return WMSG_FAIL; if (IsInside(x, y) == FALSE) { Close(); return WMSG_FAIL; } if( m_pmoveArea && m_pmoveArea->IsInside(x, y)) { m_bDrag = true; m_nOriX = x; m_nOriY = y; } CUIManager::getSingleton()->RearrangeOrder( UI_PORTAL, TRUE ); return WMSG_FAIL; }
void IOThread::LockRemove(int fd) { mutex.Lock(); const bool old_modified = modified; Remove(fd); const bool new_modified = modified; if (new_modified && running && !IsInside()) { /* this method is synchronous: after returning, all handlers must be finished */ do { cond.Wait(mutex); } while (running); } mutex.Unlock(); if (!old_modified && new_modified) pipe.Signal(); }
WMSG_RESULT CUITrade::OnLButtonDBLClick( UINT16 x, UINT16 y ) { if (m_bHide) return WMSG_FAIL; if (IsInside(x, y) == FALSE) return WMSG_FAIL; if (m_pList[eLIST_AMEND_ITEM]->IsInside(x, y) == TRUE) { if (m_pList[eLIST_AMEND_ITEM]->HitTest(x, y) < 0) { UpdateAmendItem(-1); UpdateAmendCondition(-1); if (m_pBtnOk != NULL) m_pBtnOk->SetEnable(FALSE); } } return WMSG_SUCCESS; }
WMSG_RESULT CUIQuestBook::OnLButtonDown( UINT16 x, UINT16 y ) { if (m_bHide) return WMSG_FAIL; if (m_bLockQuestList == TRUE) return WMSG_FAIL; if (IsInside(x, y) == FALSE) return WMSG_FAIL; if( m_pmoveArea && m_pmoveArea->IsInside(x, y)) { m_bDrag = true; m_nOriX = x; m_nOriY = y; } CUIManager::getSingleton()->RearrangeOrder( UI_QUESTBOOK_LIST, TRUE ); return WMSG_FAIL; }
bool Frustum::IsVisible(const Node& node, Mesh& mesh) const { if (mesh.IsReady()) { Vertex3 center = node.GetGlobalPosition(); float radius = mesh.GetBoundingSphereRadius(); Vector3 scale = node.GetGlobalScale(); float maxScale = std::max(std::max(scale.x, scale.y), scale.z); radius *= maxScale; Intersection sphereFrustumIntersec = IsSphereInside(center, radius); if (sphereFrustumIntersec == Intersection::INTERSECTS) { BoundingBox bb = mesh.GetBB(); bb.Transform(node); return IsInside(bb) != Intersection::OUTSIDE; } else return sphereFrustumIntersec != Intersection::OUTSIDE; } return false; }
bool Thread::Join(unsigned timeout_ms) { assert(IsDefined()); assert(!IsInside()); bool result = ::WaitForSingleObject(handle, timeout_ms) == WAIT_OBJECT_0; if (result) { ::CloseHandle(handle); handle = NULL; #ifndef NDEBUG { all_threads_mutex.Lock(); siblings.Remove(); all_threads_mutex.Unlock(); } #endif } return result; }
bool Thread::Join(unsigned timeout_ms) { assert(IsDefined()); assert(!IsInside()); bool result = ::WaitForSingleObject(handle, timeout_ms) == WAIT_OBJECT_0; if (result) { ::CloseHandle(handle); handle = nullptr; #ifndef NDEBUG { all_threads_mutex.lock(); all_threads.erase(all_threads.iterator_to(*this)); all_threads_mutex.unlock(); } #endif } return result; }
WMSG_RESULT CUIBase::MouseWheel(UINT16 x, UINT16 y, int wheel) { if (m_bHide) return WMSG_FAIL; if (IsInside(x, y) == FALSE) return WMSG_FAIL; WMSG_RESULT ret = WMSG_FAIL; if (wheel > 0) OnMouseWheelUp(); else if (wheel < 0) OnMouseWheelDown(); ret = OnMouseWheel(x, y, wheel); if (ret == WMSG_FAIL) ret = MouseWheelChild(x, y, wheel); return ret; }
//================================================================================================= void ListBox::Update(float dt) { if(extended) { if(menu->visible) { // powinno byæ aktualizowane tu ale niestety wed³ug kolejnoœci musi byæ na samym pocz¹tku //menu->Update(dt); if(!menu->focus) menu->visible = false; } else if(mouse_focus && Key.Focus() && PointInRect(GUI.cursor_pos, global_pos, size) && Key.PressedRelease(VK_LBUTTON)) { menu->global_pos = global_pos + INT2(0,size.y); if(menu->global_pos.y+menu->size.y >= GUI.wnd_size.y) menu->global_pos.y = GUI.wnd_size.y-menu->size.y; menu->visible = true; menu->focus = true; } } else { if(mouse_focus && Key.Focus() && PointInRect(GUI.cursor_pos, global_pos, real_size) && Key.PressedRelease(VK_LBUTTON)) { int n = (GUI.cursor_pos.y-global_pos.y+int(scrollbar.offset))/20; if(n >= 0 && n < (int)items.size() && n != selected) { selected = n; if(e_change_index) e_change_index(n); } } if(IsInside(GUI.cursor_pos)) scrollbar.ApplyMouseWheel(); scrollbar.Update(dt); } }
void CClanMemberItem::Update( POINT ptMouse ) { CTDialog* pDlg = CTDialog::GetProcessMouseOverDialog(); if( pDlg && pDlg->GetDialogType() != DLG_TYPE_CLAN ) return; if( IsInside( ptMouse.x, ptMouse.y) && m_iChannelNo != 0xFF) { m_Info.Clear(); POINT ptDraw = m_sPosition; ptDraw.y -= 50; ptDraw.x += 25; m_Info.SetPosition( ptDraw ); m_Info.AddString( CStr::Printf("%s: %d", CStringManager::GetSingleton().GetAbility( AT_LEVEL ), m_nLevel ) ); m_Info.AddString( CStr::Printf("%s: %s", CStringManager::GetSingleton().GetAbility( AT_CLASS ), m_strJob.c_str() ) ); m_Info.AddString( CStr::Printf("%s: %d","Channel", m_iChannelNo ) ); CToolTipMgr::GetInstance().RegistInfo( m_Info ); } }
unsigned int CSlotBuyPrivateStore::Process( UINT uiMsg,WPARAM wParam,LPARAM lParam ) { POINT pt = { LOWORD( lParam ), HIWORD( lParam ) }; if( !IsInside( pt.x, pt.y )) return 0; CIcon* pIcon = GetIcon(); if( pIcon && uiMsg == WM_LBUTTONDOWN && GetAsyncKeyState( VK_SHIFT ) < 0 ) { CIconItem* pItemIcon = (CIconItem*)pIcon; if( m_bExhibition ) { CPrivateStore::GetInstance().RemoveItemBuyList( pItemIcon->GetIndex() ); } else { CTDialog* pDlg = g_itMGR.FindDlg( DLG_TYPE_GOODS ); if( pDlg ) { CGoodsDlg* pGoodsDlg = (CGoodsDlg*)pDlg; pGoodsDlg->SetIcon( pItemIcon ); pGoodsDlg->SetType( CGoodsDlg::ADD_BUYLIST ); g_itMGR.OpenDialog( DLG_TYPE_GOODS ); } } return uiMsg; } if( m_bExhibition ) { if( uiMsg == WM_LBUTTONDOWN ) return uiMsg; return 0; } return CSlot::Process( uiMsg, wParam, lParam ); }
int EditBox::HandleEvent(MouseEvent* evt){ if(!Visible()) return 0; if(evt->button != LBUTTON) return 0; bool inside = IsInside(evt->pos); if(evt->type == BUTTON_DOWN && inside){ mClicked = true; mClickPos = evt->pos; UiState::mFocus = this; }else if(evt->type == BUTTON_UP){ mClicked = false; if(!inside) return 0; int cStart = GetCaretFromX(mClickPos.x - mPosition.x); int cEnd = GetCaretFromX(evt->pos.x - mPosition.x); mCaret = cEnd; if(cStart == cEnd){ mSelectStart = mCaret; mSelectEnd = mCaret; } } return mID; }
WMSG_RESULT CUITrade::OnMouseMove( UINT16 x, UINT16 y, MSG* pMsg ) { if (m_bHide) return WMSG_FAIL; if( m_bDrag && ( pMsg->wParam & MK_LBUTTON ) ) { int ndX = x - m_nOriX; int ndY = y - m_nOriY; m_nOriX = x; m_nOriY = y; Move( ndX, ndY ); return WMSG_SUCCESS; } if (IsInside(x, y) == FALSE) return WMSG_FAIL; UIMGR()->SetMouseCursorInsideUIs(); return CUIBase::OnMouseMove(x, y, pMsg); }
WMSG_RESULT CUIPortal::OnMouseMove( UINT16 x, UINT16 y, MSG* pMsg ) { if (m_bHide) return WMSG_FAIL; if( m_bDrag && ( pMsg->wParam & MK_LBUTTON ) ) { int ndX = x - m_nOriX; int ndY = y - m_nOriY; m_nOriX = x; m_nOriY = y; Move( ndX, ndY ); return WMSG_SUCCESS; } if (IsInside(x, y) == FALSE) return WMSG_FAIL; CUIManager::getSingleton()->SetMouseCursorInsideUIs(); return WMSG_FAIL; }
bool cBoundingBox::IsInside(const Vector3d & a_Point) { return IsInside(m_Min, m_Max, a_Point); }
void SaveGame(const std::string& filename, const ServerSaveGameData& server_save_game_data, const std::vector<PlayerSaveGameData>& player_save_game_data, const Universe& universe, const EmpireManager& empire_manager, const SpeciesManager& species_manager, const CombatLogManager& combat_log_manager, const GalaxySetupData& galaxy_setup_data, bool multiplayer) { ScopedTimer timer("SaveGame: " + filename, true); bool use_binary = GetOptionsDB().Get<bool>("binary-serialization"); DebugLogger() << "SaveGame(" << (use_binary ? "binary" : "zlib-xml") << ") filename: " << filename; GetUniverse().EncodingEmpire() = ALL_EMPIRES; DebugLogger() << "Compiling save empire and preview data"; std::map<int, SaveGameEmpireData> empire_save_game_data = CompileSaveGameEmpireData(empire_manager); SaveGamePreviewData save_preview_data; CompileSaveGamePreviewData(server_save_game_data, player_save_game_data, empire_save_game_data, save_preview_data); // reinterpret save game data as header data for uncompressed header std::vector<PlayerSaveHeaderData> player_save_header_data; for (std::vector<PlayerSaveGameData>::const_iterator it = player_save_game_data.begin(); it != player_save_game_data.end(); ++it) { player_save_header_data.push_back(*it); } try { fs::path path = FilenameToPath(filename); // A relative path should be relative to the save directory. if (path.is_relative()) { path = GetSaveDir()/path; DebugLogger() << "Made save path relative to save dir. Is now: " << path; } if (multiplayer) { // Make sure the path points into our save directory if (!IsInside(path, GetSaveDir())) { path = GetSaveDir() / path.filename(); } } // set up output archive / stream for saving fs::ofstream ofs(path, std::ios_base::binary); if (!ofs) throw std::runtime_error(UNABLE_TO_OPEN_FILE); if (use_binary) { DebugLogger() << "Creating binary oarchive"; freeorion_bin_oarchive boa(ofs); boa << BOOST_SERIALIZATION_NVP(save_preview_data); boa << BOOST_SERIALIZATION_NVP(galaxy_setup_data); boa << BOOST_SERIALIZATION_NVP(server_save_game_data); boa << BOOST_SERIALIZATION_NVP(player_save_header_data); boa << BOOST_SERIALIZATION_NVP(empire_save_game_data); boa << BOOST_SERIALIZATION_NVP(player_save_game_data); boa << BOOST_SERIALIZATION_NVP(empire_manager); boa << BOOST_SERIALIZATION_NVP(species_manager); boa << BOOST_SERIALIZATION_NVP(combat_log_manager); Serialize(boa, universe); DebugLogger() << "Done serializing"; } else { // Two-tier serialization: // main archive is uncompressed serialized header data first // then contains a string for compressed second archive // that contains the main gamestate info // allocate buffers for serialized gamestate DebugLogger() << "Allocating buffers for XML serialization..."; std::string serial_str, compressed_str; try { serial_str.reserve( std::pow(2.0, 29.0)); compressed_str.reserve(std::pow(2.0, 26.0)); } catch (...) { DebugLogger() << "Unable to preallocate full serialization buffers. Attempting serialization with dynamic buffer allocation."; } // wrap buffer string in iostream::stream to receive serialized data typedef boost::iostreams::back_insert_device<std::string> InsertDevice; InsertDevice serial_inserter(serial_str); boost::iostreams::stream<InsertDevice> s_sink(serial_inserter); // create archive with (preallocated) buffer... freeorion_xml_oarchive xoa(s_sink); // serialize main gamestate info xoa << BOOST_SERIALIZATION_NVP(player_save_game_data); xoa << BOOST_SERIALIZATION_NVP(empire_manager); xoa << BOOST_SERIALIZATION_NVP(species_manager); xoa << BOOST_SERIALIZATION_NVP(combat_log_manager); Serialize(xoa, universe); s_sink.flush(); // wrap gamestate string in iostream::stream to extract serialized data typedef boost::iostreams::basic_array_source<char> SourceDevice; SourceDevice source(serial_str.data(), serial_str.size()); boost::iostreams::stream<SourceDevice> s_source(source); // wrap compresed buffer string in iostream::streams to receive compressed string InsertDevice compressed_inserter(compressed_str); boost::iostreams::stream<InsertDevice> c_sink(compressed_inserter); // compression-filter gamestate into compressed string boost::iostreams::filtering_ostreambuf o; o.push(boost::iostreams::zlib_compressor()); o.push(c_sink); boost::iostreams::copy(s_source, o); c_sink.flush(); // write to save file: uncompressed header serialized data, with compressed main archive string at end... freeorion_xml_oarchive xoa2(ofs); // serialize uncompressed save header info xoa2 << BOOST_SERIALIZATION_NVP(save_preview_data); xoa2 << BOOST_SERIALIZATION_NVP(galaxy_setup_data); xoa2 << BOOST_SERIALIZATION_NVP(server_save_game_data); xoa2 << BOOST_SERIALIZATION_NVP(player_save_header_data); xoa2 << BOOST_SERIALIZATION_NVP(empire_save_game_data); // append compressed gamestate info xoa2 << BOOST_SERIALIZATION_NVP(compressed_str); } } catch (const std::exception& e) { ErrorLogger() << UserString("UNABLE_TO_WRITE_SAVE_FILE") << " SaveGame exception: " << ": " << e.what(); throw e; } DebugLogger() << "SaveGame : Successfully wrote save file"; }
//================================================================================================= void TeamPanel::Update(float dt) { GamePanel::Update(dt); if(focus) { if(Key.Focus() && IsInside(GUI.cursor_pos)) scrollbar.ApplyMouseWheel(); scrollbar.mouse_focus = mouse_focus; scrollbar.Update(dt); if(picking && Key.Focus()) { picked = -1; GUI.Intersect(hitboxes, GUI.cursor_pos, &picked); if(Key.Pressed(VK_LBUTTON)) { picking = false; if(picked >= 0) { target = Team.members[picked]; switch(mode) { case Bt_GiveGold: GiveGold(); break; case Bt_Kick: Kick(); break; case Bt_Leader: ChangeLeader(); break; } } } else if(Key.Pressed(VK_RBUTTON)) picking = false; } } // enable change leader button if player is leader if(Net::IsClient()) { bool was_leader = bt[2].state != Button::DISABLED; bool is_leader = Team.IsLeader(); if(was_leader != is_leader) bt[2].state = (is_leader ? Button::NONE : Button::DISABLED); } int count = (Net::IsOnline() ? 4 : 2); for(int i = 0; i < count; ++i) { bt[i].mouse_focus = focus; bt[i].Update(dt); } if(focus && Key.Focus() && Key.PressedRelease(VK_ESCAPE)) Hide(); }
/** * Returns pointer to alpha data for pixel (x,y). * * \author ***bd*** 2.2004 */ BYTE* CxImage::AlphaGetPointer(const long x,const long y) { if (pAlpha && IsInside(x,y)) return pAlpha+x+y*head.biWidth; return 0; }
/** * Adds a polygonal region to the existing selection. points points to an array of POINT structures. * Each structure specifies the x-coordinate and y-coordinate of one vertex of the polygon. * npoints specifies the number of POINT structures in the array pointed to by points. */ bool CxImage::SelectionAddPolygon(POINT *points, long npoints) { if (points==NULL || npoints<3) return false; if (pSelection==NULL) SelectionCreate(); if (pSelection==NULL) return false; BYTE* plocal = (BYTE*)calloc(head.biWidth*head.biHeight, 1); RECT localbox = {head.biWidth,0,0,head.biHeight}; long x,y,i=0; POINT *current,*next,*start; //trace contour while (i < npoints){ current = &points[i]; if (current->x!=-1){ if (i==0 || (i>0 && points[i-1].x==-1)) start = &points[i]; if ((i+1)==npoints || points[i+1].x==-1) next = start; else next = &points[i+1]; float beta; if (current->x != next->x){ beta = (float)(next->y - current->y)/(float)(next->x - current->x); if (current->x < next->x){ for (x=current->x; x<=next->x; x++){ y = (long)(current->y + (x - current->x) * beta); if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; } } else { for (x=current->x; x>=next->x; x--){ y = (long)(current->y + (x - current->x) * beta); if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; } } } if (current->y != next->y){ beta = (float)(next->x - current->x)/(float)(next->y - current->y); if (current->y < next->y){ for (y=current->y; y<=next->y; y++){ x = (long)(current->x + (y - current->y) * beta); if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; } } else { for (y=current->y; y>=next->y; y--){ x = (long)(current->x + (y - current->y) * beta); if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; } } } } RECT r2; if (current->x < next->x) {r2.left=current->x; r2.right=next->x; } else {r2.left=next->x ; r2.right=current->x; } if (current->y < next->y) {r2.bottom=current->y; r2.top=next->y; } else {r2.bottom=next->y ; r2.top=current->y; } if (localbox.top < r2.top) localbox.top = max(0L,min(head.biHeight-1,r2.top+1)); if (localbox.left > r2.left) localbox.left = max(0L,min(head.biWidth-1,r2.left-1)); if (localbox.right < r2.right) localbox.right = max(0L,min(head.biWidth-1,r2.right+1)); if (localbox.bottom > r2.bottom) localbox.bottom = max(0L,min(head.biHeight-1,r2.bottom-1)); i++; } //fill the outer region long npix=(localbox.right - localbox.left)*(localbox.top - localbox.bottom); POINT* pix = (POINT*)calloc(npix,sizeof(POINT)); BYTE back=0, mark=1; long fx, fy, fxx, fyy, first, last,xmin,xmax,ymin,ymax; for (int side=0; side<4; side++){ switch(side){ case 0: xmin=localbox.left; xmax=localbox.right+1; ymin=localbox.bottom; ymax=localbox.bottom+1; break; case 1: xmin=localbox.right; xmax=localbox.right+1; ymin=localbox.bottom; ymax=localbox.top+1; break; case 2: xmin=localbox.left; xmax=localbox.right+1; ymin=localbox.top; ymax=localbox.top+1; break; case 3: xmin=localbox.left; xmax=localbox.left+1; ymin=localbox.bottom; ymax=localbox.top+1; break; } //fill from the border points for(y=ymin;y<ymax;y++){ for(x=xmin;x<xmax;x++){ if (plocal[x+y*head.biWidth]==0){ // Subject: FLOOD FILL ROUTINE Date: 12-23-97 (00:57) // Author: Petter Holmberg Code: QB, QBasic, PDS // Origin: [email protected] Packet: GRAPHICS.ABC first=0; last=1; while(first!=last){ fx = pix[first].x; fy = pix[first].y; fxx = fx + x; fyy = fy + y; do { if ((plocal[fxx + fyy*head.biWidth] == back) && fxx>=localbox.left && fxx<=localbox.right && fyy>=localbox.bottom && fyy<=localbox.top ) { plocal[fxx + fyy*head.biWidth] = mark; if (fyy > 0 && plocal[fxx + (fyy - 1)*head.biWidth] == back){ pix[last].x = fx; pix[last].y = fy - 1; last++; if (last == npix) last = 0; } if ((fyy + 1)<head.biHeight && plocal[fxx + (fyy + 1)*head.biWidth] == back){ pix[last].x = fx; pix[last].y = fy + 1; last++; if (last == npix) last = 0; } } else { break; } fx++; fxx++; } while(1); fx = pix[first].x - 1; fy = pix[first].y; fxx = fx + x; fyy = fy + y; do { if ((plocal[fxx + fyy*head.biWidth] == back) && fxx>=localbox.left && fxx<=localbox.right && fyy>=localbox.bottom && fyy<=localbox.top ) { plocal[fxx + (y + fy)*head.biWidth] = mark; if (fyy > 0 && plocal[fxx + (fyy - 1)*head.biWidth] == back){ pix[last].x = fx; pix[last].y = fy - 1; last++; if (last == npix) last = 0; } if ((fyy + 1)<head.biHeight && plocal[fxx + (fyy + 1)*head.biWidth] == back){ pix[last].x = fx; pix[last].y = fy + 1; last++; if (last == npix) last = 0; } } else { break; } fx--; fxx--; } while(1); first++; if (first == npix) first = 0; } } } } } //transfer the region long yoffset; for (y=localbox.bottom; y<=localbox.top; y++){ yoffset = y * head.biWidth; for (x=localbox.left; x<=localbox.right; x++) if (plocal[x + yoffset]!=1) pSelection[x + yoffset]=255; } if (info.rSelectionBox.top < localbox.top) info.rSelectionBox.top = localbox.top+1; if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = localbox.left; if (info.rSelectionBox.right < localbox.right) info.rSelectionBox.right = localbox.right+1; if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = localbox.bottom; free(plocal); free(pix); return true; }
bool Rect::IsInside(float x, float y) { Point p(x, y); return IsInside(p); }
bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face) { if (IsInside(a_Min, a_Max, a_Line1)) { // The starting point is inside the bounding box. a_LineCoeff = 0; a_Face = BLOCK_FACE_NONE; // No faces hit return true; } eBlockFace Face = BLOCK_FACE_NONE; double Coeff = Vector3d::NO_INTERSECTION; // Check each individual bbox face for intersection with the line, remember the one with the lowest coeff double c = a_Line1.LineCoeffToXYPlane(a_Line2, a_Min.z); if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c)) { Face = (a_Line1.z > a_Line2.z) ? BLOCK_FACE_ZP : BLOCK_FACE_ZM; Coeff = c; } c = a_Line1.LineCoeffToXYPlane(a_Line2, a_Max.z); if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c)) { Face = (a_Line1.z > a_Line2.z) ? BLOCK_FACE_ZP : BLOCK_FACE_ZM; Coeff = c; } c = a_Line1.LineCoeffToXZPlane(a_Line2, a_Min.y); if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c)) { Face = (a_Line1.y > a_Line2.y) ? BLOCK_FACE_YP : BLOCK_FACE_YM; Coeff = c; } c = a_Line1.LineCoeffToXZPlane(a_Line2, a_Max.y); if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c)) { Face = (a_Line1.y > a_Line2.y) ? BLOCK_FACE_YP : BLOCK_FACE_YM; Coeff = c; } c = a_Line1.LineCoeffToYZPlane(a_Line2, a_Min.x); if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c)) { Face = (a_Line1.x > a_Line2.x) ? BLOCK_FACE_XP : BLOCK_FACE_XM; Coeff = c; } c = a_Line1.LineCoeffToYZPlane(a_Line2, a_Max.x); if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c)) { Face = (a_Line1.x > a_Line2.x) ? BLOCK_FACE_XP : BLOCK_FACE_XM; Coeff = c; } if (Coeff >= Vector3d::NO_INTERSECTION) { // There has been no intersection return false; } a_LineCoeff = Coeff; a_Face = Face; return true; }
bool cBoundingBox::IsInside(const Vector3d & a_Min, const Vector3d & a_Max) { // If both coords are inside this, then the entire a_Other is inside return (IsInside(a_Min) && IsInside(a_Max)); }
bool cBoundingBox::IsInside(cBoundingBox & a_Other) { // If both a_Other's coords are inside this, then the entire a_Other is inside return (IsInside(a_Other.m_Min) && IsInside(a_Other.m_Max)); }
gcc_pure bool IsInside(RasterPoint pt) const { return IsInside(pt.x, pt.y); }
static void UIObjectDrawAndAddChildren( UIObject *o, GraphicsDevice *g, Vec2i pos, Vec2i mouse, CArray *objs) { if (!o) { return; } if (o->CheckVisible) { o->CheckVisible(o, o->Data); } if (!o->IsVisible) { return; } int isHighlighted = UIObjectIsHighlighted(o); Vec2i oPos = Vec2iAdd(pos, o->Pos); switch (o->Type) { case UITYPE_LABEL: { const char *text = LabelGetText(o); if (!text) { break; } color_t textMask = isHighlighted ? colorRed : colorWhite; FontStrMaskWrap(text, oPos, textMask, o->Size.x); } break; case UITYPE_TEXTBOX: { int isText = !!o->u.Textbox.TextLinkFunc; const char *text = isText ? o->u.Textbox.TextLinkFunc(o, o->Data) : NULL; int isEmptyText = !isText || !text || strlen(text) == 0; color_t bracketMask = isHighlighted ? colorRed : colorWhite; color_t textMask = isEmptyText ? colorGray : colorWhite; int oPosX = oPos.x; if (isEmptyText) { text = o->u.Textbox.Hint; } if (!o->u.Textbox.IsEditable) { textMask = bracketMask; } if (o->u.Textbox.IsEditable) { oPos = FontChMask('>', oPos, bracketMask); } oPos = FontStrMaskWrap( text, oPos, textMask, o->Pos.x + o->Size.x - oPosX); if (o->u.Textbox.IsEditable) { oPos = FontChMask('<', oPos, bracketMask); } oPos.x = oPosX; } break; case UITYPE_TAB: if (o->Children.size > 0) { color_t textMask = isHighlighted ? colorRed : colorWhite; char **labelp = CArrayGet(&o->u.Tab.Labels, o->u.Tab.Index); UIObject **objp = CArrayGet(&o->Children, o->u.Tab.Index); FontStrMaskWrap( *labelp, Vec2iAdd(pos, o->Pos), textMask, o->Size.x); if (!((*objp)->Flags & UI_ENABLED_WHEN_PARENT_HIGHLIGHTED_ONLY) || isHighlighted) { UIObjectDrawAndAddChildren(*objp, g, oPos, mouse, objs); } } break; case UITYPE_BUTTON: { int isDown = o->u.Button.IsDownFunc && o->u.Button.IsDownFunc(o->Data); BlitMasked( g, o->u.Button.Pic, oPos, isDown ? colorGray : colorWhite, 1); } break; case UITYPE_CONTEXT_MENU: { // Draw background DrawRectangle( g, Vec2iAdd(oPos, Vec2iScale(Vec2iUnit(), -TOOLTIP_PADDING)), Vec2iAdd(o->Size, Vec2iScale(Vec2iUnit(), 2 * TOOLTIP_PADDING)), menuBGColor, 0); // Find if mouse over any children, and draw highlight for (int i = 0; i < (int)o->Children.size; i++) { UIObject *child = *(UIObject **)CArrayGet(&o->Children, i); if (IsInside(mouse, Vec2iAdd(oPos, child->Pos), child->Size)) { DrawRectangle( g, Vec2iAdd(oPos, child->Pos), child->Size, hiliteColor, 0); } } } break; case UITYPE_CUSTOM: o->u.CustomDrawFunc(o, g, pos, o->Data); break; default: // do nothing break; } // add children // Note: tab type draws its own children (one) if (o->Type != UITYPE_TAB && objs != NULL) { size_t i; UIObject **childPtr = o->Children.data; for (i = 0; i < o->Children.size; i++, childPtr++) { if (!((*childPtr)->Flags & UI_ENABLED_WHEN_PARENT_HIGHLIGHTED_ONLY) || isHighlighted) { UIObjectDrawContext c; c.obj = *childPtr; c.pos = oPos; CArrayPushBack(objs, &c); } } } }
// ---------------------------------------------------------------------------- // Name : MouseMessage() // Desc : // ---------------------------------------------------------------------------- WMSG_RESULT CUICompound::MouseMessage( MSG *pMsg ) { WMSG_RESULT wmsgResult; // Title bar static BOOL bTitleBarClick = FALSE; // Mouse point static int nOldX, nOldY; int nX = LOWORD( pMsg->lParam ); int nY = HIWORD( pMsg->lParam ); // Mouse message switch( pMsg->message ) { case WM_MOUSEMOVE: { CUIManager* pUIManager = CUIManager::getSingleton(); if( IsInside( nX, nY ) ) { pUIManager->SetMouseCursorInsideUIs(); if( IsInsideRect( nX, nY, m_rcInsertItem ) ) { bool bShowItem = false; for( int iRow = 0; iRow < 3; iRow++ ) { m_pIconSlot[iRow]->MouseMessage(pMsg); } } } int ndX = nX - nOldX; int ndY = nY - nOldY; // Move if( bTitleBarClick && ( pMsg->wParam & MK_LBUTTON ) ) { nOldX = nX; nOldY = nY; Move( ndX, ndY ); return WMSG_SUCCESS; } // Close button else if( m_btnClose.MouseMessage( pMsg ) != WMSG_FAIL ) return WMSG_SUCCESS; // OK button else if( m_btnOK.MouseMessage( pMsg ) != WMSG_FAIL ) return WMSG_SUCCESS; // Cancel button else if( m_btnCancel.MouseMessage( pMsg ) != WMSG_FAIL ) return WMSG_SUCCESS; else if (pUIManager->GetDragIcon() == NULL) { if( IsInsideRect( nX, nY, m_rcInsertItem ) && ( pMsg->wParam & MK_LBUTTON ) && ( ndX != 0 || ndY != 0 ) ) { for ( int i = 0; i < COMPOUND_ITEM_SLOT_COUNT; i++ ) { if ( IsInsideRect( nX, nY, m_rcItemSlot[i] ) ) { m_nCurItemSlot = i; pUIManager->SetHoldBtn(m_pIconSlot[m_nCurItemSlot]); return WMSG_SUCCESS; } } } } } break; case WM_LBUTTONDOWN: { if( IsInside( nX, nY ) ) { nOldX = nX; nOldY = nY; // Close button if( m_btnClose.MouseMessage( pMsg ) != WMSG_FAIL ) { // Nothing } // Title bar else if( IsInsideRect( nX, nY, m_rcTitle ) ) { bTitleBarClick = TRUE; } // OK button else if( m_btnOK.MouseMessage( pMsg ) != WMSG_FAIL ) { // Nothing } // Cancel button else if( m_btnCancel.MouseMessage( pMsg ) != WMSG_FAIL ) { // Nothing } CUIManager::getSingleton()->RearrangeOrder( UI_COMPOUND, TRUE ); return WMSG_SUCCESS; } } break; case WM_LBUTTONUP: { CUIManager* pUIManager = CUIManager::getSingleton(); // If holding button doesn't exist if (pUIManager->GetDragIcon() == NULL) { // Title bar bTitleBarClick = FALSE; // If isn't focused if( !IsFocused() ) return WMSG_FAIL; // Close button if( ( wmsgResult = m_btnClose.MouseMessage( pMsg ) ) != WMSG_FAIL ) { if( wmsgResult == WMSG_COMMAND ) CloseCompound(); return WMSG_SUCCESS; } // OK button else if( ( wmsgResult = m_btnOK.MouseMessage( pMsg ) ) != WMSG_FAIL ) { if( wmsgResult == WMSG_COMMAND ) SendCompoundReq(); return WMSG_SUCCESS; } // Cancel button else if( ( wmsgResult = m_btnCancel.MouseMessage( pMsg ) ) != WMSG_FAIL ) { if( wmsgResult == WMSG_COMMAND ) CloseCompound(); return WMSG_SUCCESS; } } // If holding button exists else { if( IsInside( nX, nY ) ) { CUIIcon* pDrag = pUIManager->GetDragIcon(); // If holding button is item and comes from inventory if (pDrag->getBtnType() == UBET_ITEM && pDrag->GetWhichUI() == UI_INVENTORY || pDrag->GetWhichUI() == UI_COMPOUND ) { if( IsInsideRect( nX, nY, m_rcInsertItem ) ) { /* 슬롯 0번 부터 차례 대로 입력하는 방식 for ( int i = 0; i < COMPOUND_ITEM_SLOT_COUNT; i++ ) { if ( IsInsideRect( nX-BTN_SIZE/2, nY-BTN_SIZE/2, m_rcItemSlot[i] ) ) { // Set item SetCompoundItem ( i ); return WMSG_SUCCESS; } } */ SetCompoundItem ();// NearPosition ( nX-BTN_SIZE/2, nY-BTN_SIZE/2 ) ); } } return WMSG_SUCCESS; } else { ResetCompoundItem (); pUIManager->ResetHoldBtn(); return WMSG_SUCCESS; } } } break; case WM_LBUTTONDBLCLK: { if( IsInside( nX, nY ) && IsInsideRect( nX, nY, m_rcInsertItem ) ) { m_nCurItemSlot = NearPosition ( nX-BTN_SIZE/2, nY-BTN_SIZE/2 ); ResetCompoundItem (); CUIManager::getSingleton()->ResetHoldBtn(); } return WMSG_SUCCESS; } break; } return WMSG_FAIL; }
bool cBoundingBox::IsInside(double a_X, double a_Y, double a_Z) { return IsInside(m_Min, m_Max, a_X, a_Y, a_Z); }