bool Map::CheckValidDirection(int x, int y, Direction dir, int size) { if (false == CheckPosition(x, y)) return false; int deltaX = 0; int deltaY = 0; switch (dir) { case DIR_UP: deltaY = 1; break; case DIR_DOWN: deltaY = -1; break; case DIR_LEFT: deltaX = -1; break; case DIR_RIGHT: deltaX = 1; break; } for (int i = 0; i < size; ++i) { if (false == CheckPosition(x, y)) return false; x += deltaX; y += deltaY; } return true; }
void cGameObject::move() { m_position.x += m_speed.vx; m_position.y += m_speed.vy; CheckPosition(); }
void CurveEditor::NotifyPointMove(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { if (_id != MyGUI::MouseButton::Left) return; if (!CheckPosition(_left, _top)) return; auto pos = MyGUI::IntPoint(_left, _top) - _sender->getCroppedParent()->getAbsolutePosition(); auto value = GetValue(pos.left, pos.top); pos.left -= 7; pos.top -= 7; _sender->setPosition(pos); DiString str; str.Format("%.3g", value.x); mEditTimeEditBox->setCaption(str.c_str()); str.Format("%.3g", value.y); mEditValueEditBox->setCaption(str.c_str()); std::sort(mButtons.begin(), mButtons.end(), [](MyGUI::Button* a, MyGUI::Button* b) { return a->getPosition().left < b->getPosition().left; }); RefreshCurve(); }
int RadioList::MouseEvent(MOUSE_EVENT_RECORD& mer) { COORD x = mer.dwMousePosition; if (CheckPosition(x)) { int tmp = x.Y - GetY(); tmp = (int)tmp / (HEIGHT_OF_CELL - 1); node* iterator = _head; while (iterator) { if (iterator->index == tmp) { _current = iterator; _current->checked = true; } else iterator->checked = false; iterator = iterator->next; } return DRAW; } }
void cGameObject::move( int offsetX, int offsetY ) { m_position.x += offsetX; m_position.y += offsetY; CheckPosition(); }
void Screen::Display(const char *Text, int x, int y) { if (x >= 0) this->OutputPosition.x = x; if (y >= 0) this->OutputPosition.y = y; for (int i = 0; i < (int)strlen(Text); i++) { if (Text[i] == 10) { NewLine(); } else if (Text[i] == 9) { this->OutputPosition.x += this->FontWidth * 8; CheckPosition(); } else { int len = SDL2Function::GetAllowCharNum(Text); char *t = (char*)malloc(len + 1); strncpy(t, Text + i, len); t[len] = '\0'; i += len - 1; char *text = GB2312toUTF8(t); free(t); SDL_Surface *SDLText; SDL_Color FrontColor; Uint8 r, g, b; SDL_GetRGB(this->TextColor, this->ScreenSurface->format, &r, &g, &b); FrontColor.a = 255; FrontColor.r = r; FrontColor.g = g; FrontColor.b = b; SDLText = TTF_RenderUTF8_Solid((TTF_Font*)this->Font, text, FrontColor); Rect RefRect = ShowText(SDLText, this->OutputPosition.x, this->OutputPosition.y, 0, 0, this->ScreenSurface); this->Refresh(&RefRect); } } }
BOOL FixPos(int *Y) { int nY = *Y; if (CheckPosition(nY) == TRUE) { *Y = sizeStatusBar; return TRUE; } return FALSE; };
DAVA::String CommandLineParser::GetCommandParam(const DAVA::String &command) { int32 commandPosition = GetCommandPosition(command); if(CheckPosition(commandPosition)) { return GetCommand(commandPosition + 1); } return String(); }
void TextBox::MousePressed(MOUSE_EVENT_RECORD mer) { int res = CheckPosition(mer); if (res != -1) { res = LastLetterIndex(res); curserPosition = res; textIndex = res - coord.X - 1; COORD reset = { res , coord.Y + 1 }; SetConsoleCursorPosition(handle, reset); focus = true; } }
void CurveEditor::NotifyMousePressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { if (_id != MyGUI::MouseButton::Left) return; auto pos = _sender->getAbsolutePosition(); if (CheckPosition(_left, _top)) { AddButton(_left - pos.left, _top - pos.top); } }
void CGUITextButton::Move(float _x, float _y) { CheckPosition(_x,_y); if(text) text->Move(_x-x+psx,_y-y+psy); if(texts){ for(int i=0;i<numLines;i++) { texts[i]->Move(_x-x+psx,_y-y+psy); } } SetPos(_x,_y); }
void CGUIStaticText::Move(float _x, float _y) { CheckPosition(_x,_y); if(text) text->Move(_x-x,_y-y); if(texts){ for(int i=0;i<numLines;i++) { texts[i]->Move(_x-x,_y-y); } } SetPos(_x,_y); }
bool CapsuleProc::RotateIMG( size_t blobIndex, FBLOB profileBlob, IMG proImg, IMG &proSubIMG, size_t &posIndex) { long profileCount = 0; FBlobGetNumBlobs (profileBlob, profileCount); if ( blobIndex >= static_cast<size_t>(profileCount) ) { posIndex = -1; return false; } //Get Range long x0 = 0, y0 = 0, width = 0, height = 0; FBlobGetBoundingBox (profileBlob, blobIndex, x0, y0, width, height); posIndex = CheckPosition(x0+width/2, y0+height/2); IMG proIMGMap = NULL; CreateImageMap (proImg, x0, y0, x0+width, y0+height, width, height, proIMGMap); double rabi = 0.0, rabi1 = 0.0, rabi2 = 0.0, momentAngle = 0.0; FBlobGetMoments (profileBlob, blobIndex, rabi, rabi1, rabi2, momentAngle); static const double ADIVPI = 180.0 /(4.0*atan(1.0)); //ppi = 180/PI static const double ANGLE90 = 90; //ppiH = 180/PI*PI/2 double angle = 0.0; if(momentAngle>=0) { angle = (ANGLE90 - ADIVPI * momentAngle); } else { angle = -(ANGLE90 + ADIVPI * momentAngle); } RotateImage( proIMGMap, angle, IP_Linear, proSubIMG); TCoordinateMap cm; InitCoordinateMap(cm); SetImageCoordinates (proSubIMG, cm); ShrinkVertical (proSubIMG, m_segmentParam.shrinkY); ShrinkHorizontal(proSubIMG, m_segmentParam.shrinkX); ReleaseImage (proIMGMap); return true; }
Rect Screen::ShowText(SDL_Surface *Text, int x, int y, int width, int height, SDL_Surface *Dest) { SDL_Rect textPosition; textPosition.x = x; textPosition.y = y; textPosition.w = (width == 0)? Text->w : width; textPosition.h = (height == 0)? Text->h : height; if (this->Transparent == false) { SDL_FillRect(this->ScreenSurface, &textPosition, this->BackgroundColor); } SDL_BlitSurface(Text, NULL, Dest, &textPosition); this->OutputPosition.x += Text->w; CheckPosition(); Rect Ref; Ref.x = textPosition.x; Ref.y = textPosition.y; Ref.w = textPosition.w; Ref.h = textPosition.h; return Ref; }
/* -------------------------------------------------------------------- * FUNCTION NAME: MouseEvent * DESCRIPTION : Recives mouse event and check what to do. * RETURN : On Hover - DRAW_COLOR, On click - DRAW. * NOTES : Polymorphic function - inherited from Widget. * -------------------------------------------------------------------- */ int ComboBox::MouseEvent(MOUSE_EVENT_RECORD& mer) { COORD x = mer.dwMousePosition; if (CheckPosition(x)) { if (mer.dwButtonState == 0 && !_isOpen) { int tmp = x.Y - GetY(); tmp = static_cast<int>(tmp) / (HEIGHT_OF_CELL - 1); strVecItr itr = _comboNames.begin(); while (itr != _comboNames.end()) { if (itr->index == tmp) { _current = itr->index; return DRAW_COLOR; } ++itr; } } else { int tmp = x.Y - GetY(); tmp = static_cast<int>(tmp) / (HEIGHT_OF_CELL - 1); strVecItr itr = _comboNames.begin(); while (itr != _comboNames.end()) { if (itr->index == tmp) { if (!_isOpen) _selected = itr->index; return DRAW; } ++itr; } } } }
/* short BSPTree::ClipTrace( STrace& tr ) { ClipTrace_r( 0, 0, 1, tr.vStart, tr.vGoal, tr); return 0; } */ bool BSPTree::ClipTrace_r( short sNodeIndex, float p1f, float p2f, Vector3& vP1, Vector3& vP2, STrace &rTrace) { float t1, t2; float frac; Vector3 vMid; int side; float midf; // check for empty if (sNodeIndex < 0) { if (sNodeIndex != CONTENTS_SOLID) { rTrace.in_solid = false; } else rTrace.in_solid = true; // original: trace->startsolid = true; return true; // empty } SNode_f& rNode = m_paNode[sNodeIndex]; SPlane& rPlane = m_paPlane[rNode.sPlaneIndex]; // // find the point distances // t1 = rPlane.GetDistanceFromPoint( vP1 ); t2 = rPlane.GetDistanceFromPoint( vP2 ); if( rTrace.bvType != BVTYPE_DOT ) { t1 -= rTrace.aabb.GetRadiusForPlane( rPlane ); t2 -= rTrace.aabb.GetRadiusForPlane( rPlane ); } #if 1 if (t1 >= 0 && t2 >= 0) return ClipTrace_r(rNode.sFrontChild, p1f, p2f, vP1, vP2, rTrace); if (t1 < 0 && t2 < 0) return ClipTrace_r(rNode.sBackChild, p1f, p2f, vP1, vP2, rTrace); #else if ( (t1 >= EPSILON && t2 >= EPSILON) || (t2 > t1 && t1 >= 0) ) return ClipTrace_r(rNode.sFrontChild, p1f, p2f, vP1, vP2, rTrace); if ( (t1 <= -EPSILON && t2 <= -EPSILON) || (t2 < t1 && t1 <= 0) ) return ClipTrace_r(rNode.sBackChild, p1f, p2f, vP1, vP2, rTrace); #endif // put the crosspoint DIST_EPSILON pixels on the near side if (t1 < 0) frac = (t1 + EPSILON)/(t1-t2); else frac = (t1 - EPSILON)/(t1-t2); if (frac < 0) frac = 0; if (frac > 1) frac = 1; midf = p1f + (p2f - p1f)*frac; vMid = vP1 + frac*(vP2 - vP1); side = (t1 < 0); short sNextIndex = (side == 0) ? rNode.sFrontChild : rNode.sBackChild; short sInvIndex = (side == 0) ? rNode.sBackChild : rNode.sFrontChild; // move up to the node if( !ClipTrace_r(sNextIndex, p1f, midf, vP1, vMid, rTrace) ) return false; #ifdef PARANOID if ( CheckPosition(vMid, sNextIndex) == CONTENTS_SOLID ) { //Con_Printf ("mid PointInHullSolid\n"); return false; } #endif if ( CheckPosition(vMid, sInvIndex) != CONTENTS_SOLID ) // go past the node return ClipTrace_r(sInvIndex, midf, p2f, vMid, vP2, rTrace); if ( rTrace.in_solid ) /* original: trace->allsolid */ return false; // never got out of the solid area //================== // the other side of the node is solid, this is the impact point //================== if (!side) { rTrace.plane = rPlane; } else { rTrace.plane = rPlane; rTrace.plane.Flip(); } while ( CheckPosition(vMid, 0) == CONTENTS_SOLID ) { // shouldn't really happen, but does occasionally frac -= 0.1f; if (frac < 0) { rTrace.fFraction = midf; rTrace.vEnd = vMid; return false; } midf = p1f + (p2f - p1f) * frac; vMid = vP1 + frac*(vP2 - vP1); } rTrace.fFraction = midf; rTrace.vEnd = vMid; return false; }
void AddTotemBuff(uint32 target_id, SFightPlayerInfo &play_info, uint32 packet) { if(play_info.attr == kAttrPlayer) { SUser *user = theUserDC.find(target_id); if(user == NULL) { LOG_ERROR("cannot find user=%u", target_id); return; } for(uint32 i = 0; i < play_info.soldier_list.size(); ++i) { SFightSoldier &soldier = play_info.soldier_list[i]; if(soldier.attr == kAttrTotem) { continue; } for(uint32 x = 0; x < play_info.soldier_list.size(); ++x) { SFightSoldier &soldier_totem = play_info.soldier_list[x]; if(soldier_totem.attr != kAttrTotem) { continue; } STotemInfo &info = user->data.totem_map[packet]; TotemList::iterator iter = std::find_if(info.totem_list.begin(), info.totem_list.end(), FindTotemByGuid(soldier_totem.soldier_guid)); if(iter == info.totem_list.end()) { LOG_ERROR("cannot find totem guid=%u in user=%u totem packet=%u", soldier_totem.soldier_guid, user->guid, packet); continue; } STotem &totem = *iter; if(CheckPosition(totem.id, totem.formation_add_lv, soldier_totem.fight_index, soldier.fight_index)) { // 阵法加成 CTotemAttrData::SData *attr_data = theTotemAttrExt.Find(totem.id, totem.formation_add_lv); if(attr_data != NULL) { S2UInt32 &attr = attr_data->formation_add_attr; AddOddToList(soldier_totem.guid, attr.first, attr.second, soldier.odd_list); } } // 速度加成 CTotemAttrData::SData *attr_data = theTotemAttrExt.Find(totem.id, totem.speed_lv); if(attr_data != NULL) { if(soldier_totem.fight_index / 3 == soldier.fight_index / 3) { AddOddToList(soldier_totem.guid, attr_data->speed.first, attr_data->speed.second, soldier.odd_list); } } } } } else if(play_info.attr == kAttrMonster) { for(uint32 i = 0; i < play_info.soldier_list.size(); ++i) { SFightSoldier &soldier = play_info.soldier_list[i]; if(soldier.attr == kAttrTotem) { continue; } for(uint32 x = 0; x < play_info.soldier_list.size(); ++x) { SFightSoldier &soldier_totem = play_info.soldier_list[x]; if(soldier_totem.attr != kAttrTotem) { continue; } CTotemExtData::SData *ext = theTotemExtExt.Find(soldier_totem.soldier_guid); if(ext == NULL) { continue; } // 阵法加成 if(CheckPosition(ext->totem_id, ext->formation_lv, soldier_totem.fight_index, soldier.fight_index)) { CTotemAttrData::SData *attr_data = theTotemAttrExt.Find(ext->totem_id, ext->formation_lv); if(attr_data != NULL) { S2UInt32 &attr = attr_data->formation_add_attr; AddOddToList(soldier_totem.guid, attr.first, attr.second, soldier.odd_list); } } // 速度加成 CTotemAttrData::SData *attr_data = theTotemAttrExt.Find(ext->totem_id, ext->speed_lv); if(attr_data != NULL) { if(soldier_totem.fight_index / 3 == soldier.fight_index / 3) { AddOddToList(soldier_totem.guid, attr_data->speed.first, attr_data->speed.second, soldier.odd_list); } } } } } }
void GetFightInfo(uint32 id, uint32 level, uint32 wake_lv, uint32 speed_lv, uint32 add_lv, SFightSoldier &fight_soldier) { CTotemData::SData *totem_data = theTotemExt.Find(id); if(totem_data == NULL) { LOG_ERROR("cannot find totem data, id=%u", id); return; } fight_soldier.totem.id = id; fight_soldier.totem.level = level; fight_soldier.totem.speed_lv = speed_lv; fight_soldier.totem.formation_add_lv = add_lv; fight_soldier.totem.wake_lv = wake_lv; // 觉醒odd CTotemAttrData::SData *attr_data = theTotemAttrExt.Find(id, wake_lv); if(attr_data != NULL) { AddOddToList(0, attr_data->wake.first, attr_data->wake.second, fight_soldier.odd_list); } // 主动技能 attr_data = theTotemAttrExt.Find(id, level); if(attr_data == NULL) { LOG_ERROR("cannot find totem_attr data, id=%u, level=%u", id, level); return; } // base info fight_soldier.name = totem_data->name; fight_soldier.soldier_id = totem_data->id; fight_soldier.attr = kAttrTotem; if ( 0 == fight_soldier.level ) fight_soldier.level = attr_data->level; // skill if(attr_data->skill.first != 0) { SFightSkill skill; skill.skill_id = attr_data->skill.first; skill.skill_level = attr_data->skill.second; fight_soldier.skill_list.push_back(skill); } // 给自己加的odd if(CheckPosition(id, add_lv, 0, 0)) { CTotemAttrData::SData *attr_data = theTotemAttrExt.Find(id, add_lv); if(attr_data != NULL) { S2UInt32 &attr = attr_data->formation_add_attr; AddOddToList(0, attr.first, attr.second, fight_soldier.odd_list); } } // extable totem::GetTotemExt(id, speed_lv, fight_soldier.fight_ext_able ); }
void ArrayImpl<T_t>::ReadBuffer(const T_t* buff, size_t buffSize, size_t ownOffSet) { CheckPosition(ownOffSet + buffSize - 1); for (size_t i = 0; i < buffSize; i++) { m_Storage[ownOffSet + i] = buff[i]; } }
void Screen::NewLine() { this->OutputPosition.y += TTF_FontHeight((TTF_Font*)this->Font) - 1; this->OutputPosition.x = 0; CheckPosition(); }
short BSPTree::ClipTrace( STrace& tr ) { if( Vec3LengthSq( tr.vGoal - tr.vStart ) < 0.000000001f ) return CONTENTS_EMPTY; short nodenum, prev_nodenum; SNode_f* paNode = m_paNode; SPlane* paPlane = m_paPlane; Vector3 vP1, vP2; float fd1, fd2; float f, fStart, fGoal; char cNumBackTrack; static short nodenums[MAX_DIVIDE_NUM]; static float fGoals[MAX_DIVIDE_NUM]; static Vector3 vGoals[MAX_DIVIDE_NUM]; static char rearside[MAX_DIVIDE_NUM]; cNumBackTrack = 0; nodenum = 0; prev_nodenum = 0; Vector3 &vP0 = tr.vStart; fStart = 0; vP1 = tr.vStart; fGoal = 1; if(tr.fFraction == 1) //hasn't hit anything yet vP2 = tr.vGoal; else //already hit something vP2 = tr.vEnd; SPlane* pTouchPlane = paPlane; SPlane* pPlane = NULL; short sEndCellIndex = 32767; while(1) { while(0 <= nodenum) { pPlane = paPlane + paNode[nodenum].sPlaneIndex; fd1 = pPlane->GetDistanceFromPoint( vP1 ); fd2 = pPlane->GetDistanceFromPoint( vP2 ); if( tr.bvType != BVTYPE_DOT ) { fd1 -= tr.aabb.GetRadiusForPlane( *pPlane ); fd2 -= tr.aabb.GetRadiusForPlane( *pPlane ); } if(0 <= fd1 && 0 <= fd2) { prev_nodenum = nodenum; nodenum = paNode[nodenum].sFrontChild; continue; } if(fd1 < 0 && fd2 < 0) { prev_nodenum = nodenum; nodenum = paNode[nodenum].sBackChild; continue; } //Need to split the line. if(fd1 < 0) f = (fd1 + EPSILON) / (fd1 - fd2); else f = (fd1 - EPSILON) / (fd1 - fd2); if(f < 0) f = 0; //This occurs when fd1 < EPSILON else if(1 < f) f = 1; //Store the rear-line data in stack fGoals[cNumBackTrack] = fGoal; vGoals[cNumBackTrack] = vP2; nodenums[cNumBackTrack] = nodenum; //Prepare for the next fore-line check fGoal = fStart + f * (fGoal - fStart); vP2 = vP1 + f * (vP2 - vP1); prev_nodenum = nodenum; if( 0 <= fd1 ) { nodenum = paNode[nodenum].sFrontChild; rearside[cNumBackTrack] = 1; //the rear-line is behind the plane } else { nodenum = paNode[nodenum].sBackChild; rearside[cNumBackTrack] = 0; //the rear-line is in front of the plane } cNumBackTrack++; if( MAX_DIVIDE_NUM <= cNumBackTrack ) assert( !"stack overflow - bsptree traversal in BSPTree::ClipTrace()" ); } if(nodenum == CONTENTS_EMPTY) { sEndCellIndex = paNode[prev_nodenum].sCellIndex; if(0 < cNumBackTrack) //if a subsequent line exists, {//Prepare for checking the next rear-line. cNumBackTrack--; fStart = fGoal; fGoal = fGoals[cNumBackTrack]; vP1 = vP2; vP2 = vGoals[cNumBackTrack]; prev_nodenum = nodenums[cNumBackTrack]; if(rearside[cNumBackTrack] == 1) nodenum = paNode[ prev_nodenum ].sBackChild; else nodenum = paNode[ prev_nodenum ].sFrontChild; pTouchPlane = paPlane + paNode[prev_nodenum].sPlaneIndex; continue; } else { tr.vEnd = vP2; tr.in_solid = false; return sEndCellIndex; // returns the cell where the trace has ended up } } if(nodenum == CONTENTS_SOLID) { tr.vEnd = vP1; while( CheckPosition( tr ) == CONTENTS_SOLID ) { fStart -= 0.1f; if( fStart < 0 /*|| fStart != fStart*/ ) { // returns the original position (this part should be improved) // if( fStart != fStart ) // int error = 1; //MessageBox(NULL, "Cannot get out of the solid area.","Error", MB_OK|MB_ICONWARNING); tr.fFraction = 0.0f; /// tr.vEnd = vP1; tr.vEnd = tr.vStart; tr.in_solid = true; return CONTENTS_SOLID; } tr.vEnd = vP0 + fStart * (tr.vEnd - vP0); } // tr.fFraction = fStart; tr.fFraction = fStart * tr.fFraction; tr.in_solid = false; //Record the plane 'tr' hit tr.iNumTouches++; tr.plane = *pTouchPlane; return sEndCellIndex; } } return 0; }
T_t& ArrayImpl<T_t>::RefAt(size_t iAt) { CheckPosition(iAt); return m_Storage[iAt]; }