static int SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; unsigned inva = 0xff - a; switch (fmt->BytesPerPixel) { case 4: switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_RGBA); break; } return 0; default: return SDL_Unsupported(); } }
static void rtgui_dc_buffer_fill_rect(struct rtgui_dc *self, struct rtgui_rect *dst_rect) { struct rtgui_dc_buffer *dst; unsigned r, g, b, a; rtgui_rect_t _r, *rect; RT_ASSERT(self); if (dst_rect == RT_NULL) rtgui_dc_get_rect(self, &_r); else _r = *dst_rect; dst = (struct rtgui_dc_buffer *)self; if (_r.x2 < 0 || _r.y2 < 0) return; /* out of rect */ /* parameter checking */ if (_r.x1 >= dst->width) return; else if (_r.x1 < 0) _r.x1 = 0; if (_r.x2 > dst->width) _r.x2 = dst->width; if (_r.y1 >= dst->height) return; else if (_r.y1 < 0) _r.y1 = 0; if (_r.y2 > dst->height) _r.y2 = dst->height; rect = &_r; r = RTGUI_RGB_R(dst->gc.background); g = RTGUI_RGB_G(dst->gc.background); b = RTGUI_RGB_B(dst->gc.background); a = RTGUI_RGB_A(dst->gc.background); switch (dst->pixel_format) { case RTGRAPHIC_PIXEL_FORMAT_RGB565: FILLRECT(rt_uint16_t, DRAW_SETPIXEL_RGB565); break; case RTGRAPHIC_PIXEL_FORMAT_BGR565: FILLRECT(rt_uint16_t, DRAW_SETPIXEL_BGR565); break; case RTGRAPHIC_PIXEL_FORMAT_RGB888: FILLRECT(rt_uint32_t, DRAW_SETPIXEL_RGB888); break; case RTGRAPHIC_PIXEL_FORMAT_ARGB888: FILLRECT(rt_uint32_t, DRAW_SETPIXEL_ARGB8888); break; } }
static int SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888); break; } return 0; }
static void rtgui_dc_buffer_fill_rect(struct rtgui_dc *self, struct rtgui_rect *dst_rect) { struct rtgui_dc_buffer *dst; unsigned r, g, b, a; rtgui_rect_t _r, *rect; dst = (struct rtgui_dc_buffer *)self; _r = *dst_rect; /* parameter checking */ if (_r.x1 > dst->width) _r.x1 = dst->width; if (_r.x2 > dst->width) _r.x2 = dst->width; if (_r.y1 > dst->height) _r.y1 = dst->height; if (_r.y2 > dst->height) _r.y2 = dst->height; rect = &_r; r = RTGUI_RGB_R(dst->gc.foreground); g = RTGUI_RGB_G(dst->gc.foreground); b = RTGUI_RGB_B(dst->gc.foreground); a = RTGUI_RGB_A(dst->gc.foreground); switch (dst->pixel_format) { case RTGRAPHIC_PIXEL_FORMAT_RGB565: FILLRECT(rt_uint16_t, DRAW_SETPIXEL_RGB565); break; case RTGRAPHIC_PIXEL_FORMAT_BGR565: FILLRECT(rt_uint16_t, DRAW_SETPIXEL_BGR565); break; case RTGRAPHIC_PIXEL_FORMAT_RGB888: FILLRECT(rt_uint16_t, DRAW_SETPIXEL_RGB888); break; case RTGRAPHIC_PIXEL_FORMAT_ARGB888: FILLRECT(rt_uint16_t, DRAW_SETPIXEL_ARGB8888); break; } }
TANY PEXPORT KpiUpdateRectLight(OBJECTID idSelf, LPSTR ap) { WORD wType = OBJECT_TYPE(idSelf); ATOMID idWidget = KppGetItemName(wType, idSelf); ATOMID idValue = va_far_arg(ap, ATOMID); short sXL, sHeight = 0; WORD wMaxWidth, wTextHeight, wRectWidth, wTitleHgt; ATOMID idOwner, idOwnerSlot, idItem, idDesc; LISTID idPossValues; WORD wNumPossValues; HBRUSH hRedBrush, hWhiteBrush, hOldBrush; RECT rect; HFONT hOldFont; short sBkMode; DWORD dwTextColor; HDC hDC; HWND hWnd; TANY res; res.type = T_CBOOL; res.data.cbool = FALSE; KppGetAtomInt(Kpp_Get_SlotValue(wType, idSelf, lpSNs->idWinIdSN), (int *) &hWnd); if (!hWnd) return res; hDC = GetDC(hWnd); if (!hDC) return res; idOwner = Kpp_Get_SlotValue(wType, idSelf, lpSNs->idOwnerSN); idOwnerSlot = Kpp_Get_SlotValue(wType, idSelf, lpSNs->idOwnerSlotSN); idDesc = Kpp_Get_SlotValue(wType, idSelf, lpSNs->idTitleSN); if (!idOwner || !idOwnerSlot || !idDesc) { ReleaseDC(hWnd, hDC); return res; } if (idOwner == lpIDs->idNull || idOwnerSlot == lpIDs->idNull) { idPossValues = Kpp_Get_SlotListValue(wType, idSelf, lpSNs->idPossValuesSN); if (!idPossValues) { ReleaseDC(hWnd, hDC); return res; } } else { /* Get the current values from owner */ if (!idValue || idValue == lpIDs->idNull) idValue = KppGetSlotValue(idOwner, idOwnerSlot); idPossValues = KppGetOption(idOwner, idOwnerSlot, OPT_PV); if (!idPossValues || idPossValues == lpIDs->idNull) idPossValues = Kpp_Get_SlotListValue(wType, idSelf, lpSNs->idPossValuesSN); if (!idValue) { ReleaseDC(hWnd, hDC); return res; } } /* Determine the maximum width of a string in possible values */ wNumPossValues = KppListLen(idPossValues); if (!wNumPossValues) { ReleaseDC(hWnd, hDC); return res; } /* Determine scaling parameters */ hOldFont = KpsSetWidgetFont(idWidget, hDC, FALSE, 1.0); wMaxWidth = DetRStringWidths(hDC, idPossValues, idDesc, &wRectWidth, &wTextHeight); SetupRLightMapping(hWnd, hDC, wMaxWidth, wTextHeight, wNumPossValues); sXL = (short) ((double) wRectWidth / 2.0); if (idDesc != lpIDs->idNull) { SelectObject(hDC, hOldFont); hOldFont = KpsSetWidgetFont(idWidget, hDC, TRUE, 1.0); KppGetAtomName(idDesc, (LPSTR) pBuffer, 50); wTitleHgt = HIWORD(GetTextExtent(hDC, (LPSTR) pBuffer, strlen(pBuffer))); sHeight = HALF_VERT_PAD + wTitleHgt; if (hOldFont) SelectObject(hDC, hOldFont); } hOldFont = KpsSetWidgetFont(idWidget, hDC, FALSE, 1.0); sHeight += (VERT_PAD + HALF_VERT_PAD); sBkMode = GetBkMode(hDC); hRedBrush = CreateSolidBrush(RGB(255, 0, 0)); hWhiteBrush = KpsSetWidgetText2Color(idWidget, hDC, (HBRUSH) NULL); dwTextColor = GetTextColor(hDC); hOldBrush = SelectObject(hDC, hWhiteBrush); if (idPossValues && idPossValues != lpIDs->idNull) { LIST_LOOP loop; kpc_init_loop(idPossValues, &loop); while (idItem = KppNextListElement(&loop)) { WORD wLen = KppGetAtomName(idItem, pBuffer, 32); sHeight += (VERT_PAD + wTextHeight); SelectObject(hDC, hWhiteBrush); ECHO_ROUNDRECT(hDC, sXL, sHeight, wTextHeight); if (idValue == idItem) { SelectObject(hDC, hRedBrush); SetTextColor(hDC, RGB(255, 255, 255)); } else { SelectObject(hDC, hWhiteBrush); SetTextColor(hDC, dwTextColor); } DRAW_ROUNDRECT(hDC, sXL, sHeight, wTextHeight); FILLRECT(rect, -sXL, sHeight, sXL, sHeight - wTextHeight); SetBkMode(hDC, TRANSPARENT); DrawText(hDC, pBuffer, wLen, &rect, DT_CENTER); SetBkMode(hDC, OPAQUE); sHeight += VERT_PAD; } } Kpp_Set_SlotValue(wType, idSelf, lpSNs->idValueSN, idValue, EXPATOM); SetBkMode(hDC, sBkMode); SelectObject(hDC, hOldFont); SelectObject(hDC, hOldBrush); DeleteObject(hRedBrush); SetTextColor(hDC, BLACK); ReleaseDC(hWnd, hDC); res.data.cbool = TRUE; return res; }
TANY PEXPORT KpiDrawRectLight(OBJECTID idSelf, LPSTR ap) { WORD wType = OBJECT_TYPE(idSelf); ATOMID idWidget = va_far_arg(ap, ATOMID); short sXL, sHeight = 0; char *Context = "Context"; ATOMID idOwner = Kpp_Get_SlotValue(wType, idSelf, lpSNs->idOwnerSN); ATOMID idOwnerSlot = Kpp_Get_SlotValue(wType, idSelf, lpSNs->idOwnerSlotSN); WORD wMaxWidth, wTextHeight, wTitleHgt; BOOL bOwnerValues = FALSE; short sBkMode; HDC hDC; HWND hWnd; ATOMID idDesc, idValue = NULLID, idItem; LISTID idPossValues; WORD wNumPossValues, wRectWidth; RECT rect; HBRUSH hRedBrush, hWhiteBrush, hOldBrush; HFONT hOldFont; DWORD dwTextColor; TANY res; res.type = T_CBOOL; res.data.cbool = FALSE; KppGetAtomInt(Kpp_Get_SlotValue(wType, idSelf, lpSNs->idWinIdSN), (int *) &hWnd); if (!hWnd) return res; hDC = GetProp(hWnd, Context); if (!hDC) hDC = GetDC(hWnd); if (idOwner != lpIDs->idNull && idOwnerSlot != lpIDs->idNull) { idValue = KppGetSlotValue(idOwner, idOwnerSlot); idPossValues = KppGetOption(idOwner, idOwnerSlot, OPT_PV); wNumPossValues = KppListLen(idPossValues); if (wNumPossValues > 0) bOwnerValues = TRUE; } if (!bOwnerValues) { idPossValues = Kpp_Get_SlotListValue(wType, idSelf, lpSNs->idPossValuesSN); wNumPossValues = KppListLen(idPossValues); } if (!idValue || idValue == lpIDs->idNull) idValue = Kpp_Get_SlotValue(wType, idSelf, lpSNs->idValueSN); if (wNumPossValues <= 0) { if (!GetProp(hWnd, Context)) ReleaseDC(hWnd, hDC); return res; } idDesc = Kpp_Get_SlotValue(wType, idSelf, lpSNs->idTitleSN); SetTextColor(hDC, BLACK); hOldFont = KpsSetWidgetFont(idWidget, hDC, FALSE, 1.0); wMaxWidth = DetRStringWidths(hDC, idPossValues, idDesc, &wRectWidth, &wTextHeight); SetupRLightMapping(hWnd, hDC, wMaxWidth, wTextHeight, wNumPossValues); sXL = (short) ((double) wMaxWidth / 2.0); if (hOldFont) SelectObject(hDC, hOldFont); if (idDesc != lpIDs->idNull) { WORD wLen = KppGetAtomName(idDesc, pBuffer, 50); HBRUSH hBrBack = KpsSetWidgetTextColor(idWidget, hDC, NULL); DWORD dwExtent; hOldFont = KpsSetWidgetFont(idWidget, hDC, TRUE, 1.0); SetBkMode(hDC, TRANSPARENT); dwExtent = GetTextExtent(hDC, pBuffer, wLen); wMaxWidth = LOWORD(dwExtent); wTitleHgt = HIWORD(dwExtent); sXL = (short) ((double) wMaxWidth / 2.0); sHeight = HALF_VERT_PAD + wTitleHgt; FILLRECT(rect, -sXL, sHeight, sXL, sHeight - wTitleHgt); DrawText(hDC, pBuffer, wLen, &rect, DT_CENTER); if (hOldFont) { SelectObject(hDC, hOldFont); hOldFont = NULL; } DeleteObject(hBrBack); SetTextColor(hDC, BLACK); } hOldFont = KpsSetWidgetFont(idWidget, hDC, FALSE, 1.0); sXL = (short) ((double) wRectWidth / 2.0); sHeight += (VERT_PAD + HALF_VERT_PAD); /* Prepare fonts && brushes */ sBkMode = GetBkMode(hDC); hRedBrush = CreateSolidBrush(RGB(255, 0, 0)); hWhiteBrush = KpsSetWidgetText2Color(idWidget, hDC, NULL); dwTextColor = GetTextColor(hDC); hOldBrush = SelectObject(hDC, hWhiteBrush); /* Begin looping && draw possible values */ if (idPossValues && idPossValues != lpIDs->idNull) { LIST_LOOP loop; kpc_init_loop(idPossValues, &loop); while (idItem = KppNextListElement(&loop)) { WORD wLen = KppGetAtomName(idItem, pBuffer, 32); sHeight += (VERT_PAD + wTextHeight); SelectObject(hDC, hWhiteBrush); ECHO_ROUNDRECT(hDC, sXL, sHeight, wTextHeight); if (idValue == idItem) { SelectObject(hDC, hRedBrush); SetTextColor(hDC, RGB(255, 255, 255)); } else { SelectObject(hDC, hWhiteBrush); SetTextColor(hDC, dwTextColor); } DRAW_ROUNDRECT(hDC, sXL, sHeight, wTextHeight); FILLRECT(rect, -sXL, sHeight, sXL, sHeight - wTextHeight); SetBkMode(hDC, TRANSPARENT); DrawText(hDC, pBuffer, wLen, &rect, DT_CENTER); SetBkMode(hDC, OPAQUE); sHeight += VERT_PAD; } } Kpp_Set_SlotValue(wType, idSelf, lpSNs->idValueSN, idValue, EXPATOM); /* Restore the fonts && brushes */ SetBkMode(hDC, sBkMode); SelectObject(hDC, hOldFont); SelectObject(hDC, hOldBrush); DeleteObject(hRedBrush); SetTextColor(hDC, dwTextColor); if (!GetProp(hWnd, Context)) ReleaseDC(hWnd, hDC); res.data.cbool = TRUE; return res; }