📄 pw_draw.c
字号:
{ IPW_TRACE_EXIT(DR3); return; } reg = reg->next; } } else { /* Universal line */ Pw_uInt c1, c2; /* * Check each rectangle in clip region - if our * line intersect one of them, than draw the * visible part */ while (PW_NULL != reg) { IPW_TRACE_RECT(DR3, ®->area); /* * Calc the line position according * to the current clip region rectangle */ c1 = IPw_RectOutCode(®->area, x1, y1); c2 = IPw_RectOutCode(®->area, x2, y2); IPW_TRACE2(DR3, d, c1, c2); if ((c1 == 0) && (c2 == 0)) { /* Line is inside current clip rectangle */ _DrawLine(gc, x1, y1, x2, y2); IPW_TRACE_EXIT(DR3); return; } else if ((c1 & c2) == 0) { /* Line intersects current clip rectangle */ _DrawClipLine(gc, x1, y1, x2, y2, ®->area); } reg = reg->next; } } IPW_TRACE_EXIT(DR3);}/** * Draws a circle. * @param gc pointer to graphic context * @param x circle center x coord * @param y circle center y coord * @param r circle radius * @todo use faster functions * @see Pw_FillCircle */void Pw_DrawCircle(Pw_GC* gc, Pw_Coord x, Pw_Coord y, Pw_Coord r) { IPW_TRACE_ENTER(DR3); Pw_DrawEllipse(gc, x, y, r, r); IPW_TRACE_EXIT(DR3);}/** * Draws a filled circle. * @param gc pointer to graphic context * @param x circle center x coord * @param y circle center y coord * @param r circle radius * @todo use faster functions * @see Pw_DrawCircle */void Pw_FillCircle(Pw_GC* gc, Pw_Coord x, Pw_Coord y, Pw_Coord r) { IPW_TRACE_ENTER(DR3); Pw_FillEllipse(gc, x, y, r, r); IPW_TRACE_EXIT(DR3);}/** * Draws an ellipse. * @param gc pointer to graphic context * @param x ellipse center x coord * @param y ellipse center y coord * @param rx ellipse x radius * @param ry ellipse y radius * @see Pw_FillEllipse * @see Pw_DrawCircle * @see Pw_FillCircle */void Pw_DrawEllipse(Pw_GC* gc, Pw_Coord x, Pw_Coord y, Pw_Coord rx, Pw_Coord ry){ Pw_Rectangle r, rc; Pw_Region* reg; IPW_TRACE_ENTER(DR3); IPW_CHECK_PTR(gc); IPW_CHECK_GC(gc); IPW_TRACE4(DR3, d, x, y, rx, ry); /* Correct the ellipse position according to graphic context origin */ x += gc->xoff; y += gc->yoff; IPW_TRACE2(DR3, d, x, y); /* Calculate the ellipse bounding box */ r.x = x - rx; r.y = y - ry; r.w = rx * 2 + 1; r.h = ry * 2 + 1; IPW_TRACE_RECT2(DR3, &r, &gc->clip_reg.bounds); /* * Check if the ellipse bounding box intersects * the clip region bounding box */ if (!IPW_RECT_IS_OVER(&r, &gc->clip_reg.bounds)) { IPW_TRACE_EXIT(DR3); return; } /* * Check each rectangle in clip region - if our * ellipse intersect one of them, than draw the * visible part */ reg = gc->clip_reg.regs; while (PW_NULL != reg) { IPW_TRACE_RECT(DR3, ®->area); /* Make a copy of ellipse bounding box */ IPW_RECT_COPY(&rc, &r); /* * Intersect the ellipse bounding box with current * clip region rectangle */ if (IPw_RectIntersect(&rc, ®->area)) { IPW_TRACE_RECT(DR3, &rc); if (IPW_RECT_IS_EQUAL(&r, &rc)) { /* Ellipse fully visible */ _DrawEllipse(gc, x, y, rx, ry, FALSE); IPW_TRACE_EXIT(DR3); return; } else { /* Ellipse partially visible (draw with clipping) */ _DrawClipEllipse(gc, x, y, rx, ry, FALSE, &rc); } } reg = reg->next; } IPW_TRACE_EXIT(DR3);}/** * Draws a filled ellipse. * @param gc pointer to graphic context * @param x ellipse center x coord * @param y ellipse center y coord * @param rx ellipse x radius * @param ry ellipse y radius * @see Pw_DrawEllipse * @see Pw_DrawCircle * @see Pw_FillCircle */void Pw_FillEllipse(Pw_GC* gc, Pw_Coord x, Pw_Coord y, Pw_Coord rx, Pw_Coord ry){ Pw_Rectangle r, rc; Pw_Region* reg; IPW_TRACE_ENTER(DR3); IPW_CHECK_PTR(gc); IPW_CHECK_GC(gc); IPW_TRACE4(DR3, d, x, y, rx, ry); /* Correct the ellipse position according to graphic context origin */ x += gc->xoff; y += gc->yoff; IPW_TRACE2(DR3, d, x, y); /* Calculate the ellipse bounding box */ r.x = x - rx; r.y = y - ry; r.w = rx * 2 + 1; r.h = ry * 2 + 1; IPW_TRACE_RECT2(DR3, &r, &gc->clip_reg.bounds); /* * Check if the ellipse bounding box intersects * the clip region bounding box */ if (!IPW_RECT_IS_OVER(&r, &gc->clip_reg.bounds)) { IPW_TRACE_EXIT(DR3); return; } /* * Check each rectangle in clip region - if our * ellipse intersect one of them, than draw the * visible part */ reg = gc->clip_reg.regs; while (PW_NULL != reg) { IPW_TRACE_RECT(DR3, ®->area); /* Make a copy of ellipse bounding box */ IPW_RECT_COPY(&rc, &r); /* * Intersect the ellipse bounding box with current * clip region rectangle */ if (IPw_RectIntersect(&rc, ®->area)) { IPW_TRACE_RECT(DR3, &rc); if (IPW_RECT_IS_EQUAL(&r, &rc)) { /* Ellipse fully visible */ _DrawEllipse(gc, x, y, rx, ry, TRUE); IPW_TRACE_EXIT(DR3); return; } else { /* Ellipse partially visible (draw with clipping) */ _DrawClipEllipse(gc, x, y, rx, ry, TRUE, &rc); } } reg = reg->next; } IPW_TRACE_EXIT(DR3);}/** * Draws a bitmap. * @param gc pointer to graphic context * @param x x coord of bitmap top left corner * @param y y coord of bitmap top left corner * @param bitmap pointer to bitmap */void Pw_DrawBitmap(Pw_GC* gc, Pw_Coord x, Pw_Coord y, Pw_Bitmap* bitmap){ Pw_Rectangle r, rc; Pw_Region* reg; IPW_TRACE_ENTER(DR3);// IPW_CHECK_PTR(gc);// IPW_CHECK_PTR(bitmap);// IPW_CHECK_BITMAP(bitmap); //IPW_CHECK_GC(gc); IPW_TRACE2(DR3, d, x, y); /* Correct the bitmap position according to clip region bounds */ r.x = x + gc->xoff; r.y = y + gc->yoff; r.w = bitmap->width; r.h = bitmap->height; IPW_TRACE_RECT2(DR3, &r, &gc->clip_reg.bounds); /* * Check if the bitmap bounding box intersects clip * region bounding box */ if (!IPW_RECT_IS_OVER(&r, &gc->clip_reg.bounds)) { IPW_TRACE_EXIT(DR3); return; } /* * Check each rectangle in clip region - if our * bitmap intersect one of them, than draw the * visible part */ reg = gc->clip_reg.regs; while (PW_NULL != reg) { IPW_TRACE_RECT(DR3, ®->area); /* Make a copy of bitmap bounding box */ IPW_RECT_COPY(&rc, &r); /* Intersect bitmap's bounds with current clip region rectangle */ if (IPw_RectIntersect(&rc, ®->area)) { IPW_TRACE_RECT(DR3, &rc); if (IPW_RECT_IS_EQUAL(&rc, &r)) { /* Bitmap fully visible */ _DrawBitmap(gc, r.x, r.y, r.w, r.h, bitmap->bits); IPW_TRACE_EXIT(DR3); return; } else { /* Bitmap partially visible - draw with clipping */ _DrawClipBitmap(gc, r.x, r.y, r.w, r.h, bitmap->bits, &rc); } } reg = reg->next; } IPW_TRACE_EXIT(DR3);} /** * Draws a string. * @param gc pointer to graphic context * @param x x coord of string box top left corner * @param y y coord of string box left corner * @param string string to be drawn */void Pw_DrawString(Pw_GC* gc, Pw_Coord x, Pw_Coord y, Pw_Char* string){ Pw_Rectangle r, rc; Pw_Coord rx; Pw_FontCharInfo* cinfo; Pw_Region* reg; IPW_TRACE_ENTER(DR3);// IPW_CHECK_PTR2(gc, string);// IPW_CHECK_GC(gc); IPW_TRACE3M(DR3, d, x, d, y, s, string); if (gc->font == PW_NULL) { IPW_ASSERT(FALSE, ("GC font is NULL")); return; } /* * Correct the string position according to graphic context origin * and calculate its bounding box */ r.x = x + gc->xoff; r.y = y + gc->yoff - gc->font->ascent; r.w = Pw_GCGetStringWidth(gc, string); r.h = gc->font->ascent + gc->font->descent; IPW_TRACE_RECT2(DR3, &r, &gc->clip_reg.bounds); /* * If the string bounding box does not intersect clip region * bounding box return */ if (!IPW_RECT_IS_OVER(&r, &gc->clip_reg.bounds)) { IPW_TRACE_EXIT(DR3); return; } /* * Check if the whole string fits in one clip rectangle and * draw all charachters without clipping */ reg = gc->clip_reg.regs; while (PW_NULL != reg) { IPW_TRACE_RECT(DR3, ®->area); /* Make a copy of string bounding box */ IPW_RECT_COPY(&rc, &r); /* Intersect string's bounds with current clip region rectangle */ if (IPw_RectIntersect(&rc, ®->area)) { IPW_TRACE_RECT(DR3, &rc); if (IPW_RECT_IS_EQUAL(&rc, &r)) { /* * The whole string fits in this clip rectangle - * draw all charachters without clipping */ rx = x + gc->xoff; while (*string != '\0'){ /* Get font info for current charachter */ if ((Pw_Byte)*string < gc->font->chars_num) cinfo = &gc->font->info[(Pw_Byte)*string]; else cinfo = &gc->font->info[0]; /* Draw current charachter bitmap */ _DrawBitmap(gc, rx + cinfo->bbx, y + gc->yoff - (cinfo->bby + cinfo->bbh), cinfo->bbw, cinfo->bbh, &gc->font->bits[cinfo->bits_offset]); rx += cinfo->dwx; string++; } IPW_TRACE_EXIT(DR3); return; } } reg = reg->next; } /* * The whole string didn't fit in one clip rectangle - we have to * clip and draw charachter by charachter */ rx = x + gc->xoff; while (*string != '\0') { /* Get font info for current charachter */ if ((Pw_Byte)*string < gc->font->chars_num) cinfo = &gc->font->info[(Pw_Byte)*string]; else cinfo = &gc->font->info[0]; IPW_TRACE1(DR3, c, *string); /* Set the current charachter bounding box */ r.x = rx + cinfo->bbx; r.y = y + gc->yoff - (cinfo->bby + cinfo->bbh); r.w = cinfo->bbw; r.h = cinfo->bbh; IPW_TRACE1(DR3, d, rx); IPW_TRACE_RECT2(DR3, &r, &gc->clip_reg.bounds); /* * If the charachter bounding box intersect clip region * bounding box then try to draw it */ if (IPW_RECT_IS_OVER(&r, &gc->clip_reg.bounds)) { reg = gc->clip_reg.regs; /* Try to draw the current charachter inside clip region */ while (PW_NULL != reg){ IPW_TRACE_RECT(DR3, ®->area); /* Make a copy of charachter bounding box */ IPW_RECT_COPY(&rc, &r); /* * Intersect charachter's bounds with * current clip region rectangle */ if (IPw_RectIntersect(&rc, ®->area)) { IPW_TRACE_RECT(DR3, &rc); if (IPW_RECT_IS_EQUAL(&rc, &r)) { /* Charachter fully visible */ _DrawBitmap(gc, r.x, r.y, r.w, r.h, &gc->font->bits[cinfo->bits_offset]); break; } else { /* Charachter partially visible - draw with clipping */ _DrawClipBitmap(gc, r.x, r.y, r.w, r.h, &gc->font->bits[cinfo->bits_offset], &rc); } } reg = reg->next; } } rx += cinfo->dwx; string++; } IPW_TRACE_EXIT(DR3);}
void Pw_DrawFrameRect(Pw_GC* gc, Pw_Coord x, Pw_Coord y, int w, int h, int t, Pw_Char* Title) {
int xt, yt, wt;
wt = Pw_FontGetStringWidth(gc->font, Title);
yt = Pw_GCGetFontHeight(gc);
// Pw_GCSetColor(gc, pw_black_pixel);
// Pw_FillRect(gc, x, y, w, h);
Pw_GCSetColor(gc, pw_white_pixel);
if (Title)
Pw_FillRect(gc, x, y+yt/2, w, h-yt/2);
else
Pw_FillRect(gc, x, y, w, h);
Pw_GCSetColor(gc, pw_black_pixel);
if (Title)
// Pw_FillRect(gc, x+t, y+yt/2+t, w-2*t-1, h-2*t-yt/2);
Pw_FillRect(gc, x+t, y+yt/2+t, w-2*t, h-2*t-yt/2);
else
Pw_FillRect(gc, x+t, y+t, w-2*t, h-2*t);
if (Title) {
xt = x + (w - wt)/2;
Pw_FillRect(gc, xt - 10, y, wt + 20, y + yt);
Pw_GCSetColor(gc, pw_white_pixel);
Pw_DrawString(gc, xt, y+yt, Title);
}}
void Pw_DrawGrayTextBackgr(Pw_GC *gc, int x, int y , int w, int h) {
unsigned char mask;
int i, j, xt;
x += gc->xoff; y += (gc->yoff);// + Pw_GCGetFontDescent(gc));
w = (w + 7) >> 3;
Pw_GCSetColor(gc, pw_white_pixel);
for (i = 0; i <= h; i++) {
if (i & 0x0001) mask = 0x00AA;
else mask = 0x0055;
xt = x;
for (j = 0; j < w; j++) {
gc->d.lld->draw_points (gc, xt, y, mask);
xt += 8;
}
y++;
}
} /*---------------------------------------------------------------------------// end of pw_draw.c //--------------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -