void CLib2D::DrawLine(int in_SrcX, int in_SrcY, int in_DstX, int in_DstY, short in_Color) const { int dy = in_DstY - in_SrcY; int dx = in_DstX - in_SrcX; int stepx, stepy; if (dy < 0) { dy = -dy; stepy = -GetDestWidth(); } else { stepy = GetDestWidth(); } if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } dy <<= 1; dx <<= 1; unsigned short *dest = (unsigned short *)GetDestPtr(); in_SrcY *= GetDestWidth(); in_DstY *= GetDestWidth(); const ARect& clipRect = GetClippingRect(); const int MIN_Y = clipRect.y1 * GetDestWidth(); const int MAX_Y = clipRect.y2 * GetDestWidth(); // We don't verify the source point (there should not be any collision at the source). if (in_SrcX >= clipRect.x1 && in_SrcX < clipRect.x2 && in_SrcY >= MIN_Y && in_SrcY < MAX_Y) { dest[in_SrcX+in_SrcY] = in_Color; } if (dx > dy) { int fraction = dy - (dx >> 1); while (in_SrcX != in_DstX) { if (fraction >= 0) { in_SrcY += stepy; fraction -= dx; } in_SrcX += stepx; fraction += dy; if (in_SrcX >= clipRect.x1 && in_SrcX < clipRect.x2 && in_SrcY >= MIN_Y && in_SrcY < MAX_Y) { dest[in_SrcX+in_SrcY] = in_Color; } } }
void InitEditorItemsInfo(UINT32 uiItemType) { VSURFACE_DESC vs_desc; UINT8 *pDestBuf, *pSrcBuf; UINT32 uiSrcPitchBYTES, uiDestPitchBYTES; INVTYPE *item; SGPRect SaveRect, NewRect; HVOBJECT hVObject; UINT32 uiVideoObjectIndex; UINT16 usUselessWidth, usUselessHeight; INT16 sWidth, sOffset, sStart; INT16 i, x, y; UINT16 usCounter; CHAR16 pStr[ 100 ];//, pStr2[ 100 ]; CHAR16 pItemName[SIZE_ITEM_NAME]; UINT8 ubBitDepth; BOOLEAN fTypeMatch; INT32 iEquipCount = 0; // Check to make sure that there isn't already a valid eInfo if( eInfo.fActive ) { if( eInfo.uiItemType == uiItemType ) { //User clicked on the same item classification -- ignore return; } else { //User selected a different item classification -- delete it first. ClearEditorItemsInfo(); ClearTaskbarRegion( iScreenWidthOffset + 100, 2 * iScreenHeightOffset + 360, iScreenWidthOffset + 480, 2 * iScreenHeightOffset + 440 ); } } else { //Clear the menu area, so that the buffer doesn't get corrupted. ClearTaskbarRegion( iScreenWidthOffset + 100, 2 * iScreenHeightOffset + 360, iScreenWidthOffset + 480, 2 * iScreenHeightOffset + 440 ); } EnableEditorRegion( ITEM_REGION_ID ); eInfo.uiItemType = uiItemType; eInfo.fActive = TRUE; //Begin initialization of data. switch(uiItemType) { case TBAR_MODE_ITEM_WEAPONS: eInfo.sNumItems = eInfo.sNumWeapons; eInfo.sScrollIndex = eInfo.sSaveWeaponsScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelWeaponsIndex; break; case TBAR_MODE_ITEM_AMMO: eInfo.sNumItems = eInfo.sNumAmmo; eInfo.sScrollIndex = eInfo.sSaveAmmoScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelAmmoIndex; break; case TBAR_MODE_ITEM_ARMOUR: eInfo.sNumItems = eInfo.sNumArmour; eInfo.sScrollIndex = eInfo.sSaveArmourScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelArmourIndex; break; case TBAR_MODE_ITEM_LBEGEAR: eInfo.sNumItems = eInfo.sLBEGear; eInfo.sScrollIndex = eInfo.sSaveLBEScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelLBEIndex; break; case TBAR_MODE_ITEM_EXPLOSIVES: eInfo.sNumItems = eInfo.sNumExplosives; eInfo.sScrollIndex = eInfo.sSaveExplosivesScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelExplosivesIndex; break; case TBAR_MODE_ITEM_EQUIPMENT1: eInfo.sNumItems = eInfo.sNumEquipment1; eInfo.sScrollIndex = eInfo.sSaveEquipment1ScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelEquipment1Index; break; case TBAR_MODE_ITEM_EQUIPMENT2: eInfo.sNumItems = eInfo.sNumEquipment2; eInfo.sScrollIndex = eInfo.sSaveEquipment2ScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelEquipment2Index; break; case TBAR_MODE_ITEM_EQUIPMENT3: eInfo.sNumItems = eInfo.sNumEquipment3; eInfo.sScrollIndex = eInfo.sSaveEquipment3ScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelEquipment3Index; break; case TBAR_MODE_ITEM_TRIGGERS: eInfo.sNumItems = eInfo.sNumTriggers; eInfo.sScrollIndex = eInfo.sSaveTriggersScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelTriggersIndex; break; case TBAR_MODE_ITEM_KEYS: eInfo.sNumItems = eInfo.sNumKeys; eInfo.sScrollIndex = eInfo.sSaveKeysScrollIndex; eInfo.sSelItemIndex = eInfo.sSaveSelKeysIndex; break; default: //error return; } //Allocate memory to store all the item pointers. eInfo.pusItemIndex = (UINT16*)MemAlloc( sizeof(UINT16) * eInfo.sNumItems ); //Disable the appropriate scroll buttons based on the saved scroll index if applicable //Left most scroll position DetermineItemsScrolling(); //calculate the width of the buffer based on the number of items. //every pair of items (odd rounded up) requires 60 pixels for width. //the minimum buffer size is 420. Height is always 80 pixels. eInfo.sWidth = (eInfo.sNumItems > 12) ? ((eInfo.sNumItems+1)/2)*60 : SCREEN_HEIGHT - 120; eInfo.sHeight = 80; // Create item buffer GetCurrentVideoSettings( &usUselessWidth, &usUselessHeight, &ubBitDepth ); vs_desc.fCreateFlags = VSURFACE_CREATE_DEFAULT | VSURFACE_SYSTEM_MEM_USAGE; vs_desc.usWidth = eInfo.sWidth; vs_desc.usHeight = eInfo.sHeight; vs_desc.ubBitDepth = ubBitDepth; //!!!Memory check. Create the item buffer if(!AddVideoSurface( &vs_desc, &eInfo.uiBuffer )) { eInfo.fKill = TRUE; eInfo.fActive = FALSE; return; } pDestBuf = LockVideoSurface(eInfo.uiBuffer, &uiDestPitchBYTES); pSrcBuf = LockVideoSurface(FRAME_BUFFER, &uiSrcPitchBYTES); //copy a blank chunk of the editor interface to the new buffer. for( i=0; i<eInfo.sWidth; i+=60 ) { Blt16BPPTo16BPP((UINT16 *)pDestBuf, uiDestPitchBYTES, (UINT16 *)pSrcBuf, uiSrcPitchBYTES, 0+i, 0, iScreenWidthOffset + 100, 2 * iScreenHeightOffset + 360, 60, 80 ); } UnLockVideoSurface(eInfo.uiBuffer); UnLockVideoSurface(FRAME_BUFFER); x = 0; y = 0; usCounter = 0; NewRect.iTop = 0; NewRect.iBottom = eInfo.sHeight; NewRect.iLeft = 0; NewRect.iRight = eInfo.sWidth; GetClippingRect(&SaveRect); SetClippingRect(&NewRect); if( eInfo.uiItemType == TBAR_MODE_ITEM_KEYS ) { //Keys use a totally different method for determining for( i = 0; i < eInfo.sNumItems; i++ ) { item = &Item[ KeyTable[ 0 ].usItem + LockTable[ i ].usKeyItem ]; uiVideoObjectIndex = GetInterfaceGraphicForItem( item ); GetVideoObject( &hVObject, uiVideoObjectIndex ); //Store these item pointers for later when rendering selected items. eInfo.pusItemIndex[i] = KeyTable[ 0 ].usItem + LockTable[ i ].usKeyItem; SetFont(SMALLCOMPFONT); SetFontForeground( FONT_MCOLOR_WHITE ); SetFontDestBuffer( eInfo.uiBuffer, 0, 0, eInfo.sWidth, eInfo.sHeight, FALSE ); swprintf( pStr, L"%S", LockTable[ i ].ubEditorName ); DisplayWrappedString(x, (UINT16)(y+25), 60, 2, SMALLCOMPFONT, FONT_WHITE, pStr, FONT_BLACK, TRUE, CENTER_JUSTIFIED ); UINT16 usGraphicNum = g_bUsePngItemImages ? 0 : item->ubGraphicNum; //Calculate the center position of the graphic in a 60 pixel wide area. sWidth = hVObject->pETRLEObject[usGraphicNum].usWidth; sOffset = hVObject->pETRLEObject[usGraphicNum].sOffsetX; sStart = x + (60 - sWidth - sOffset*2) / 2; BltVideoObjectOutlineFromIndex( eInfo.uiBuffer, uiVideoObjectIndex, usGraphicNum, sStart, y+2, 0, FALSE ); //cycle through the various slot positions (0,0), (0,40), (60,0), (60,40), (120,0)... if( y == 0 ) { y = 40; } else { y = 0; x += 60; } } } else for( i = 0; i < eInfo.sNumItems; i++ ) { fTypeMatch = FALSE; while( usCounter<MAXITEMS && !fTypeMatch ) { if ( Item[usCounter].usItemClass == 0 ) break; item = &Item[usCounter]; //if( Item[usCounter].fFlags & ITEM_NOT_EDITOR ) if(item->notineditor) { usCounter++; continue; } if( eInfo.uiItemType == TBAR_MODE_ITEM_TRIGGERS ) { if( i < PRESSURE_ACTION_ID ) usCounter = ( i % 2 ) ? ACTION_ITEM : SWITCH; else usCounter = ACTION_ITEM; fTypeMatch = TRUE; item = &Item[usCounter]; } else switch( item->usItemClass ) { case IC_GUN: case IC_BLADE: case IC_LAUNCHER: case IC_THROWN: case IC_THROWING_KNIFE: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_WEAPONS; break; case IC_PUNCH: if ( i != NOTHING ) { fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_WEAPONS; } else { fTypeMatch = FALSE; } break; case IC_AMMO: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_AMMO; break; case IC_ARMOUR: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_ARMOUR; break; case IC_LBEGEAR: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_LBEGEAR; break; case IC_GRENADE: case IC_BOMB: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_EXPLOSIVES; break; case IC_MEDKIT: case IC_KIT: case IC_FACE: case IC_MONEY: case IC_BELTCLIP: fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_EQUIPMENT1; break; case IC_MISC: if( usCounter == ACTION_ITEM || usCounter == SWITCH ) break; if( iEquipCount < eInfo.sNumEquipment2 ) fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_EQUIPMENT2; else fTypeMatch = eInfo.uiItemType == TBAR_MODE_ITEM_EQUIPMENT3; iEquipCount++; break; } if( fTypeMatch ) { uiVideoObjectIndex = GetInterfaceGraphicForItem( item ); GetVideoObject( &hVObject, uiVideoObjectIndex ); //Store these item pointers for later when rendering selected items. eInfo.pusItemIndex[i] = usCounter; SetFont(SMALLCOMPFONT); SetFontForeground( FONT_MCOLOR_WHITE ); SetFontDestBuffer( eInfo.uiBuffer, 0, 0, eInfo.sWidth, eInfo.sHeight, FALSE ); if( eInfo.uiItemType != TBAR_MODE_ITEM_TRIGGERS ) { LoadItemInfo( usCounter, pItemName, NULL ); swprintf( pStr, L"%s", pItemName ); } else { if( i == PRESSURE_ACTION_ID ) { swprintf( pStr, pInitEditorItemsInfoText[0] ); } else if( i < 2 ) { if( usCounter == SWITCH ) swprintf( pStr, pInitEditorItemsInfoText[5] ); else swprintf( pStr, pInitEditorItemsInfoText[1] ); } else if( i < 4 ) { if( usCounter == SWITCH ) swprintf( pStr, pInitEditorItemsInfoText[6] ); else swprintf( pStr, pInitEditorItemsInfoText[2] ); } else if( i < 6 ) { if( usCounter == SWITCH ) swprintf( pStr, pInitEditorItemsInfoText[7] ); else swprintf( pStr, pInitEditorItemsInfoText[3] ); } else { if( usCounter == SWITCH ) swprintf( pStr, pInitEditorItemsInfoText[8], (i-4)/2 ); else swprintf( pStr, pInitEditorItemsInfoText[4], (i-4)/2 ); } } DisplayWrappedString(x, (UINT16)(y+25), 60, 2, SMALLCOMPFONT, FONT_WHITE, pStr, FONT_BLACK, TRUE, CENTER_JUSTIFIED ); UINT16 usGraphicNum = g_bUsePngItemImages ? 0 : item->ubGraphicNum; if(usGraphicNum < hVObject->usNumberOfObjects) { //Calculate the center position of the graphic in a 60 pixel wide area. sWidth = hVObject->pETRLEObject[usGraphicNum].usWidth; sOffset = hVObject->pETRLEObject[usGraphicNum].sOffsetX; sStart = x + (60 - sWidth - sOffset*2) / 2; if( sWidth && sWidth > 0 ) { BltVideoObjectOutlineFromIndex( eInfo.uiBuffer, uiVideoObjectIndex, usGraphicNum, sStart, y+2, 0, FALSE ); } //cycle through the various slot positions (0,0), (0,40), (60,0), (60,40), (120,0)... if( y == 0 ) { y = 40; } else { y = 0; x += 60; } } else { static vfs::Log& editorLog = *vfs::Log::create(L"EditorItems.log"); editorLog << L"Tried to access item [" << item->ubGraphicNum << L"/" << hVObject->usNumberOfObjects << L"]" << vfs::Log::endl; } } usCounter++; } } SetFontDestBuffer( FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE ); SetClippingRect(&SaveRect); gfRenderTaskbar = TRUE; }