AMInt32 _AMBitBltEx(AMGraphics dst, AMRect* rect, AMGraphics src, AMPoint* point, AMDrawMode drawMode) { AMGraphics_* gdst = (AMGraphics_* )dst; AMGraphics_* gsrc = (AMGraphics_* )src; CHECK_PARG_AND_RET(gdst); CHECK_PARG_AND_RET(gsrc); CHECK_PARG_AND_RET(rect); CHECK_PARG_AND_RET(point); /* if(BitBlt(gdst->hdc, rect->x, rect->y, rect->w, rect->h, gsrc->hdc, point->x, point->y, _ParseDrawMode(drawMode)) == NULL) { DWORD err_code = GetLastError(); return AME_GRAPHICS_ERROR; } */ for(int x = 0; x < rect->w; x++) { for(int y = 0; y < rect->h; y++) { COLORREF corSrc = GetPixel(gsrc->hdc, point->x + x, point->y + y); COLORREF corDst = GetPixel(gdst->hdc, rect->x + x, rect->y + y); AMUInt8 alphaSrc = ARGB_GETALPHA(corSrc); AMUInt8 alphadst = ARGB_GETALPHA(corDst); AMUInt8 rS = ARGB_GETRED(corSrc); AMUInt8 gS = ARGB_GETGREEN(corSrc); AMUInt8 bS = ARGB_GETBLUE(corSrc); AMUInt8 rd= ARGB_GETRED(corDst); AMUInt8 gd = ARGB_GETGREEN(corDst); AMUInt8 bd = ARGB_GETBLUE(corDst); AMUInt8 r = (AMUInt8)(((rS * alphaSrc) + (rd * (255-alphaSrc)))/255); AMUInt8 g = (AMUInt8)(((gS * alphaSrc) + (gd * (255-alphaSrc)))/255); AMUInt8 b = (AMUInt8)(((bS * alphaSrc) + (bd * (255-alphaSrc)))/255); COLORREF uiNewColor = alphadst << 24 |b <<16| g<<8 | r ; SetPixel(gsrc->hdc, rect->x + x, rect->y + y, uiNewColor); } } if(BitBlt(gdst->hdc, rect->x, rect->y, rect->w, rect->h, gsrc->hdc, point->x, point->y, _ParseDrawMode(drawMode)) == NULL) { DWORD err_code = GetLastError(); return AME_GRAPHICS_ERROR; } return AME_GRAPHICS_SUCCESS; }
AMInt32 _AMSetBrushColor(AMGraphics graphics) { AMGraphics_* g = (AMGraphics_* )graphics; CHECK_PARG_AND_RET(graphics); #if 0 if(g->isSetBackColor == FALSE) { HBRUSH hBrush = CreateSolidBrush(g->color); HBRUSH oldBrush = (HBRUSH)SelectObject(g->hdc, hBrush); if(g->isSetPen == FALSE) { g->brush = oldBrush; g->isSetBrush = TRUE; } else DeleteObject(oldBrush); g->isSetBackColor = TRUE; } #else HBRUSH hBrush = CreateSolidBrush(g->bgColor); int errorno = GetLastError(); HBRUSH oldBrush = (HBRUSH)SelectObject(g->hdc, hBrush); if(g->isSetPen == FALSE) { g->brush = oldBrush; g->isSetBrush = TRUE; } else DeleteObject(oldBrush); #endif return AME_GRAPHICS_SUCCESS; }
AMInt32 _AMSetForeColor(AMGraphics graphics) { AMGraphics_* g = (AMGraphics_* )graphics; CHECK_PARG_AND_RET(graphics); #if 0 if(g->isSetForeColor == FALSE) { HPEN hPen = _CreatePen(g->color); HPEN oldhPen = (HPEN)SelectObject(g->hdc, hPen); if(g->isSetPen == FALSE) { g->pen = oldhPen; g->isSetPen = TRUE; } else DeleteObject(oldhPen); g->isSetForeColor = TRUE; } #else HPEN hPen = _CreatePen(g->fgColor); HPEN oldhPen = (HPEN)SelectObject(g->hdc, hPen); if(g->isSetPen == FALSE) { g->pen = oldhPen; g->isSetPen = TRUE; } else DeleteObject(oldhPen); #endif return AME_GRAPHICS_SUCCESS; }
AMInt32 AMThreadMutexUnlock (AMThreadMutex * mutex) { AMInt32 err_code = 0; CHECK_PARG_AND_RET(mutex); err_code = pthread_mutex_unlock((pthread_mutex_t*)*mutex); CHECK_EQUAL_AND_RETV(0, err_code, AME_MUTEX_SCUESS); return AME_MUTEX_ERROR; }
AMInt32 AMFontDestroy(AMFont font) { AMFont_* pfont = (AMFont_*)font; CHECK_PARG_AND_RET(pfont); free(pfont); pfont = NULL; return AME_FONT_SUCCESS; }
AMInt32 AMCharHeight(AMFont font) { AMFont_* pfont = (AMFont_*)font; CHECK_PARG_AND_RET(pfont); TEXTMETRIC textMetric; GetTextMetrics(pfont->hdc, &textMetric); return textMetric.tmHeight; }
AMInt32 AMThreadMutexLock (AMThreadMutex * mutex) { //AMLogForDebug("AMThread", __func__); AMInt32 err_code = 0; CHECK_PARG_AND_RET(mutex); err_code = pthread_mutex_lock((pthread_mutex_t*)*mutex); CHECK_EQUAL_AND_RETV(0,err_code, AME_MUTEX_SCUESS); CHECK_EQUAL_AND_RETV(EBUSY,err_code, AME_MUTEX_BUSY); return AME_MUTEX_ERROR; }
AMInt32 AMThreadMutexDestroy (AMThreadMutex * mutex) { AMInt32 err_code = 0; CHECK_PARG_AND_RET(mutex); err_code = pthread_mutex_destroy((pthread_mutex_t*)*mutex); CHECK_EQUAL_AND_RETV(EBUSY,err_code, AME_MUTEX_BUSY); CHECK_EQUAL_AND_RETV(EINVAL,err_code, AME_MUTEX_ERROR); // 成功, 则释放空间 free(*mutex); return AME_MUTEX_SCUESS; }
AMInt32 _AMSetTextColor(AMGraphics graphics) { AMGraphics_* g = (AMGraphics_* )graphics; CHECK_PARG_AND_RET(graphics); #if 0 if(g->isSetTextColor == FALSE) { SetTextColor(g->hdc, g->color); g->isSetTextColor = TRUE; } #else SetTextColor(g->hdc, g->fgColor); #endif return AME_GRAPHICS_SUCCESS; }
AMInt32 AMThreadMutexCreate (AMThreadMutex * mutex) { AMInt32 err_code = 0; pthread_mutexattr_t pattr; CHECK_PARG_AND_RET(mutex); *mutex = (AMPVoid)malloc(sizeof(pthread_mutex_t)); CHECK_AND_RETV(*mutex, AME_MALLOC_ERROR); pthread_mutexattr_init(&pattr); pthread_mutexattr_settype(&pattr, PTHREAD_MUTEX_RECURSIVE_NP); err_code = pthread_mutex_init((pthread_mutex_t*)*mutex, &pattr); pthread_mutexattr_destroy(&pattr); CHECK_EQUAL_AND_RETV(0,err_code, AME_MUTEX_SCUESS); free(*mutex); return AME_MUTEX_ERROR; }
AMInt32 AMCharsWidth(AMFont font, const AMWChar* text, AMInt32 length) { AMFont_* pfont = (AMFont_*)font; CHECK_PARG_AND_RET(pfont); SIZE size = { 0}; if(GetTextExtentPoint(pfont->hdc, (WCHAR*)text, length, &size) == 0) { int errorCode = GetLastError(); return AME_FONT_ERROR; } #if 0 if(wcscmp(text, L"UI Demo")==0) { length = length; } printf("���ו�ם¶�: \"%S", text); printf("\" = [%d, %d]\n", size.cx, size.cy); #endif return size.cx; }
AMInt32 AMCreateSystemFont(AMFont* pFont, AMFontFace face, AMFontStyle style, AMFontSize size) { CHECK_PARG_AND_RET(pFont); AMFont_* f = (AMFont_*)malloc(sizeof(AMFont_)); CHECK_PARG_AND_RETV(f, AME_MALLOC_ERROR); memset(f, 0 , sizeof(AMFont_)); f->hdc = GetDC(NULL); f->size = size; f->style = style; f->face = face; EnumFontFamilies(f->hdc, NULL, _FontCreateSystemFontEnumFontFamProc, (LPARAM)f); if(NULL == f->hfont) { free(f); return AME_FONT_ERROR; } *pFont = f; return AME_FONT_SUCCESS; }
AMInt32 AMFontCreate(AMFont* pFont) { CHECK_PARG_AND_RET(pFont); AMFont_* f = (AMFont_*)malloc(sizeof(AMFont_)); CHECK_PARG_AND_RETV(f, AME_MALLOC_ERROR); memset(f, 0 , sizeof(AMFont_)); f->style = AMFONT_STYLE_ERROR; f->size = AMFONT_SIZE_MEDIUM; f->face = AMFONT_FACE_SYSTEM; f->hdc = GetDC(NULL); EnumFontFamilies(f->hdc, NULL, _FontCreateEnumFontFamProc, (LPARAM)f); if(NULL == f->hfont) { free(f); return AME_FONT_ERROR; } *pFont = f; return AME_FONT_SUCCESS; }