void GUITextBox::OnKeyDown(UCHAR key) { SetShift(keys[VK_SHIFT]); if(GetText()) { if((IsAlpabetic(key) || key == VK_SPACE) && GetTextLength() < GetMaxTextLength()) { char* new_text = new char[strlen(GetText())+2]; if(GetShift()) sprintf(new_text, "%s%c\0", GetText(), key); else sprintf(new_text, "%s%c\0", GetText(), tolower(key)); try { delete[] GetText(); } catch(...) { WriteToLog("Exception in GUITextBox::OnKeyDown()"); } SetText(new_text); SetTextLength(strlen(GetText())); } else if(key == VK_BACK) { UINT len = strlen(GetText()); if(len > 0) { string s = string(GetText()); char* new_text = new char[len]; sprintf(new_text, "%s\0", s.substr(0, s.length()-1).c_str()); try { delete[] GetText(); } catch(...) { WriteToLog("Exception in GUITextBox::OnKeyDown()"); } SetText(new_text); SetTextLength(strlen(GetText())); } } } else { char* new_text = new char[1]; if(GetShift()) new_text[0] = key; else new_text[0] = tolower(key); SetText(new_text); } }
IplImage* FillHoleShiftMap::CalculatedRetargetImage() { IplImage* output = cvCloneImage(_maskData); int num_pixels = _pointMapping->size(); printf("Rendering graph-cut result to image... \n"); for(int i = 0; i < num_pixels; i++) { int label = _gcGeneral->whatLabel(i); CvPoint* point = (*(_pointMapping))[i]; CvPoint shift = GetShift(label, _shiftSize); CvPoint pointLabel = cvPoint(point->x + shift.x, point->y + shift.y); if(!IsOutside(pointLabel, cvSize(_input->width, _input->height))) { CvScalar value = cvGet2D(_input, pointLabel.y, pointLabel.x); cvSet2D(output, point->y, point->x, value); // printf("*%i %i %i %i", point->x, point->y, pointLabel.x, pointLabel.y); } else { printf("warning mapped outside"); cvSet2D(output, point->y, point->x, cvScalar(255, 0, 0)); } } return output; }
CvMat* FillHoleShiftMap::CalculateLabelMap() { CvMat* output = cvCreateMat(_mask->height, _mask->width, CV_32SC2); for(int i = 0; i < output->width; i++) for(int j = 0; j < output->height; j++) { SetLabel(cvPoint(i,j), cvPoint(-100, -100), output); } int num_pixels = _pointMapping->size(); printf("Getting label map... \n"); for(int i = 0; i < num_pixels; i++) { int label = _gcGeneral->whatLabel(i); CvPoint* point = (*(_pointMapping))[i]; CvPoint pointLabel = GetShift(label, _shiftSize); SetLabel(*point, pointLabel, output); } return output; }
unsigned OptShift2(CodeSeg* S) /* A call to the asrax1 routines may get replaced by something simpler, if * X is not used later: * * cmp #$80 * ror a * */ { unsigned Changes = 0; unsigned I; /* Walk over the entries */ I = 0; while (I < CS_GetEntryCount (S)) { unsigned Shift; unsigned Count; /* Get next entry */ CodeEntry* E = CS_GetEntry (S, I); /* Check for the sequence */ if (E->OPC == OP65_JSR && (Shift = GetShift (E->Arg)) != SHIFT_NONE && SHIFT_TYPE (Shift) == SHIFT_TYPE_ASR && (Count = SHIFT_COUNT (Shift)) > 0 && Count * 100 <= S->CodeSizeFactor && !RegXUsed (S, I+1)) { CodeEntry* X; unsigned J = I+1; /* Generate the replacement sequence */ while (Count--) { /* cmp #$80 */ X = NewCodeEntry (OP65_CMP, AM65_IMM, "$80", 0, E->LI); CS_InsertEntry (S, X, J++); /* ror a */ X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, E->LI); CS_InsertEntry (S, X, J++); } /* Delete the call to asrax */ CS_DelEntry (S, I); /* Remember, we had changes */ ++Changes; } /* Next entry */ ++I; } /* Return the number of changes made */ return Changes; }
dword Ctrl::KEYtoK(dword key) { if(key != K_CTRL_KEY && key != K_SHIFT_KEY && key != K_ALT_KEY) { if(GetCtrl()) key |= K_CTRL; if(GetAlt()) key |= K_ALT; if(GetShift()) key |= K_SHIFT; } return key; }
int smoothFunctionFH(int pixel1, int pixel2, int label1, int label2, void* extraData) { ForSmoothFH* data = (ForSmoothFH*)extraData; CvPoint* point1 = (*(data->pointMapping))[pixel1]; CvPoint* point2 = (*(data->pointMapping))[pixel2]; CvPoint shift1 = GetShift(label1, data->shiftSize); CvPoint shift2 = GetShift(label2, data->shiftSize); CvPoint origin1 = cvPoint(shift1.x + point1->x, shift1.y + point1->y); CvPoint origin2 = cvPoint(shift2.x + point2->x, shift2.y + point2->y); CvPoint neighbor1 = GetNeighbor(*point1, *point2, origin1); CvPoint neighbor2 = GetNeighbor(*point2, *point1, origin2); CvSize inputSize = cvSize(data->input->width, data->input->height); if(IsOutside(origin1, inputSize) || IsOutside(origin2, inputSize) || IsOutside(neighbor1, inputSize) || IsOutside(neighbor2, inputSize)) return 10000; int energy = 0; energy += SquareColorDifference(origin1, neighbor2, data->input); energy += SquareColorDifference(origin2, neighbor1, data->input); energy += SquareColorDifference(origin1, neighbor2, data->inputGradient); energy += SquareColorDifference(origin2, neighbor1, data->inputGradient); }
int dataFunctionFH(int pixel, int label, void *extraData) { ForDataFH* forData = (ForDataFH*) extraData; CvPoint* point = (*(forData->pointMapping))[pixel]; CvPoint origin; CvPoint shift = GetShift(label, forData->shiftSize); origin.x = point->x + shift.x; origin.y = point->y + shift.y; // penalty if outside if(IsOutside(origin, forData->inputSize)) return 1000000; // saliency cost double saliency = 0; CvScalar value = cvGet2D(forData->saliency, origin.y, origin.x); saliency += (value.val[0] + value.val[1] + value.val[2]); // smooth cost with predefined region int energy = 0; value = cvGet2D(forData->maskNeighbor, point->y, point->x); if(value.val[0] == 1) { // compare with up position energy += smoothFunctionFHMask(origin, *point, cvPoint(point->x, point->y - 1), forData->input, forData->inputGradient, forData->maskData, forData->maskDataGradient); } if(value.val[1] == 1) { // compare with right energy += smoothFunctionFHMask(origin, *point, cvPoint(point->x + 1, point->y), forData->input, forData->inputGradient, forData->maskData, forData->maskDataGradient); } if(value.val[2] == 1) { // compare with down energy += smoothFunctionFHMask(origin, *point, cvPoint(point->x, point->y + 1), forData->input, forData->inputGradient, forData->maskData, forData->maskDataGradient); } if(value.val[3] == 1) { // compare with left energy += smoothFunctionFHMask(origin, *point, cvPoint(point->x - 1, point->y), forData->input, forData->inputGradient, forData->maskData, forData->maskDataGradient); } return energy + saliency; }
bool Monster::CanFocus(int nPointX, int nPointY) { switch(m_CurrMotion.Motion){ case MOTION_MON_DIE: { return false; } default: { break; } } auto nGfxID = GfxID(m_CurrMotion.Motion, m_CurrMotion.Direction); if(nGfxID >= 0){ // we only check the body frame // can focus or not is decided by the graphics size uint32_t nKey0 = ((uint32_t)(nGfxID & 0X03FFFF) << 5) + m_CurrMotion.Frame; int nDX0 = 0; int nDY0 = 0; auto pFrame0 = g_MonsterDBN->Retrieve(nKey0, &nDX0, &nDY0); int nShiftX = 0; int nShiftY = 0; GetShift(&nShiftX, &nShiftY); int nStartX = X() * SYS_MAPGRIDXP + nDX0 + nShiftX; int nStartY = Y() * SYS_MAPGRIDYP + nDY0 + nShiftY; int nW = 0; int nH = 0; SDL_QueryTexture(pFrame0, nullptr, nullptr, &nW, &nH); int nMaxTargetW = SYS_MAPGRIDXP + SYS_TARGETRGN_GAPX; int nMaxTargetH = SYS_MAPGRIDYP + SYS_TARGETRGN_GAPY; return ((nW >= nMaxTargetW) ? MathFunc::PointInSegment(nPointX, (nStartX + (nW - nMaxTargetW) / 2), nMaxTargetW) : MathFunc::PointInSegment(nPointX, nStartX, nW)) && ((nH >= nMaxTargetH) ? MathFunc::PointInSegment(nPointY, (nStartY + (nH - nMaxTargetH) / 2), nMaxTargetH) : MathFunc::PointInSegment(nPointY, nStartY, nH)); } return false; }
char CKeyboard::GetAscii() { char lowLevelAscii = CLowLevelKeyboard::GetAscii(); int translatedAscii = GetUnicode(); #ifdef DEBUG_KEYBOARD_GETCHAR CLog::Log(LOGDEBUG, "low level ascii: %c ", lowLevelAscii); CLog::Log(LOGDEBUG, "low level ascii code: %d ", lowLevelAscii); CLog::Log(LOGDEBUG, "result char: %c ", translatedAscii); CLog::Log(LOGDEBUG, "result char code: %d ", translatedAscii); CLog::Log(LOGDEBUG, "ralt is pressed bool: %d ", GetRAlt()); CLog::Log(LOGDEBUG, "shift is pressed bool: %d ", GetShift()); #endif if (translatedAscii >= 0 && translatedAscii < 128) // only TRUE ASCII! Otherwise XBMC crashes! No unicode not even latin 1! return translatedAscii; // mapping to ASCII is supported only if the result is TRUE ASCII else return lowLevelAscii; // old style }
//坐标转换 void DcGp::DcGpPointCloud::ApplyTransform(EigenMatrix4d& transMatrix) { //初始化最大值最小值 m_pDcGpPointCloudImpl->m_minPoint = DCVector3D(DCCore::MAX_POINTCOORD, DCCore::MAX_POINTCOORD, DCCore::MAX_POINTCOORD); m_pDcGpPointCloudImpl->m_maxPoint = DCVector3D(DCCore::MIN_POINTCOORD, DCCore::MIN_POINTCOORD, DCCore::MIN_POINTCOORD); Eigen::Matrix<double, 1, 3> eshift; Point_3D shift = GetShift(); eshift << shift[0], shift[1], shift[2]; Eigen::Matrix<double, 1, 3> temp; for (unsigned i = 0; i != Size(); ++i) { temp << m_pDcGpPointCloudImpl->m_points[i][0], m_pDcGpPointCloudImpl->m_points[i][1], m_pDcGpPointCloudImpl->m_points[i][2]; temp = (temp - eshift) * transMatrix.block(0, 0, 3, 3).transpose() + eshift; temp += transMatrix.block(0, 3, 3, 1).transpose(); m_pDcGpPointCloudImpl->m_points[i][0] = temp[0]; m_pDcGpPointCloudImpl->m_points[i][1] = temp[1]; m_pDcGpPointCloudImpl->m_points[i][2] = temp[2]; //重新计算最大值 m_pDcGpPointCloudImpl->m_minPoint[0] = std::min(m_pDcGpPointCloudImpl->m_minPoint[0], m_pDcGpPointCloudImpl->m_points[i][0]); m_pDcGpPointCloudImpl->m_minPoint[1] = std::min(m_pDcGpPointCloudImpl->m_minPoint[1], m_pDcGpPointCloudImpl->m_points[i][1]); m_pDcGpPointCloudImpl->m_minPoint[2] = std::min(m_pDcGpPointCloudImpl->m_minPoint[2], m_pDcGpPointCloudImpl->m_points[i][2]); m_pDcGpPointCloudImpl->m_maxPoint[0] = std::max(m_pDcGpPointCloudImpl->m_maxPoint[0], m_pDcGpPointCloudImpl->m_points[i][0]); m_pDcGpPointCloudImpl->m_maxPoint[1] = std::max(m_pDcGpPointCloudImpl->m_maxPoint[1], m_pDcGpPointCloudImpl->m_points[i][1]); m_pDcGpPointCloudImpl->m_maxPoint[2] = std::max(m_pDcGpPointCloudImpl->m_maxPoint[2], m_pDcGpPointCloudImpl->m_points[i][2]); } //将Eigen::Matrix4d矩阵值,传给QMatrix4x4类型的矩阵 //double* matValue = transMatrix.data(); //m_pDcGpPointCloudImpl->m_pop = QMatrix4x4(matValue); //重新计算边界盒 m_pDcGpPointCloudImpl->SetBorderInValid(); }
//保存到文件 bool DcGp::DcGpPointCloud::SaveToFile(QFile& file) const { if (file.open(QIODevice::WriteOnly)) { QTextStream out(&file); //设置格式控制 out.setRealNumberNotation(QTextStream::FixedNotation); out.setRealNumberPrecision(3); //获取偏移量坐标值 Point_3D shift = GetShift(); for (unsigned i = 0; i < Size(); ++i) { out << m_pDcGpPointCloudImpl->m_points[i][0] - shift[0] << ' ' << m_pDcGpPointCloudImpl->m_points[i][1] - shift[1] << ' ' << m_pDcGpPointCloudImpl->m_points[i][2] - shift[2] << endl; } file.close(); return true; } return false; }
dword fbKEYtoK(dword chr) { if(findarg(chr, 9, 0xd) < 0) chr = chr + K_DELTA; if(chr == K_ALT_KEY || chr == K_CTRL_KEY || chr == K_SHIFT_KEY) return chr; if(GetCtrl()) chr |= K_CTRL; if(GetAlt()) chr |= K_ALT; if(GetShift()) chr |= K_SHIFT; return chr; /* if(chr == SDLK_TAB) chr = K_TAB; else if(chr == SDLK_SPACE) chr = K_SPACE; else if(chr == SDLK_RETURN) chr = K_RETURN; else chr = chr + K_DELTA; */ }
CvMat* ShiftMapHierarchy::CalculateLabelMapGuess() { CvMat* output = cvCreateMat(_outputSize.height, _outputSize.width, CV_32SC2); int num_pixels = _outputSize.width * _outputSize.height; printf("Getting label map... \n"); for(int i = 0; i < num_pixels; i++) { int label = _gc->whatLabel(i); CvPoint point = GetPoint(i, _outputSize); CvPoint shift = GetShift(label, _shiftSize); CvPoint guess = GetLabel(point, _initialGuess); CvPoint pointLabel = cvPoint(shift.x + guess.x, shift.y + guess.y); // test //CvPoint mapped = cvPoint(point.x + pointLabel.x, point.y + pointLabel.y); //if(IsOutside(mapped, _inputSize)) // printf("test"); SetLabel(point, pointLabel, output); } return output; }
dword fbKEYtoK(dword chr) { if(chr == SCANCODE_TAB) chr = K_TAB; else if(chr == SCANCODE_SPACE) chr = K_SPACE; else if(chr == SCANCODE_ENTER) chr = K_RETURN; else chr = chr + K_DELTA; //if the mod keys themselves, no need to have CTRL+ xxx behaviour indicator if(chr == K_ALT_KEY || chr == K_CTRL_KEY || chr == K_SHIFT_KEY) return chr; if(GetCtrl()) chr |= K_CTRL; if(GetAlt()) chr |= K_ALT; if(GetShift()) chr |= K_SHIFT; return chr; }
HRESULT CTextureHolder::CopyBitmapToSurface(){ // Get a DDraw object to create a temporary surface LPDIRECTDRAW7 pDD; m_pddsSurface->GetDDInterface( (VOID**)&pDD ); // Get the bitmap structure (to extract width, height, and bpp) BITMAP bm; GetObject( m_hbmBitmap, sizeof(BITMAP), &bm ); // Setup the new surface desc DDSURFACEDESC2 ddsd; ddsd.dwSize = sizeof(ddsd); m_pddsSurface->GetSurfaceDesc( &ddsd ); ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT| DDSD_TEXTURESTAGE; ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE|DDSCAPS_SYSTEMMEMORY; ddsd.ddsCaps.dwCaps2 = 0L; ddsd.dwWidth = bm.bmWidth; ddsd.dwHeight = bm.bmHeight; // Create a new surface for the texture LPDIRECTDRAWSURFACE7 pddsTempSurface; HRESULT hr; if( FAILED( hr = pDD->CreateSurface( &ddsd, &pddsTempSurface, NULL ) ) ) { pDD->Release(); return hr; } // Get a DC for the bitmap HDC hdcBitmap = CreateCompatibleDC( NULL ); if( NULL == hdcBitmap ) { pddsTempSurface->Release(); pDD->Release(); return hr; // bug? return E_FAIL? } SelectObject( hdcBitmap, m_hbmBitmap ); // Handle palettized textures. Need to attach a palette if( ddsd.ddpfPixelFormat.dwRGBBitCount == 8 ) { LPDIRECTDRAWPALETTE pPalette; DWORD dwPaletteFlags = DDPCAPS_8BIT|DDPCAPS_ALLOW256; DWORD pe[256]; WORD wNumColors = GetDIBColorTable( hdcBitmap, 0, 256, (RGBQUAD*)pe ); // Create the color table for( WORD i=0; i<wNumColors; i++ ) { pe[i] = RGB( GetBValue(pe[i]), GetGValue(pe[i]), GetRValue(pe[i]) ); // Handle textures with transparent pixels if( m_dwFlags & (D3DTEXTR_TRANSPARENTWHITE|D3DTEXTR_TRANSPARENTBLACK) ) { // Set alpha for opaque pixels if( m_dwFlags & D3DTEXTR_TRANSPARENTBLACK ) { if( pe[i] != 0x00000000 ) pe[i] |= 0xff000000; } else if( m_dwFlags & D3DTEXTR_TRANSPARENTWHITE ) { if( pe[i] != 0x00ffffff ) pe[i] |= 0xff000000; } } } // Add DDPCAPS_ALPHA flag for textures with transparent pixels if( m_dwFlags & (D3DTEXTR_TRANSPARENTWHITE|D3DTEXTR_TRANSPARENTBLACK) ) dwPaletteFlags |= DDPCAPS_ALPHA; // Create & attach a palette pDD->CreatePalette( dwPaletteFlags, (PALETTEENTRY*)pe, &pPalette, NULL ); pddsTempSurface->SetPalette( pPalette ); m_pddsSurface->SetPalette( pPalette ); SAFE_RELEASE( pPalette ); } // Copy the bitmap image to the surface. HDC hdcSurface; if( SUCCEEDED( pddsTempSurface->GetDC( &hdcSurface ) ) ) { BitBlt( hdcSurface, 0, 0, bm.bmWidth, bm.bmHeight, hdcBitmap, 0, 0, SRCCOPY ); pddsTempSurface->ReleaseDC( hdcSurface ); } DeleteDC( hdcBitmap ); // Copy the temp surface to the real texture surface m_pddsSurface->Blt( NULL, pddsTempSurface, NULL, DDBLT_WAIT, NULL ); // Done with the temp surface pddsTempSurface->Release(); // For textures with real alpha (not palettized), set transparent bits if( ddsd.ddpfPixelFormat.dwRGBAlphaBitMask ) { if( m_dwFlags & (D3DTEXTR_TRANSPARENTWHITE|D3DTEXTR_TRANSPARENTBLACK) ) { // Lock the texture surface DDSURFACEDESC2 ddsd; ddsd.dwSize = sizeof(ddsd); while( m_pddsSurface->Lock( NULL, &ddsd, 0, NULL ) == DDERR_WASSTILLDRAWING ); DWORD dwAlphaMask = ddsd.ddpfPixelFormat.dwRGBAlphaBitMask; DWORD dwRGBMask = ( ddsd.ddpfPixelFormat.dwRBitMask | ddsd.ddpfPixelFormat.dwGBitMask | ddsd.ddpfPixelFormat.dwBBitMask ); DWORD dwColorkey = 0x00000000; // Colorkey on black if( m_dwFlags & D3DTEXTR_TRANSPARENTWHITE ) dwColorkey = dwRGBMask; // Colorkey on white // Add an opaque alpha value to each non-colorkeyed pixel for( DWORD y=0; y<ddsd.dwHeight; y++ ) { WORD* p16 = (WORD*)((BYTE*)ddsd.lpSurface + y*ddsd.lPitch); DWORD* p32 = (DWORD*)((BYTE*)ddsd.lpSurface + y*ddsd.lPitch); for( DWORD x=0; x<ddsd.dwWidth; x++ ) { if( ddsd.ddpfPixelFormat.dwRGBBitCount == 16 ) { if( ( *p16 &= dwRGBMask ) != dwColorkey ) *p16 |= dwAlphaMask; p16++; } if( ddsd.ddpfPixelFormat.dwRGBBitCount == 32 ) { if( ( *p32 &= dwRGBMask ) != dwColorkey ) *p32 |= dwAlphaMask; p32++; } } } m_pddsSurface->Unlock( NULL ); } else if( m_bHasMyAlpha ){ DDSURFACEDESC2 ddsd; ddsd.dwSize = sizeof(ddsd); while( m_pddsSurface->Lock( NULL, &ddsd, 0, NULL ) == DDERR_WASSTILLDRAWING ); DWORD dwRGBMask = ( ddsd.ddpfPixelFormat.dwRBitMask | ddsd.ddpfPixelFormat.dwGBitMask | ddsd.ddpfPixelFormat.dwBBitMask ); DWORD rMask = ddsd.ddpfPixelFormat.dwRBitMask; DWORD gMask = ddsd.ddpfPixelFormat.dwGBitMask; DWORD bMask = ddsd.ddpfPixelFormat.dwBBitMask; DWORD aMask = ddsd.ddpfPixelFormat.dwRGBAlphaBitMask; DWORD rShift = GetShift( rMask ); DWORD gShift = GetShift( gMask ); DWORD bShift = GetShift( bMask ); DWORD aShift = GetShift( aMask ); DWORD maxRVal = rMask >> rShift; DWORD maxGVal = gMask >> gShift; DWORD maxBVal = bMask >> bShift; DWORD maxAVal = aMask >> aShift; DWORD rVal, gVal, bVal, aVal; FLOAT min, max; // Add an opaque alpha value to each non-colorkeyed pixel for( DWORD y=0; y<ddsd.dwHeight; y++ ){ WORD* p16 = (WORD*)((BYTE*)ddsd.lpSurface + y*ddsd.lPitch); DWORD* p32 = (DWORD*)((BYTE*)ddsd.lpSurface + y*ddsd.lPitch); for( DWORD x=0; x<ddsd.dwWidth; x++ ){ if( ddsd.ddpfPixelFormat.dwRGBBitCount == 32 ){ *p32 &= dwRGBMask; // set alpha to zero if( *p32 == 0 ){} // black is 100% transparent, so leave alpha at 0% else if( *p32 == dwRGBMask ){ // white is opaque, so set alpha to 100% *p32 |= aMask; } else{ // set alpha to equal intensity of brightest hue rVal = ( *p32 & rMask ) >> rShift; gVal = ( *p32 & gMask ) >> gShift; bVal = ( *p32 & bMask ) >> bShift; max = max( (FLOAT)rVal / maxRVal, max( (FLOAT)gVal / maxGVal, (FLOAT)bVal / maxBVal ) ); // min = min( (FLOAT)rVal / maxRVal, min( (FLOAT)gVal / maxGVal, (FLOAT)bVal / maxBVal ) ); aVal = max * 255; //if( rVal == gVal && gVal == bVal ){ // white fading to black // *p32 = dwRGBMask; // set color to white //} // maximize luminosity and saturation rVal /= max; gVal /= max; bVal /= max; *p32 = ( aVal << aShift ) | ( rVal << rShift ) | ( gVal << gShift ) | ( bVal << bShift ); } p32++; } else if( ddsd.ddpfPixelFormat.dwRGBBitCount == 16 ){ *p16 &= dwRGBMask; // set alpha to zero if( *p16 == 0 ){} // black is 100% transparent, so leave alpha at 0% else if( *p16 == dwRGBMask ){ // white is opaque, so set alpha to 100% *p16 |= aMask; } else{ // set alpha to equal intensity of brightest hue rVal = ( *p16 & rMask ) >> rShift; gVal = ( *p16 & gMask ) >> gShift; bVal = ( *p16 & bMask ) >> bShift; aVal = STATSTEXTURE_ALPHA * max( (FLOAT)rVal / maxRVal, max( (FLOAT)gVal / maxGVal, (FLOAT)bVal / maxBVal ) ); if( aVal < STATSTEXTURE_ALPHA ){ // semi-tranparent white *p16 = dwRGBMask; } *p16 |= aVal << aShift; } p16++; } } }
unsigned OptShift5 (CodeSeg* S) /* Search for the sequence * * lda xxx * ldx yyy * jsr aslax1/asrax1/shlax1/shrax1 * sta aaa * stx bbb * * and replace it by * * lda xxx * asl a * sta aaa * lda yyy * rol a * sta bbb * * or similar, provided that a/x is not used later */ { unsigned Changes = 0; /* Walk over the entries */ unsigned I = 0; while (I < CS_GetEntryCount (S)) { unsigned ShiftType; CodeEntry* L[5]; /* Get next entry */ L[0] = CS_GetEntry (S, I); /* Check for the sequence */ if (L[0]->OPC == OP65_LDA && (L[0]->AM == AM65_ABS || L[0]->AM == AM65_ZP) && CS_GetEntries (S, L+1, I+1, 4) && !CS_RangeHasLabel (S, I+1, 4) && L[1]->OPC == OP65_LDX && (L[1]->AM == AM65_ABS || L[1]->AM == AM65_ZP) && L[2]->OPC == OP65_JSR && (ShiftType = GetShift (L[2]->Arg)) != SHIFT_NONE && SHIFT_COUNT(ShiftType) == 1 && L[3]->OPC == OP65_STA && (L[3]->AM == AM65_ABS || L[3]->AM == AM65_ZP) && L[4]->OPC == OP65_STX && (L[4]->AM == AM65_ABS || L[4]->AM == AM65_ZP) && !RegAXUsed (S, I+5)) { CodeEntry* X; /* Handle the four shift types differently */ switch (ShiftType) { case SHIFT_ASR_1: X = NewCodeEntry (OP65_LDA, L[1]->AM, L[1]->Arg, 0, L[1]->LI); CS_InsertEntry (S, X, I+5); X = NewCodeEntry (OP65_CMP, AM65_IMM, "$80", 0, L[2]->LI); CS_InsertEntry (S, X, I+6); X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+7); X = NewCodeEntry (OP65_STA, L[4]->AM, L[4]->Arg, 0, L[4]->LI); CS_InsertEntry (S, X, I+8); X = NewCodeEntry (OP65_LDA, L[0]->AM, L[0]->Arg, 0, L[0]->LI); CS_InsertEntry (S, X, I+9); X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+10); X = NewCodeEntry (OP65_STA, L[3]->AM, L[3]->Arg, 0, L[3]->LI); CS_InsertEntry (S, X, I+11); CS_DelEntries (S, I, 5); break; case SHIFT_LSR_1: X = NewCodeEntry (OP65_LDA, L[1]->AM, L[1]->Arg, 0, L[1]->LI); CS_InsertEntry (S, X, I+5); X = NewCodeEntry (OP65_LSR, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+6); X = NewCodeEntry (OP65_STA, L[4]->AM, L[4]->Arg, 0, L[4]->LI); CS_InsertEntry (S, X, I+7); X = NewCodeEntry (OP65_LDA, L[0]->AM, L[0]->Arg, 0, L[0]->LI); CS_InsertEntry (S, X, I+8); X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+9); X = NewCodeEntry (OP65_STA, L[3]->AM, L[3]->Arg, 0, L[3]->LI); CS_InsertEntry (S, X, I+10); CS_DelEntries (S, I, 5); break; case SHIFT_LSL_1: case SHIFT_ASL_1: /* These two are identical */ X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+1); X = NewCodeEntry (OP65_STA, L[3]->AM, L[3]->Arg, 0, L[3]->LI); CS_InsertEntry (S, X, I+2); X = NewCodeEntry (OP65_LDA, L[1]->AM, L[1]->Arg, 0, L[1]->LI); CS_InsertEntry (S, X, I+3); X = NewCodeEntry (OP65_ROL, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+4); X = NewCodeEntry (OP65_STA, L[4]->AM, L[4]->Arg, 0, L[4]->LI); CS_InsertEntry (S, X, I+5); CS_DelEntries (S, I+6, 4); break; } /* Remember, we had changes */ ++Changes; } /* Next entry */ ++I; } /* Return the number of changes made */ return Changes; }
DWORD PixelFormat::AlphaShift() const { return GetShift(AlphaMask()); }
void Ctrl::Proc() { #ifdef LOG_EVENTS String ev = "?"; Tuple2<int, const char *> *f = FindTuple(xEvent, __countof(xEvent), CurrentEvent.type); if(f) ev = f->b; LOG(rmsecs() << " PROCESS EVENT " << Upp::Name(this) << " " << ev); ProcStop tm; tm.ev = ev; #endif if(!IsOpen()) return; Ptr<Ctrl> _this = this; bool pressed = false; int kv; static int clicktime = msecs() - 100000; switch(CurrentEvent.type) { case GDK_MOTION_NOTIFY: { GtkMouseEvent(MOUSEMOVE, MOUSEMOVE, 0); break; } case GDK_BUTTON_PRESS: if(!HasWndFocus() && !popup) SetWndFocus(); ClickActivateWnd(); if(ignoremouseup) { KillRepeat(); ignoreclick = false; ignoremouseup = false; } if(!ignoreclick) GtkButtonEvent(msecs(clicktime) < 250 ? DOUBLE : DOWN); clicktime = msecs(); break; /* case GDK_2BUTTON_PRESS: if(!ignoreclick) GtkButtonEvent(DOUBLE); break; */ case GDK_BUTTON_RELEASE: if(ignoreclick) EndIgnore(); else GtkButtonEvent(UP); break; case GDK_SCROLL: { GtkMouseEvent(MOUSEWHEEL, MOUSEWHEEL, CurrentEvent.value); break; } case GDK_KEY_PRESS: pressed = true; case GDK_KEY_RELEASE: kv = CurrentEvent.value; if(kv >= 0 && kv < 65536) { LLOG("keyval " << FormatIntHex(kv) << ' ' << (char)kv); if(kv >= 'a' && kv <= 'z') kv = kv - 'a' + 'A'; static Tuple2<int, int> cv[] = { { GDKEY(BackSpace), K_BACKSPACE }, { GDKEY(Tab), K_TAB }, { GDKEY(ISO_Left_Tab), K_TAB }, { GDKEY(Return), K_ENTER }, { GDKEY(Escape), K_ESCAPE }, { GDKEY(space), K_SPACE }, { GDKEY(Control_L), K_CTRL_KEY }, { GDKEY(Control_R), K_CTRL_KEY }, { GDKEY(Shift_L), K_SHIFT_KEY }, { GDKEY(Shift_R), K_SHIFT_KEY }, { GDKEY(Alt_L), K_ALT_KEY }, { GDKEY(Alt_R), K_ALT_KEY }, { GDKEY(KP_Space), K_SPACE }, { GDKEY(KP_Tab), K_TAB }, { GDKEY(KP_Enter), K_ENTER }, { GDKEY(KP_F1), K_F1 }, { GDKEY(KP_F2), K_F2 }, { GDKEY(KP_F3), K_F3 }, { GDKEY(KP_F4), K_F4 }, { GDKEY(KP_Home), K_HOME }, { GDKEY(KP_Left), K_LEFT }, { GDKEY(KP_Up), K_UP }, { GDKEY(KP_Right), K_RIGHT }, { GDKEY(KP_Down), K_DOWN }, { GDKEY(KP_Page_Up), K_PAGEUP }, { GDKEY(KP_Page_Down), K_PAGEDOWN }, { GDKEY(KP_End), K_END }, { GDKEY(KP_Begin), K_HOME }, { GDKEY(KP_Insert), K_INSERT }, { GDKEY(KP_Delete), K_DELETE }, }; Tuple2<int, int> *x = FindTuple(cv, __countof(cv), kv); if(x) kv = x->b; else kv += K_DELTA; if(GetShift() && kv != K_SHIFT_KEY) kv |= K_SHIFT; if(GetCtrl() && kv != K_CTRL_KEY) kv |= K_CTRL; if(GetAlt() && kv != K_ALT_KEY) kv |= K_ALT; LLOG(GetKeyDesc(kv) << ", pressed: " << pressed << ", count: " << CurrentEvent.count); #ifdef GDK_WINDOWING_X11 if(pressed) for(int i = 0; i < hotkey.GetCount(); i++) { if(hotkey[i] && keyhot[i] == (dword)kv) { hotkey[i](); return; } } #endif DispatchKey(!pressed * K_KEYUP + kv, CurrentEvent.count); } break; case EVENT_TEXT: { WString h = CurrentEvent.value; for(int i = 0; i < h.GetCount(); i++) // TODO: Add compression DispatchKey(h[i], 1); break; } case GDK_DELETE: { TopWindow *w = dynamic_cast<TopWindow *>(this); if(w) { if(IsEnabled()) { IgnoreMouseUp(); w->WhenClose(); } } return; } case GDK_CONFIGURE: { Rect rect = CurrentEvent.value; if(GetRect() != rect) SetWndRect(rect); } break; default: return; } if(_this) _this->PostInput(); }
DWORD PixelFormat::GreenShift() const { return GetShift(GreenMask()); }
DWORD PixelFormat::BlueShift() const { return GetShift(BlueMask()); }
//***************************************************************************** // TXML_Lex::NextLexem (m) - returns next extracted lexem. // Your should define the function yourself. //***************************************************************************** Lexem TXML_Lex::NextLexem( void ) { Lexem ret; double *p_d; QString *p_s; ret.LexType = LEX_NONE; do { while( IsSpaceNextChar() ) ; //*** Remarks' termination *** if( RemTermination( ret ) == -1 ) { if( ret.LexType == __LEX_eof ) { ret.LexType = LEX_eof; PutBack(); } continue; } ret.line = GetLine(); ret.col = GetCol(); ret.shift = GetShift(); if( ( SoleChar().isDigit() || SoleChar() == _T('.') || SoleChar() == _T('+') || SoleChar() == _T('-') ) && mode == TXML_Lex_MODE_INTAG ) { static LSDigit ldigit; ldigit.Reset(); ret.LexType = ldigit.Analisys( getCurrentText() ); switch( ret.LexType ) { case LSDigit::Integer: ret.Index = ldigit.asign * ldigit.mnt_int; ret.LexType = LEX_const_int; break; case LSDigit::Float: ret.LexType = LEX_const_real; ldigit.mnt_float *= pow( 10.0, (int)ldigit.power ); ret.Smth = d_autoheap.Add2List( p_d = new double( ldigit.asign * ldigit.mnt_float ) ); break; case LSDigit::FloatIEEE: ret.LexType = LEX_const_real; ldigit.mnt_float *= pow( 10.0, (int)(ldigit.power + ldigit.sign * ldigit.powerE) ); ret.Smth = d_autoheap.Add2List( p_d = new double( ldigit.asign * ldigit.mnt_float ) ); break; default: lex_err = Lex::BadNumericFormat; ret.LexType = LEX_NONE; ret.Smth = 0; } Inc( ldigit.GetRead() ); continue; } if( (SoleChar() == _T('\"') || SoleChar() == _T('\'')) && mode == TXML_Lex_MODE_INTAG ) { static LXMLString lstring( SoleChar() ); lstring.Reset( SoleChar() ); if( ( ret.LexType = lstring.Analisys( getCurrentText() ) ) != LEX_NONE ) { ret.LexType = LEX_const_string; ret.Smth = s_autoheap.Add2List( p_s = new QString( lstring.read_string ) ); } Inc( lstring.GetRead() ); continue; } if( (SoleChar().isLetter() || (SoleChar() == _T('_'))) && mode == TXML_Lex_MODE_INTAG ) { static LXMLVar lvar; lvar.Reset(); int r = lvar.Analisys( getCurrentText() ); if( r ) { if( r == LXMLVar::XML ) ret.LexType = LEX_kw_xml; else if( r == LXMLVar::DOCTYPE ) ret.LexType = LEX_kw_doctype; else ret.LexType = LEX_id; ret.Smth = s_autoheap.Add2List( p_s = new QString( (lvar.getNS().length() == 0) ? lvar.getID() : (lvar.getNS() + _T(":") + lvar.getID()) ) ); Inc( lvar.GetRead() ); } else ret.LexType = LEX_NONE; continue; } if( mode == TXML_Lex_MODE_INTAG ) { QChar tch = NextChar(); switch( tch.unicode() ) { case _T('<'): if( SoleChar() == _T('?') ) { ret.LexType = LEX_begintag_q; NextChar(); } else if( SoleChar() == _T('!') ) { ret.LexType = LEX_begintag_e; NextChar(); } else if( SoleChar() == _T('/') ) { ret.LexType = LEX_begintag_s; NextChar(); } else ret.LexType = LEX_begintag; mode = TXML_Lex_MODE_INTAG; break; case _T('>'): ret.LexType = LEX_endtag; mode = TXML_Lex_MODE_OUTTAG; break; case _T('='): ret.LexType = LEX_equal; break; case _T('['): ret.LexType = LEX_lab; break; case _T(']'): ret.LexType = LEX_rab; break; case EOF_ASCII_1A : case EOF_ASCII_NULL : ret.LexType = LEX_eof; PutBack(); break; case _T('/'): case _T('?'): if( SoleChar() == _T('>') ) { ret.LexType = tch == _T('/') ? LEX_endtag_s : LEX_endtag_q; mode = TXML_Lex_MODE_OUTTAG; NextChar(); } else ret.LexType = LEX_NONE; break; } } else { switch( NextChar().unicode() ) { case _T('<'): if( SoleChar() == _T('?') ) { ret.LexType = LEX_begintag_q; NextChar(); } else if( SoleChar() == _T('!') ) { ret.LexType = LEX_begintag_e; NextChar(); } else if( SoleChar() == _T('/') ) { ret.LexType = LEX_begintag_s; NextChar(); } else ret.LexType = LEX_begintag; mode = TXML_Lex_MODE_INTAG; break; case EOF_ASCII_1A : // !!! eof !!! case EOF_ASCII_NULL : // !!! eof !!! ret.LexType = LEX_eof; PutBack(); break; default : { QChar pch; PutBack( 2 ); while( SoleChar().isSpace() && !isBOF() ) PutBack(); NextChar(); ret.Smth = s_autoheap.Add2List( p_s = new QString( _T("") ) ); ret.LexType = LEX_text; for( pch = NextChar(); pch != QChar('<') && pch != QChar(EOF_ASCII_1A) && pch != QChar(EOF_ASCII_NULL); pch = NextChar() ) { *(QString*)ret.Smth += pch; } PutBack(); } } } } while( 0 ); prev_lexem.LexType = ret.LexType; return ret; }
DWORD PixelFormat::RedShift() const { return GetShift(RedMask()); }
bool Monster::Draw(int nViewX, int nViewY, int nFocusMask) { // monster graphics retrieving key structure // // 3322 2222 2222 1111 1111 1100 0000 0000 // 1098 7654 3210 9876 5432 1098 7654 3210 // ^^^^ ^^^^ ^^^^ ^^^^ ^^^^ ^^^^ ^^^^ ^^^^ // |||| |||| |||| |||| |||| |||| |||| |||| // |||| |||| |||| |||| |||+-++++----------- frame : max = 32 // |||| |||| |||| |||| +++----------------- direction : max = 8 -+ // |||| |||| |||| ++++--------------------- motion : max = 16 -+ // |+++-++++-++++-------------------------- look : max = 2048 -+------> GfxID // +--------------------------------------- shadow : max = 2 // auto nGfxID = GfxID(m_CurrMotion.Motion, m_CurrMotion.Direction); if(nGfxID >= 0){ uint32_t nKey0 = ((uint32_t)(0) << 23) + ((uint32_t)(nGfxID & 0X03FFFF) << 5) + m_CurrMotion.Frame; // body uint32_t nKey1 = ((uint32_t)(1) << 23) + ((uint32_t)(nGfxID & 0X03FFFF) << 5) + m_CurrMotion.Frame; // shadow int nDX0 = 0; int nDY0 = 0; int nDX1 = 0; int nDY1 = 0; auto pFrame0 = g_MonsterDBN->Retrieve(nKey0, &nDX0, &nDY0); auto pFrame1 = g_MonsterDBN->Retrieve(nKey1, &nDX1, &nDY1); int nShiftX = 0; int nShiftY = 0; GetShift(&nShiftX, &nShiftY); // always reset the alpha mode for each texture because texture is shared // one texture to draw can be configured with different alpha mode for other creatures if(pFrame0){ SDL_SetTextureAlphaMod(pFrame0, 255); } if(pFrame1){ SDL_SetTextureAlphaMod(pFrame1, 128); } if(true && (m_CurrMotion.Motion == MOTION_MON_DIE) && (m_CurrMotion.FadeOut > 0 )){ // FadeOut : 0 : normal // : 1-255: fadeOut if(pFrame0){ SDL_SetTextureAlphaMod(pFrame0, (255 - m_CurrMotion.FadeOut) / 1); } if(pFrame1){ SDL_SetTextureAlphaMod(pFrame1, (255 - m_CurrMotion.FadeOut) / 2); } } auto fnBlendFrame = [](SDL_Texture *pTexture, int nFocusChan, int nX, int nY) { if(true && pTexture && nFocusChan >= 0 && nFocusChan < FOCUS_MAX){ // if provided channel as 0 // just blend it using the original color auto stColor = FocusColor(nFocusChan); if(!SDL_SetTextureColorMod(pTexture, stColor.r, stColor.g, stColor.b)){ g_SDLDevice->DrawTexture(pTexture, nX, nY); } } }; int nBlendX0 = X() * SYS_MAPGRIDXP + nDX0 - nViewX + nShiftX; int nBlendY0 = Y() * SYS_MAPGRIDYP + nDY0 - nViewY + nShiftY; int nBlendX1 = X() * SYS_MAPGRIDXP + nDX1 - nViewX + nShiftX; int nBlendY1 = Y() * SYS_MAPGRIDYP + nDY1 - nViewY + nShiftY; fnBlendFrame(pFrame1, 0, nBlendX1, nBlendY1); fnBlendFrame(pFrame0, 0, nBlendX0, nBlendY0); for(int nFocusChan = 1; nFocusChan < FOCUS_MAX; ++nFocusChan){ if(nFocusMask & (1 << nFocusChan)){ fnBlendFrame(pFrame0, nFocusChan, nBlendX0, nBlendY0); } } // draw attached magics for(auto pMagic: m_AttachMagicList){ pMagic->Draw(X() * SYS_MAPGRIDXP - nViewX + nShiftX, Y() * SYS_MAPGRIDYP - nViewY + nShiftY); } // draw HP bar // if current m_HPMqx is zero we draw full bar if(m_CurrMotion.Motion != MOTION_MON_DIE){ auto pBar0 = g_ProgUseDBN->Retrieve(0X00000014); auto pBar1 = g_ProgUseDBN->Retrieve(0X00000015); int nW = -1; int nH = -1; SDL_QueryTexture(pBar1, nullptr, nullptr, &nW, &nH); g_SDLDevice->DrawTexture(pBar1, X() * SYS_MAPGRIDXP - nViewX + nShiftX + 7, Y() * SYS_MAPGRIDYP - nViewY + nShiftY - 53, 0, 0, (int)(std::lround(nW * (m_HPMax ? (std::min<double>)(1.0, (1.0 * m_HP) / m_HPMax) : 1.0))), nH); g_SDLDevice->DrawTexture(pBar0, X() * SYS_MAPGRIDXP - nViewX + nShiftX + 7, Y() * SYS_MAPGRIDYP - nViewY + nShiftY - 53); } } return false; }
void Ctrl::EventProc(XWindow& w, XEvent *event) { GuiLock __; eventid++; Ptr<Ctrl> _this = this; bool pressed = false; int count = 1; switch(event->type) { case NoExpose: LLOG("NoExpose serial " << event->xnoexpose.serial); break; case GraphicsExpose: LLOG("GraphicsExpose serial " << event->xgraphicsexpose.serial); case Expose: { XExposeEvent& e = event->xexpose; w.exposed = true; LLOG("Expose " << RectC(e.x, e.y, e.width, e.height)); Invalidate(w, RectC(e.x, e.y, e.width, e.height)); } return; case ConfigureNotify: { XConfigureEvent& e = event->xconfigure; int x, y; Window dummy; // 01/12/2007 - mdelfede // added support for windowed controls // if(top) // XTranslateCoordinates(Xdisplay, top->window, Xroot, 0, 0, &x, &y, &dummy); if(top) { Window DestW = (parent ? GetParentWindow() : Xroot); XTranslateCoordinates(Xdisplay, top->window, DestW, 0, 0, &x, &y, &dummy); Rect rect = RectC(x, y, e.width, e.height); LLOG("CongigureNotify " << rect); if(GetRect() != rect) SetWndRect(rect); // Synchronizes native windows (NOT the main one) } SyncNativeWindows(); // 01/12/2007 - END } return; default: if(!IsEnabled()) return; } LTIMING("XUserInput"); switch(event->type) { case FocusIn: if(w.xic) XSetICFocus(w.xic); break; case FocusOut: if(w.xic) XUnsetICFocus(w.xic); break; case KeyPress: pressed = true; LLOG("event type:" << event->type << " state:" << event->xkey.state << "keycode:" << event->xkey.keycode); for(;;) { XEvent ev1[1], ev2[1]; bool hasev2 = false; if(!IsWaitingEvent()) break; do XNextEvent(Xdisplay, ev1); while(ev1->type == NoExpose && IsWaitingEvent()); LLOG("ev1 type:" << ev1->type << " state:" << ev1->xkey.state << "keycode:" << ev1->xkey.keycode); if(ev1->type == KeyPress) *ev2 = *ev1; else { if(ev1->type != KeyRelease || ev1->xkey.state != event->xkey.state || ev1->xkey.keycode != event->xkey.keycode || !IsWaitingEvent()) { XPutBackEvent(Xdisplay, ev1); break; } do XNextEvent(Xdisplay, ev2); while(ev2->type == NoExpose && IsWaitingEvent()); LLOG("ev2 type:" << ev2->type << " state:" << ev2->xkey.state << "keycode:" << ev2->xkey.keycode); hasev2 = true; } if(ev2->type != KeyPress || ev2->xkey.state != event->xkey.state || ev2->xkey.keycode != event->xkey.keycode) { if(hasev2) XPutBackEvent(Xdisplay, ev2); XPutBackEvent(Xdisplay, ev1); break; } else { XFilterEvent(ev1, None); if(hasev2) XFilterEvent(ev2, None); } count++; } case KeyRelease: { mousePos = Point(event->xkey.x_root, event->xkey.y_root); char buff[128]; Xeventtime = event->xkey.time; LLOG("Key Xeventtime: " << Xeventtime << " count:" << count); KeySym keysym; int chr = 0; WString wtext; if(pressed && w.xic) { Status status; int len = Xutf8LookupString(w.xic, &event->xkey, buff, sizeof(buff), &keysym, &status); buff[len] = 0; if(status == XLookupChars || status == XLookupBoth) { chr = FromUtf8(buff, len)[0]; if(status == XLookupChars) wtext = FromUtf8(buff, len); } else if(status != XLookupKeySym && status != XLookupBoth) keysym = 0; } else { int len = XLookupString(&event->xkey, buff, sizeof(buff), &keysym, NULL); buff[len] = 0; chr = FromUtf8(buff, len)[0]; if(len > 1) wtext = FromUtf8(buff, len); } if(keysym == XK_Control_L || keysym == XK_Control_R) { keysym = XK_Control_L; if(pressed) sKbdState |= ControlMask; else sKbdState &= ~ControlMask; } if(keysym == XK_Shift_L || keysym == XK_Shift_R) { keysym = XK_Shift_L; if(pressed) sKbdState |= ShiftMask; else sKbdState &= ~ShiftMask; } if(keysym == XK_Meta_L || keysym == XK_Meta_R || keysym == XK_Alt_L || keysym == XK_Alt_R || keysym == XK_Super_L || keysym == XK_Super_R || keysym == XK_Hyper_L || keysym == XK_Hyper_R || keysym == XK_ISO_Prev_Group) { keysym = XK_Meta_L; if(pressed) sKbdState |= Mod1Mask; else sKbdState &= ~Mod1Mask; } LLOG("KeySym:" << FormatIntHex(keysym) << " " << (char)keysym << " " << count); dword up = pressed ? 0 : K_KEYUP; static struct { KeySym keysym; dword key; } tab[] = { { XK_ISO_Left_Tab, K_TAB|K_SHIFT }, { XK_BackSpace, K_BACKSPACE }, { XK_Tab, K_TAB }, { XK_Return, K_ENTER }, { XK_KP_Enter, K_ENTER }, { XK_Escape, K_ESCAPE }, { XK_space, K_SPACE }, { XK_KP_Space, K_SPACE }, { XK_KP_Tab, K_TAB }, { XK_KP_Enter, K_ENTER }, { XK_KP_F1, K_F1 }, { XK_KP_F2, K_F2 }, { XK_KP_F3, K_F3 }, { XK_KP_F4, K_F4 }, { XK_KP_Home, K_HOME }, { XK_KP_Left, K_LEFT }, { XK_KP_Up, K_UP }, { XK_KP_Right, K_RIGHT }, { XK_KP_Down, K_DOWN }, { XK_KP_Page_Up, K_PAGEUP }, { XK_KP_Page_Down, K_PAGEDOWN }, { XK_KP_End, K_END }, { XK_KP_Begin, K_HOME }, { XK_KP_Insert, K_INSERT }, { XK_KP_Delete, K_DELETE }, }; for(int i = 0; i < __countof(tab); i++) if(tab[i].keysym == keysym) { DispatchKey(KEYtoK(tab[i].key)|up, count); return; } if(GetShift() && chr == 0) { static dword k[] = { 41, 33, 64, 35, 36, 37, 94, 38, 42, 40 }; for(int i = 0; i < 10; i++) if(keysym == k[i]) { DispatchKey(KEYtoK(i + K_0)|up, count); return; } } if(keysym >= 48 && keysym <= 57 && chr == 0) { DispatchKey(KEYtoK(keysym - 48 + K_0)|up, count); return; } if(chr >= 1 && chr < 32) { DispatchKey(KEYtoK(chr - 1 + K_CTRL_A)|up, count); return; } if(keysym >= 0xff80 && keysym <= 0xffb9 && chr) { DispatchKey(KEYtoK(chr)|up, count); return; } if(keysym >= 0xff00 && chr < 128 || (GetCtrl() || GetAlt()) && keysym >= 0x20 && keysym < 0x7f) { if(keysym >= 'a' && keysym <= 'z') keysym = keysym - 'a' + 'A'; DispatchKey(KEYtoK(keysym|K_DELTA)|up, count); return; } if((chr == 32 || chr == 9 || chr == 13) && !pressed) DispatchKey(chr|K_KEYUP, count); if(chr && pressed) { DispatchKey(chr, count); for(int ii = 1; ii < wtext.GetLength(); ii++) DispatchKey(wtext[ii], count); } } break; case ButtonPress: { if(!HasWndFocus() && !popup) SetWndFocus(); ClickActivateWnd(); mousePos = Point(event->xbutton.x_root, event->xbutton.y_root); ReleaseGrab(); XButtonEvent& e = event->xbutton; sModState = e.state; Xeventtime = e.time; if(ignoreclick) break; Point p = Point(e.x, e.y); dword action = DOWN; if((dword)e.time - (dword)Xbuttontime < 800) { action = DOUBLE; Xbuttontime = Xeventtime - 0x80000000; } else { Xbuttontime = e.time; Xbuttonpos = mousePos; } switch(e.button) { case Button1: sModState |= Button1Mask; DispatchMouse(LEFT|action, p, 0); break; case Button2: sModState |= Button2Mask; if(Xbuttons < 3) DispatchMouse(RIGHT|action, p, 0); else DispatchMouse(MIDDLE|action, p, 0); break; case Button3: sModState |= Button3Mask; DispatchMouse(RIGHT|action, p, 0); break; } if(_this) PostInput(); } break; case ButtonRelease: { mousePos = Point(event->xbutton.x_root, event->xbutton.y_root); XButtonEvent& e = event->xbutton; sModState = e.state; Xeventtime = e.time; Point p = Point(e.x, e.y); switch(e.button) { case Button1: sModState &= ~Button1Mask; break; case Button2: sModState &= ~Button2Mask; break; case Button3: sModState &= ~Button3Mask; break; } if(ignoreclick) EndIgnore(); else switch(e.button) { case Button1: DispatchMouse(LEFTUP, p, 0); break; case Button2: if(Xbuttons < 3) DispatchMouse(RIGHTUP, p, 0); else DispatchMouse(MIDDLEUP, p, 0); break; case Button3: DispatchMouse(RIGHTUP, p, 0); break; case Button4: DispatchMouse(MOUSEWHEEL, p, 120); break; case Button5: DispatchMouse(MOUSEWHEEL, p, -120); break; } if(_this) PostInput(); } break; case MotionNotify: while(XCheckWindowEvent(Xdisplay, top->window, PointerMotionMask, event)); EndIgnore(); mousePos = Point(event->xmotion.x_root, event->xmotion.y_root); Xeventtime = event->xmotion.time; Point p = mousePos - Xbuttonpos; if(max(abs(p.x), abs(p.y)) > 4) Xbuttontime = Xeventtime - 0x80000000; sModState = event->xmotion.state; DispatchMouse(MOUSEMOVE, Point(event->xmotion.x, event->xmotion.y)); DoCursorShape(); break; } DropEvent(w, event); }
unsigned OptShift1 (CodeSeg* S) /* A call to the shlaxN routine may get replaced by one or more asl insns * if the value of X is not used later. If X is used later, but it is zero * on entry and it's a shift by one, it may get replaced by: * * asl a * bcc L1 * inx * L1: * */ { unsigned Changes = 0; unsigned I; /* Walk over the entries */ I = 0; while (I < CS_GetEntryCount (S)) { unsigned Shift; CodeEntry* N; CodeEntry* X; CodeLabel* L; /* Get next entry */ CodeEntry* E = CS_GetEntry (S, I); /* Check for the sequence */ if (E->OPC == OP65_JSR && (Shift = GetShift (E->Arg)) != SHIFT_NONE && SHIFT_DIR (Shift) == SHIFT_DIR_LEFT) { unsigned Count = SHIFT_COUNT (Shift); if (!RegXUsed (S, I+1)) { if (Count == SHIFT_COUNT_Y) { CodeLabel* L; if (S->CodeSizeFactor < 200) { goto NextEntry; } /* Change into * * L1: asl a * dey * bpl L1 * ror a */ /* asl a */ X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, E->LI); CS_InsertEntry (S, X, I+1); L = CS_GenLabel (S, X); /* dey */ X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, E->LI); CS_InsertEntry (S, X, I+2); /* bpl L1 */ X = NewCodeEntry (OP65_BPL, AM65_BRA, L->Name, L, E->LI); CS_InsertEntry (S, X, I+3); /* ror a */ X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, E->LI); CS_InsertEntry (S, X, I+4); } else { /* Insert shift insns */ while (Count--) { X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, E->LI); CS_InsertEntry (S, X, I+1); } } } else if (E->RI->In.RegX == 0 && Count == 1 && (N = CS_GetNextEntry (S, I)) != 0) { /* asl a */ X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, E->LI); CS_InsertEntry (S, X, I+1); /* bcc L1 */ L = CS_GenLabel (S, N); X = NewCodeEntry (OP65_BCC, AM65_BRA, L->Name, L, E->LI); CS_InsertEntry (S, X, I+2); /* inx */ X = NewCodeEntry (OP65_INX, AM65_IMP, 0, 0, E->LI); CS_InsertEntry (S, X, I+3); } else { /* We won't handle this one */ goto NextEntry; } /* Delete the call to shlax */ CS_DelEntry (S, I); /* Remember, we had changes */ ++Changes; } NextEntry: /* Next entry */ ++I; } /* Return the number of changes made */ return Changes; }
unsigned OptShift3 (CodeSeg* S) /* The sequence * * bcc L * inx * L: jsr shrax1 * * may get replaced by * * ror a * * if X is zero on entry. For shift counts > 1, more * * shr a * * must be added. */ { unsigned Changes = 0; unsigned I; /* Walk over the entries */ I = 0; while (I < CS_GetEntryCount (S)) { unsigned Shift; unsigned Count; CodeEntry* L[3]; /* Get next entry */ L[0] = CS_GetEntry (S, I); /* Check for the sequence */ if ((L[0]->OPC == OP65_BCC || L[0]->OPC == OP65_JCC) && L[0]->JumpTo != 0 && L[0]->RI->In.RegX == 0 && CS_GetEntries (S, L+1, I+1, 2) && L[1]->OPC == OP65_INX && L[0]->JumpTo->Owner == L[2] && !CS_RangeHasLabel (S, I, 2) && L[2]->OPC == OP65_JSR && (Shift = GetShift (L[2]->Arg)) != SHIFT_NONE && SHIFT_DIR (Shift) == SHIFT_DIR_RIGHT && (Count = SHIFT_COUNT (Shift)) > 0) { /* Add the replacement insn instead */ CodeEntry* X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+3); while (--Count) { X = NewCodeEntry (OP65_LSR, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+4); } /* Remove the bcs/dex/jsr */ CS_DelEntries (S, I, 3); /* Remember, we had changes */ ++Changes; } /* Next entry */ ++I; } /* Return the number of changes made */ return Changes; }
unsigned OptShift4 (CodeSeg* S) /* Calls to the asraxN or shraxN routines may get replaced by one or more lsr * insns if the value of X is zero. */ { unsigned Changes = 0; unsigned I; /* Walk over the entries */ I = 0; while (I < CS_GetEntryCount (S)) { unsigned Shift; unsigned Count; /* Get next entry */ CodeEntry* E = CS_GetEntry (S, I); /* Check for the sequence */ if (E->OPC == OP65_JSR && (Shift = GetShift (E->Arg)) != SHIFT_NONE && SHIFT_DIR (Shift) == SHIFT_DIR_RIGHT && E->RI->In.RegX == 0) { CodeEntry* X; /* Shift count may be in Y */ Count = SHIFT_COUNT (Shift); if (Count == SHIFT_COUNT_Y) { CodeLabel* L; if (S->CodeSizeFactor < 200) { /* Not acceptable */ goto NextEntry; } /* Generate: * * L1: lsr a * dey * bpl L1 * rol a * * A negative shift count or one that is greater or equal than * the bit width of the left operand (which is promoted to * integer before the operation) causes undefined behaviour, so * above transformation is safe. */ /* lsr a */ X = NewCodeEntry (OP65_LSR, AM65_ACC, "a", 0, E->LI); CS_InsertEntry (S, X, I+1); L = CS_GenLabel (S, X); /* dey */ X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, E->LI); CS_InsertEntry (S, X, I+2); /* bpl L1 */ X = NewCodeEntry (OP65_BPL, AM65_BRA, L->Name, L, E->LI); CS_InsertEntry (S, X, I+3); /* rol a */ X = NewCodeEntry (OP65_ROL, AM65_ACC, "a", 0, E->LI); CS_InsertEntry (S, X, I+4); } else { /* Insert shift insns */ while (Count--) { X = NewCodeEntry (OP65_LSR, AM65_ACC, "a", 0, E->LI); CS_InsertEntry (S, X, I+1); } } /* Delete the call to shrax */ CS_DelEntry (S, I); /* Remember, we had changes */ ++Changes; } NextEntry: /* Next entry */ ++I; } /* Return the number of changes made */ return Changes; }
unsigned OptShift6 (CodeSeg* S) /* Inline the shift subroutines. */ { unsigned Changes = 0; /* Walk over the entries */ unsigned I = 0; while (I < CS_GetEntryCount (S)) { unsigned Shift; unsigned Count; CodeEntry* X; unsigned IP; /* Get next entry */ CodeEntry* E = CS_GetEntry (S, I); /* Check for a call to one of the shift routine */ if (E->OPC == OP65_JSR && (Shift = GetShift (E->Arg)) != SHIFT_NONE && SHIFT_DIR (Shift) == SHIFT_DIR_LEFT && (Count = SHIFT_COUNT (Shift)) > 0) { /* Code is: * * stx tmp1 * asl a * rol tmp1 * (repeat ShiftCount-1 times) * ldx tmp1 * * which makes 4 + 3 * ShiftCount bytes, compared to the original * 3 bytes for the subroutine call. However, in most cases, the * final load of the X register gets merged with some other insn * and replaces a txa, so for a shift count of 1, we get a factor * of 200, which matches nicely the CodeSizeFactor enabled with -Oi */ if (Count > 1 || S->CodeSizeFactor > 200) { unsigned Size = 4 + 3 * Count; if ((Size * 100 / 3) > S->CodeSizeFactor) { /* Not acceptable */ goto NextEntry; } } /* Inline the code. Insertion point is behind the subroutine call */ IP = (I + 1); /* stx tmp1 */ X = NewCodeEntry (OP65_STX, AM65_ZP, "tmp1", 0, E->LI); CS_InsertEntry (S, X, IP++); while (Count--) { /* asl a */ X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, E->LI); CS_InsertEntry (S, X, IP++); /* rol tmp1 */ X = NewCodeEntry (OP65_ROL, AM65_ZP, "tmp1", 0, E->LI); CS_InsertEntry (S, X, IP++); } /* ldx tmp1 */ X = NewCodeEntry (OP65_LDX, AM65_ZP, "tmp1", 0, E->LI); CS_InsertEntry (S, X, IP++); /* Remove the subroutine call */ CS_DelEntry (S, I); /* Remember, we had changes */ ++Changes; } NextEntry: /* Next entry */ ++I; } /* Return the number of changes made */ return Changes; }
WCHAR CKeyboard::GetUnicode() { // More specific mappings, i.e. with scancodes and/or with one or even more modifiers, // must be handled first/prioritized over less specific mappings! Why? // Example: an us keyboard has: "]" on one key, the german keyboard has "+" on the same key, // additionally the german keyboard has "~" on the same key, but the "~" // can only be reached with the special modifier "AltGr" (right alt). // See http://en.wikipedia.org/wiki/Keyboard_layout. // If "+" is handled first, the key is already consumed and "~" can never be reached. // The least specific mappings, e.g. "regardless modifiers" should be done at last/least prioritized. WCHAR lowLevelUnicode = CLowLevelKeyboard::GetUnicode(); BYTE key = CLowLevelKeyboard::GetKey(); #ifdef DEBUG_KEYBOARD_GETCHAR CLog::Log(LOGDEBUG, "low level unicode char: %c ", lowLevelUnicode); CLog::Log(LOGDEBUG, "low level unicode code: %d ", lowLevelUnicode); CLog::Log(LOGDEBUG, "low level vkey: %d ", key); CLog::Log(LOGDEBUG, "ralt is pressed bool: %d ", GetRAlt()); CLog::Log(LOGDEBUG, "shift is pressed bool: %d ", GetShift()); #endif if (GetRAlt()) { if (g_keyboardLayoutConfiguration.containsDeriveXbmcCharFromVkeyWithRalt(key)) { WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfDeriveXbmcCharFromVkeyWithRalt(key); #ifdef DEBUG_KEYBOARD_GETCHAR CLog::Log(LOGDEBUG, "derived with ralt to code: %d ", resultUnicode); #endif return resultUnicode; } } if (GetShift()) { if (g_keyboardLayoutConfiguration.containsDeriveXbmcCharFromVkeyWithShift(key)) { WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfDeriveXbmcCharFromVkeyWithShift(key); #ifdef DEBUG_KEYBOARD_GETCHAR CLog::Log(LOGDEBUG, "derived with shift to code: %d ", resultUnicode); #endif return resultUnicode; } } if (g_keyboardLayoutConfiguration.containsDeriveXbmcCharFromVkeyRegardlessModifiers(key)) { WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfDeriveXbmcCharFromVkeyRegardlessModifiers(key); #ifdef DEBUG_KEYBOARD_GETCHAR CLog::Log(LOGDEBUG, "derived to code: %d ", resultUnicode); #endif return resultUnicode; } if (GetRAlt()) { if (g_keyboardLayoutConfiguration.containsChangeXbmcCharWithRalt(lowLevelUnicode)) { WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfChangeXbmcCharWithRalt(lowLevelUnicode); #ifdef DEBUG_KEYBOARD_GETCHAR CLog::Log(LOGDEBUG, "changed char with ralt to code: %d ", resultUnicode); #endif return resultUnicode; }; } if (g_keyboardLayoutConfiguration.containsChangeXbmcCharRegardlessModifiers(lowLevelUnicode)) { WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfChangeXbmcCharRegardlessModifiers(lowLevelUnicode); #ifdef DEBUG_KEYBOARD_GETCHAR CLog::Log(LOGDEBUG, "changed char to code: %d ", resultUnicode); #endif return resultUnicode; }; return lowLevelUnicode; }