void wxGCDCImpl::DoDrawSpline(const wxPointList *points) { wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") ); if ( !m_logicalFunctionSupported ) return; wxGraphicsPath path = m_graphicContext->CreatePath(); wxPointList::compatibility_iterator node = points->GetFirst(); if ( !node ) // empty list return; const wxPoint *p = node->GetData(); wxCoord x1 = p->x; wxCoord y1 = p->y; node = node->GetNext(); p = node->GetData(); wxCoord x2 = p->x; wxCoord y2 = p->y; wxCoord cx1 = ( x1 + x2 ) / 2; wxCoord cy1 = ( y1 + y2 ) / 2; path.MoveToPoint( x1 , y1 ); path.AddLineToPoint( cx1 , cy1 ); #if !wxUSE_STD_CONTAINERS while ((node = node->GetNext()) != NULL) #else while ((node = node->GetNext())) #endif // !wxUSE_STD_CONTAINERS { p = node->GetData(); x1 = x2; y1 = y2; x2 = p->x; y2 = p->y; wxCoord cx4 = (x1 + x2) / 2; wxCoord cy4 = (y1 + y2) / 2; path.AddQuadCurveToPoint(x1 , y1 ,cx4 , cy4 ); cx1 = cx4; cy1 = cy4; } path.AddLineToPoint( x2 , y2 ); m_graphicContext->StrokePath( path ); wxRect2DDouble box = path.GetBox(); CalcBoundingBox(wxRound(box.m_x), wxRound(box.m_y)); CalcBoundingBox(wxRound(box.m_x + box.m_width), wxRound(box.m_y + box.m_height)); }
bool wxFont::GetStrikethrough() const { wxCHECK_MSG( IsOk(), false, wxT("invalid font") ); return M_FONTDATA->m_nativeFontInfo.GetStrikethrough(); }
int wxPen::GetDashCount() const { wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") ); return (M_PENDATA->m_countDashes); }
wxString wxFont::GetFaceName() const { wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") ); return M_FONTDATA->m_nativeFontInfo.GetFaceName(); }
wxFontWeight wxFont::GetWeight() const { wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") ); return M_FONTDATA->m_weight; }
const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { wxCHECK_MSG( IsOk(), NULL, wxT("invalid font") ); return &(M_FONTDATA->m_nativeFontInfo); }
bool wxFont::GTKSetPangoAttrs(PangoLayout* layout) const { if (!IsOk() || !(GetUnderlined() || GetStrikethrough())) return false; PangoAttrList* attrs = pango_attr_list_new(); PangoAttribute* a; if (wx_pango_version_check(1,16,0)) { // a PangoLayout which has leading/trailing spaces with underlined font // is not correctly drawn by this pango version: Pango won't underline the spaces. // This can be a problem; e.g. wxHTML rendering of underlined text relies on // this behaviour. To workaround this problem, we use a special hack here // suggested by pango maintainer Behdad Esfahbod: we prepend and append two // empty space characters and give them a dummy colour attribute. // This will force Pango to underline the leading/trailing spaces, too. const char* text = pango_layout_get_text(layout); const size_t n = strlen(text); if ((n > 0 && text[0] == ' ') || (n > 1 && text[n - 1] == ' ')) { wxCharBuffer buf(n + 6); // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format memcpy(buf.data(), "\342\200\214", 3); // copy the user string memcpy(buf.data() + 3, text, n); // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format memcpy(buf.data() + 3 + n, "\342\200\214", 3); pango_layout_set_text(layout, buf, n + 6); // Add dummy attributes (use colour as it's invisible anyhow for 0 // width spaces) to ensure that the spaces in the beginning/end of the // string are underlined too. a = pango_attr_foreground_new(0x0057, 0x52A9, 0xD614); a->start_index = 0; a->end_index = 3; pango_attr_list_insert(attrs, a); a = pango_attr_foreground_new(0x0057, 0x52A9, 0xD614); a->start_index = n + 3; a->end_index = n + 6; pango_attr_list_insert(attrs, a); } } if (GetUnderlined()) { a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); pango_attr_list_insert(attrs, a); } if (GetStrikethrough()) { a = pango_attr_strikethrough_new(true); pango_attr_list_insert(attrs, a); } pango_layout_set_attributes(layout, attrs); pango_attr_list_unref(attrs); return true; }
bool wxGCDCImpl::DoStretchBlit( wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight, wxDC *source, wxCoord xsrc, wxCoord ysrc, wxCoord srcWidth, wxCoord srcHeight, wxRasterOperationMode logical_func , bool useMask, wxCoord xsrcMask, wxCoord ysrcMask ) { wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") ); wxCHECK_MSG( source->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") ); if ( logical_func == wxNO_OP ) return true; wxCompositionMode mode = TranslateRasterOp(logical_func); if ( mode == wxCOMPOSITION_INVALID ) { wxFAIL_MSG( wxT("Blitting is not supported with this logical operation.") ); return false; } wxRect subrect(source->LogicalToDeviceX(xsrc), source->LogicalToDeviceY(ysrc), source->LogicalToDeviceXRel(srcWidth), source->LogicalToDeviceYRel(srcHeight)); const wxRect subrectOrig = subrect; // clip the subrect down to the size of the source DC wxRect clip; source->GetSize(&clip.width, &clip.height); subrect.Intersect(clip); if (subrect.width == 0) return true; bool retval = true; wxCompositionMode formerMode = m_graphicContext->GetCompositionMode(); if (m_graphicContext->SetCompositionMode(mode)) { wxAntialiasMode formerAa = m_graphicContext->GetAntialiasMode(); if (mode == wxCOMPOSITION_XOR) { m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE); } if (xsrcMask == -1 && ysrcMask == -1) { xsrcMask = xsrc; ysrcMask = ysrc; } wxBitmap blit = source->GetAsBitmap( &subrect ); if ( blit.IsOk() ) { if ( !useMask && blit.GetMask() ) blit.SetMask(NULL); double x = xdest; double y = ydest; double w = dstWidth; double h = dstHeight; // adjust dest rect if source rect is clipped if (subrect.width != subrectOrig.width || subrect.height != subrectOrig.height) { x += (subrect.x - subrectOrig.x) / double(subrectOrig.width) * dstWidth; y += (subrect.y - subrectOrig.y) / double(subrectOrig.height) * dstHeight; w *= double(subrect.width) / subrectOrig.width; h *= double(subrect.height) / subrectOrig.height; } m_graphicContext->DrawBitmap(blit, x, y, w, h); } else { wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") ); retval = false; } if (mode == wxCOMPOSITION_XOR) { m_graphicContext->SetAntialiasMode(formerAa); } } // reset composition m_graphicContext->SetCompositionMode(formerMode); return retval; }
bool wxGCDCImpl::CanGetTextExtent() const { wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") ); return true; }
void wxGCDCImpl::SetTextBackground( const wxColour &col ) { wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") ); m_textBackgroundColour = col; }
void wxGCDCImpl::DoDrawPoint( wxCoord x, wxCoord y ) { wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") ); DoDrawLine( x , y , x + 1 , y + 1 ); }
wxBitmap *wxBrush::GetStipple() const { wxCHECK_MSG( IsOk(), NULL, wxT("invalid brush") ); return &M_BRUSHDATA->m_stipple; }
wxColour wxBrush::GetColour() const { wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid brush") ); return M_BRUSHDATA->m_colour; }
wxBrushStyle wxBrush::GetStyle() const { wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID, wxT("invalid brush") ); return M_BRUSHDATA->m_style; }
int wxPen::GetWidth() const { wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") ); return 1; }
int CSocket::ReadLine ( CString& szDest ) { int iSize; if ( !IsOk () ) return -1; do { if ( m_bufferSize > 0 ) { char* p = strchr ( m_buffer, '\n' ); if ( p && ( p <= ( m_buffer + m_bufferSize ) ) ) { char* p2 = p; while ( p2 > m_buffer && ( *p2 == '\n' || *p2 == '\r' ) ) *p2-- = '\0'; size_t len = static_cast < size_t > ( p2 - m_buffer + 1 ); if ( len > 1 || ( *p2 != '\n' && *p2 != '\r' ) ) { szDest.assign ( m_buffer, len ); } size_t len2 = static_cast < size_t > ( p - m_buffer ); assert ( m_bufferSize >= len2 ); memcpy ( m_buffer, p + 1, m_bufferSize - len2 ); m_bufferSize -= len2 + 1; m_buffer [ m_bufferSize ] = '\0'; return len2; } } // Llamamos a select para establecer un timeout fd_set fds; FD_ZERO ( &fds ); FD_SET ( m_socket, &fds ); struct timeval* tvTimeout = 0; struct timeval __tvTimeout; if ( m_uiTimeout > 0 ) { __tvTimeout.tv_sec = m_uiTimeout / 1000; __tvTimeout.tv_usec = (m_uiTimeout - ( __tvTimeout.tv_sec * 1000 )) * 1000; tvTimeout = &__tvTimeout; } int nChanged = select ( m_socket + 1, &fds, NULL, NULL, tvTimeout ); // Comprobamos que todo ha ido bien en el select if ( nChanged == -1 ) { m_iErrno = errno; m_szError = strerror ( errno ); InternalClose ( true ); return -1; } else if ( nChanged == 0 ) return 0; else { // Leemos datos desde el socket iSize = recv ( m_socket, m_buffer + m_bufferSize, BUFFER_SIZE - m_bufferSize, 0 ); if ( iSize > 0 ) { m_bufferSize += iSize; } } } while ( iSize > 0 ); m_iErrno = CPortability::SocketErrno (); CPortability::SocketError ( m_iErrno, m_szError ); InternalClose ( true ); return -1; }
wxColour wxPen::GetColour() const { wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") ); return M_PENDATA->m_colour; }
void CComponentPlayerController::UpdatePostPhysX(float _fDeltaTime) { assert(IsOk()); CComponentVida* l_pComponentVida = GetEntity()->GetComponent<CComponentVida>(); CComponentEnergy* l_pComponentEnergy = GetEntity()->GetComponent<CComponentEnergy>(); const vector<CMaterial*>& l_vMaterials = m_pAnimatedModel->GetAnimatedInstanceModel()->GetAnimatedCoreModel()->GetMaterials(); CRenderer *l_pRenderer = CORE->GetRenderer(); CPostSceneRendererStep* l_pDamage = l_pRenderer->GetPostSceneRendererStep("damage_gui"); CPostSceneRendererStep* l_pBlood = l_pRenderer->GetPostSceneRendererStep("blood_gui"); float l_fHP = 100.f; float l_fMaxHP = 100.f; if(l_pComponentVida && !m_bGodMode) { l_fHP = l_pComponentVida->GetHP(); l_fMaxHP = l_pComponentVida->GetMaxHP(); } float l_fEnergy = 100.f; float l_fMaxEnergy = 100.f; if(l_pComponentEnergy && !m_bGodMode) { l_fEnergy = l_pComponentEnergy->GetEnergy(); l_fMaxEnergy = l_pComponentEnergy->GetMaxEnergy(); } float l_fMin = 0.0f; float l_fMax = 1.0f; float l_fGlowIntensity = l_fEnergy/l_fMaxEnergy * (l_fMax - l_fMin) + l_fMin; vector<CMaterial*>::const_iterator l_itMaterial = l_vMaterials.begin(); while(l_itMaterial != l_vMaterials.end()) { (*l_itMaterial)->SetGlowIntensity(l_fGlowIntensity); ++l_itMaterial; } if(l_pDamage) { if(l_fHP < l_fMaxHP) { float l_fDamageAlpha = 1.0f - (l_fHP/l_fMaxHP); l_fDamageAlpha = l_fDamageAlpha + abs(l_fDamageAlpha*0.8f*sinf(5.0f*m_fBloodTime)); if(l_fDamageAlpha > 1.0f) { l_fDamageAlpha = 1.0f; } l_pRenderer->ActivateRenderPath("damage_gui"); l_pDamage->SetAlpha(l_fDamageAlpha); }else{ l_pRenderer->DeactivateRenderPath("damage_gui"); } } if(m_fBloodFadeOutTime > 0.0f) { l_pBlood->SetAlpha(m_fBloodFadeOutTime/(float)BLOOD_FADEOUT_TIME); l_pRenderer->ActivateRenderPath("blood_gui"); m_fBloodFadeOutTime -= _fDeltaTime; }else{ l_pRenderer->DeactivateRenderPath("blood_gui"); m_fBloodFadeOutTime = 0.0f; } m_fBloodTime += _fDeltaTime; CPostSceneRendererStep* l_pShockWave = l_pRenderer->GetPostSceneRendererStep("shock_wave"); if(m_fForceTime < 3.f) { m_fForceTime += _fDeltaTime; l_pShockWave->SetTime(m_fForceTime*SHOCK_WAVE_VELOCITY); if(m_fForceTime > 3.0f) { l_pRenderer->DeactivateRenderPath("shock_wave"); } } if(l_fHP > 0.0f && l_fHP < l_fMaxHP) { float l_fDamageVolume = 1.0f - (l_fHP/l_fMaxHP); if(l_fDamageVolume > 1.0f) { l_fDamageVolume = 1.0f; } if(l_fDamageVolume < 0.0f) { l_fDamageVolume = 0.0f; } SOUND_MANAGER->PlaySample("heart_beat"); SOUND_MANAGER->SetSampleVolume("heart_beat",l_fDamageVolume); }else{ SOUND_MANAGER->StopSample("heart_beat"); } }
bool wxFont::IsFixedWidth() const { wxCHECK_MSG( IsOk(), false, wxT("invalid font") ); return wxFontBase::IsFixedWidth(); }
wxFontEncoding wxFont::GetEncoding() const { wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); return M_FONTDATA->GetEncoding(); }
int wxFont::GetPointSize() const { wxCHECK_MSG( IsOk(), 0, wxT("invalid font") ); return M_FONTDATA->m_nativeFontInfo.GetPointSize(); }
bool wxFont::IsFixedWidth() const { wxCHECK_MSG( IsOk(), false, wxT("invalid font") ); return M_FONTDATA->IsFixedWidth(); }
wxFontStyle wxFont::GetStyle() const { wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX, wxT("invalid font") ); return M_FONTDATA->m_style; }
void wxOverlayImpl::Clear(wxWindowDC* dc) { wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") ); CGRect box = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 ); CGContextClearRect( m_overlayContext, box ); }
bool wxFont::GetUnderlined() const { wxCHECK_MSG( IsOk(), false, wxT("invalid font") ); return M_FONTDATA->m_nativeFontInfo.GetUnderlined(); }
bool wxLocale::Init(int language, int flags) { #if WXWIN_COMPATIBILITY_2_8 wxASSERT_MSG( !(flags & wxLOCALE_CONV_ENCODING), wxS("wxLOCALE_CONV_ENCODING is no longer supported, add charset to your catalogs") ); #endif bool ret = true; int lang = language; if (lang == wxLANGUAGE_DEFAULT) { // auto detect the language lang = GetSystemLanguage(); } // We failed to detect system language, so we will use English: if (lang == wxLANGUAGE_UNKNOWN) { return false; } const wxLanguageInfo *info = GetLanguageInfo(lang); // Unknown language: if (info == NULL) { wxLogError(wxS("Unknown language %i."), lang); return false; } wxString name = info->Description; wxString canonical = info->CanonicalName; wxString locale; // Set the locale: #if defined(__OS2__) const char *retloc = wxSetlocale(LC_ALL , wxEmptyString); #elif defined(__UNIX__) && !defined(__WXMAC__) if (language != wxLANGUAGE_DEFAULT) locale = info->CanonicalName; const char *retloc = wxSetlocaleTryUTF8(LC_ALL, locale); const wxString langOnly = ExtractLang(locale); if ( !retloc ) { // Some C libraries don't like xx_YY form and require xx only retloc = wxSetlocaleTryUTF8(LC_ALL, langOnly); } #if wxUSE_FONTMAP // some systems (e.g. FreeBSD and HP-UX) don't have xx_YY aliases but // require the full xx_YY.encoding form, so try using UTF-8 because this is // the only thing we can do generically // // TODO: add encodings applicable to each language to the lang DB and try // them all in turn here if ( !retloc ) { const wxChar **names = wxFontMapperBase::GetAllEncodingNames(wxFONTENCODING_UTF8); while ( *names ) { retloc = wxSetlocale(LC_ALL, locale + wxS('.') + *names++); if ( retloc ) break; } } #endif // wxUSE_FONTMAP if ( !retloc ) { // Some C libraries (namely glibc) still use old ISO 639, // so will translate the abbrev for them wxString localeAlt; if ( langOnly == wxS("he") ) localeAlt = wxS("iw") + ExtractNotLang(locale); else if ( langOnly == wxS("id") ) localeAlt = wxS("in") + ExtractNotLang(locale); else if ( langOnly == wxS("yi") ) localeAlt = wxS("ji") + ExtractNotLang(locale); else if ( langOnly == wxS("nb") ) localeAlt = wxS("no_NO"); else if ( langOnly == wxS("nn") ) localeAlt = wxS("no_NY"); if ( !localeAlt.empty() ) { retloc = wxSetlocaleTryUTF8(LC_ALL, localeAlt); if ( !retloc ) retloc = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(localeAlt)); } } if ( !retloc ) ret = false; #ifdef __AIX__ // at least in AIX 5.2 libc is buggy and the string returned from // setlocale(LC_ALL) can't be passed back to it because it returns 6 // strings (one for each locale category), i.e. for C locale we get back // "C C C C C C" // // this contradicts IBM own docs but this is not of much help, so just work // around it in the crudest possible manner char* p = const_cast<char*>(wxStrchr(retloc, ' ')); if ( p ) *p = '\0'; #endif // __AIX__ #elif defined(__WIN32__) const char *retloc = "C"; if ( language != wxLANGUAGE_DEFAULT ) { if ( info->WinLang == 0 ) { wxLogWarning(wxS("Locale '%s' not supported by OS."), name.c_str()); // retloc already set to "C" } else // language supported by Windows { // Windows CE doesn't have SetThreadLocale() and there doesn't seem // to be any equivalent #ifndef __WXWINCE__ const wxUint32 lcid = info->GetLCID(); // change locale used by Windows functions ::SetThreadLocale(lcid); #endif // and also call setlocale() to change locale used by the CRT locale = info->GetLocaleName(); if ( locale.empty() ) { ret = false; } else // have a valid locale { retloc = wxSetlocale(LC_ALL, locale); } } } else // language == wxLANGUAGE_DEFAULT { retloc = wxSetlocale(LC_ALL, wxEmptyString); } #if wxUSE_UNICODE && (defined(__VISUALC__) || defined(__MINGW32__)) // VC++ setlocale() (also used by Mingw) can't set locale to languages that // can only be written using Unicode, therefore wxSetlocale() call fails // for such languages but we don't want to report it as an error -- so that // at least message catalogs can be used. if ( !retloc ) { if ( wxGetANSICodePageForLocale(LOCALE_USER_DEFAULT).empty() ) { // we set the locale to a Unicode-only language, don't treat the // inability of CRT to use it as an error retloc = "C"; } } #endif // CRT not handling Unicode-only languages if ( !retloc ) ret = false; #elif defined(__WXMAC__) if (lang == wxLANGUAGE_DEFAULT) locale = wxEmptyString; else locale = info->CanonicalName; const char *retloc = wxSetlocale(LC_ALL, locale); if ( !retloc ) { // Some C libraries don't like xx_YY form and require xx only retloc = wxSetlocale(LC_ALL, ExtractLang(locale)); } #else wxUnusedVar(flags); return false; #define WX_NO_LOCALE_SUPPORT #endif #ifndef WX_NO_LOCALE_SUPPORT if ( !ret ) { wxLogWarning(_("Cannot set locale to language \"%s\"."), name.c_str()); // continue nevertheless and try to load at least the translations for // this language } if ( !DoInit(name, canonical, retloc) ) { ret = false; } if (IsOk()) // setlocale() succeeded m_language = lang; // NB: don't use 'lang' here, 'language' wxTranslations *t = wxTranslations::Get(); if ( t ) { t->SetLanguage(static_cast<wxLanguage>(language)); if ( flags & wxLOCALE_LOAD_DEFAULT ) t->AddStdCatalog(); } return ret; #endif // !WX_NO_LOCALE_SUPPORT }
GLTexture::~GLTexture() { if ( IsOk() ) { glDeleteTextures( 1, &m_texture ); } }
wxPenStyle wxPen::GetStyle() const { wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, wxT("invalid pen") ); return M_PENDATA->m_style; }
wxDash* wxPen::GetDash() const { wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") ); return (wxDash*)M_PENDATA->m_dash; }
size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size) { wxASSERT_MSG(m_inflate && m_z_buffer, wxT("Inflate stream not open")); if (!m_inflate || !m_z_buffer) m_lasterror = wxSTREAM_READ_ERROR; if (!IsOk() || !size) return 0; int err = Z_OK; m_inflate->next_out = (unsigned char *)buffer; m_inflate->avail_out = size; #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while (err == Z_OK && m_inflate->avail_out > 0) { if (m_inflate->avail_in == 0 && m_parent_i_stream->IsOk()) { m_parent_i_stream->Read(m_z_buffer, m_z_size); m_inflate->next_in = m_z_buffer; m_inflate->avail_in = m_parent_i_stream->LastRead(); } err = inflate(m_inflate, Z_SYNC_FLUSH); } switch (err) { case Z_OK: break; case Z_STREAM_END: if (m_inflate->avail_out) { // Unread any data taken from past the end of the deflate stream, so that // any additional data can be read from the underlying stream (the crc // in a gzip for example) if (m_inflate->avail_in) { m_parent_i_stream->Reset(); m_parent_i_stream->Ungetch(m_inflate->next_in, m_inflate->avail_in); m_inflate->avail_in = 0; } m_lasterror = wxSTREAM_EOF; } break; case Z_BUF_ERROR: // Indicates that zlib was expecting more data, but the parent stream // has none. Other than Eof the error will have been already reported // by the parent strean, m_lasterror = wxSTREAM_READ_ERROR; if (m_parent_i_stream->Eof()) { wxLogError(_("Can't read inflate stream: unexpected EOF in underlying stream.")); } break; default: wxString msg(m_inflate->msg, *wxConvCurrent); if (!msg) msg = wxString::Format(_("zlib error %d"), err); wxLogError(_("Can't read from inflate stream: %s"), msg.c_str()); m_lasterror = wxSTREAM_READ_ERROR; } size -= m_inflate->avail_out; m_pos += size; return size; }