/* ddraw_vline: * Accelerated vline routine. */ static void ddraw_vline(BITMAP *bmp, int x, int y1, int y2, int color) { struct Ph_rect dest_rect; struct BITMAP *parent; if (_drawing_mode != DRAW_MODE_SOLID) { _orig_vline(bmp, x, y1, y2, color); return; } if (y1 > y2) { int tmp = y1; y1 = y2; y2 = tmp; } if (bmp->clip) { if ((x < bmp->cl) || (x >= bmp->cr)) return; if (y1 < bmp->ct) y1 = bmp->ct; if (y2 >= bmp->cb) y2 = bmp->cb-1; if (y2 < y1) return; } dest_rect.ul.x = x + bmp->x_ofs; dest_rect.ul.y = y1 + bmp->y_ofs; dest_rect.lr.x = x + bmp->x_ofs; dest_rect.lr.y = y2 + bmp->y_ofs; /* find parent */ parent = bmp; while (parent->id & BMP_ID_SUB) parent = (BITMAP *)parent->extra; PhDCSetCurrent(BMP_EXTRA(parent)->context); PgDrawLine(&dest_rect.ul, &dest_rect.lr); if (parent == pseudo_screen) ph_update_window(&dest_rect); else PgFlush(); }
/* ddraw_hline: * Accelerated scanline fill routine. */ static void ddraw_hline(BITMAP *bmp, int x1, int y, int x2, int color) { struct Ph_rect dest_rect; struct BITMAP *parent; if (_drawing_mode != DRAW_MODE_SOLID) { _orig_hline(bmp, x1, y, x2, color); return; } if (x1 > x2) { int tmp = x1; x1 = x2; x2 = tmp; } if (bmp->clip) { if ((y < bmp->ct) || (y >= bmp->cb)) return; if (x1 < bmp->cl) x1 = bmp->cl; if (x2 >= bmp->cr) x2 = bmp->cr-1; if (x2 < x1) return; } dest_rect.ul.x = x1 + bmp->x_ofs; dest_rect.ul.y = y + bmp->y_ofs; dest_rect.lr.x = x2 + bmp->x_ofs; dest_rect.lr.y = y + bmp->y_ofs; /* find parent */ parent = bmp; while (parent->id & BMP_ID_SUB) parent = (BITMAP *)parent->extra; PhDCSetCurrent(BMP_EXTRA(parent)->context); PgDrawLine(&dest_rect.ul, &dest_rect.lr); if (parent == pseudo_screen) ph_update_window(&dest_rect); else PgFlush(); }
static void scale_draw_vertical( PtWidget_t *widget ) { PtScaleWidget_t *sb = ( PtScaleWidget_t * ) widget; PhRect_t rect; PhPoint_t from; PhPoint_t to; PhPoint_t text_loc; PhPoint_t from2; PhPoint_t to2; short seg_offset = 0; short old_seg_offset; short height; short height2; short text_x_offset; int i; int j; int length1, length2; int text_flags; // Get the size of our canvas PtBasicWidgetCanvas( widget, &rect ); // Set our text colors now (won't change) PgSetStrokeColor( sb->major_ticks_color ); PgSetFont( sb->font ); PgSetTextColor( sb->major_ticks_color ); // Change setting if drawing in reverse if( sb->scale_flags & Pt_SCALE_REVERSE ) { from = rect.lr; to.x = rect.lr.x; to.y = rect.ul.y; if( sb->scale_flags & Pt_SCALE_LABEL ) { text_flags = Pg_TEXT_LEFT; text_x_offset = 0; } else { text_flags = Pg_TEXT_RIGHT; text_x_offset = -5; } } else { from.x = rect.ul.x; from.y = rect.lr.y; to = rect.ul; if( sb->scale_flags & Pt_SCALE_LABEL ) { text_flags = Pg_TEXT_RIGHT; text_x_offset = 0; } else { text_flags = Pg_TEXT_LEFT; text_x_offset = 5; } } // Draw major line, if required. if( sb->scale_flags & Pt_SCALE_DRAW_TOP_LINE ) { PgDrawLine( &from, &to ); } // Set the lenght of major/minor ticks once (use - to reverse draw direction) length1 = sb->major_ticks_length; length2 = sb->minor_ticks_length; if( sb->scale_flags & Pt_SCALE_REVERSE ) { length1 = -length1; length2 = -length2; } // Calculate the total height of the scale and constant drawing positions height = rect.lr.y - rect.ul.y; to.x = to.x + length1; // Loop, drawing major ticsk from BOTTOM to TOP for( i = 0; i < ( sb->major_ticks_division + 1 ); i++ ) { // calculate Y position of line and draw it (X remains constants) from.y = rect.lr.y - seg_offset; to.y = from.y; PgDrawLine( &from, &to ); // Draw labels, if one exist for this tick if( sb->labels[i] != NULL ) { text_loc.x = to.x + text_x_offset; text_loc.y = to.y; if( sb->scale_flags & Pt_SCALE_LABEL ) { if( sb->scale_flags & Pt_SCALE_REVERSE ) { text_loc.x = rect.ul.x; } else { text_loc.x = rect.lr.x; } } // Draw text, making sure limits are drawn within the container. if( i == 0 ) { PgDrawText( sb->labels[i], strlen( sb->labels[i]), &text_loc, text_flags | Pg_TEXT_BOTTOM ); } else if( i == sb->major_ticks_division ) { PgDrawText( sb->labels[i], strlen( sb->labels[i]), &text_loc, text_flags | Pg_TEXT_TOP ); } else { PgDrawText( sb->labels[i], strlen( sb->labels[i]), &text_loc, text_flags | Pg_TEXT_MIDDLE ); } } // Needed for later calcs, so we do it now old_seg_offset = seg_offset; seg_offset = ( ( i + 1) * height ) / (sb->major_ticks_division ? sb->major_ticks_division : 1); // Now do minor ticks, if required if( sb->minor_ticks_division > 0) { height2 = seg_offset - old_seg_offset; from2 = from; // Don't overwrite the top line, inc the y a bit. This // should incremented by the width of the line eventually. if( sb->scale_flags & Pt_SCALE_REVERSE ) { from2.x--; } else { from2.x++; } to2.x = from2.x + length2; // Don't need to overlap the major tick, so we loop for the // internal tick marks only. for( j = 1; j < sb->minor_ticks_division; j++ ) { from2.y = from.y + ( j * height2 ) / sb->minor_ticks_division; to2.y = from2.y; PgSetStrokeColor( sb->minor_ticks_color ); PgDrawLine( &from2, &to2 ); } // Reset stroke color to major (optimization) PgSetStrokeColor( sb->major_ticks_color ); } } }
static void scale_draw_horizontal( PtWidget_t *widget ) { PtScaleWidget_t *sb = ( PtScaleWidget_t * ) widget; PhRect_t rect; PhPoint_t from; PhPoint_t to; PhPoint_t from2; PhPoint_t to2; PhPoint_t text_loc; short seg_offset; short old_seg_offset; short width; short width2; int i; int j; int length1, length2; int text_flags; PtBasicWidgetCanvas( widget, &rect ); // Set our text colors now (won't change) PgSetFont( sb->font ); PgSetTextColor( sb->major_ticks_color ); PgSetStrokeColor( sb->major_ticks_color ); if( sb->scale_flags & Pt_SCALE_REVERSE ) { from.x = rect.ul.x; from.y = rect.lr.y; to = rect.lr; if( sb->scale_flags & Pt_SCALE_LABEL ) { text_flags = Pg_TEXT_TOP; } else { text_flags = Pg_TEXT_BOTTOM; } } else { from = rect.ul; to.y = rect.ul.y; to.x = rect.lr.x; if( sb->scale_flags & Pt_SCALE_LABEL ) { text_flags = Pg_TEXT_BOTTOM; } else { text_flags = Pg_TEXT_TOP; } } if( sb->scale_flags & Pt_SCALE_DRAW_TOP_LINE ) { PgDrawLine( &from, &to ); } length1 = sb->major_ticks_length; length2 = sb->minor_ticks_length; if( sb->scale_flags & Pt_SCALE_REVERSE ) { length1 = -length1; length2 = -length2; } width = rect.lr.x - rect.ul.x; to.y = to.y + length1; seg_offset = 0; for( i = 0; i < ( sb->major_ticks_division + 1 ); i++ ) { // calculate X position of line from.x = rect.ul.x + seg_offset; to.x = from.x; PgDrawLine( &from, &to ); // Draw labels, if one exist for this tick if( sb->labels[i] != NULL ) { text_loc = to; if( sb->scale_flags & Pt_SCALE_LABEL ) { if( sb->scale_flags & Pt_SCALE_REVERSE ) { text_loc.y = rect.ul.y; } else { text_loc.y = rect.lr.y; } } // Draw text, making sure limits are drawn within the container. if( i == 0 ) { PgDrawText( sb->labels[i], strlen( sb->labels[i]), &text_loc, text_flags | Pg_TEXT_LEFT ); } else if( i == sb->major_ticks_division ) { PgDrawText( sb->labels[i], strlen( sb->labels[i]), &text_loc, text_flags | Pg_TEXT_RIGHT ); } else { PgDrawText( sb->labels[i], strlen( sb->labels[i]), &text_loc, text_flags | Pg_TEXT_CENTER ); } } // Needed for later calcs, so do it now old_seg_offset = seg_offset; seg_offset = ( ( i + 1) * width ) / ( sb->major_ticks_division ? sb->major_ticks_division : 1 ); // Do minor ticks, if required if( sb->minor_ticks_division > 0) { width2 = seg_offset - old_seg_offset; from2 = from; // Don't overwrite the top line, inc the y a bit. This // should incremented by the line with eventually. if( sb->scale_flags & Pt_SCALE_REVERSE ) { from2.y--; } else { from2.y++; } to2.y = from2.y + length2; for( j = 1; j < sb->minor_ticks_division; j++ ) { from2.x = from.x + ( j * width2 ) / sb->minor_ticks_division; to2.x = from2.x; PgSetStrokeColor( sb->minor_ticks_color ); PgDrawLine( &from2, &to2 ); } // Reset stroke color to major (optimization) PgSetStrokeColor( sb->major_ticks_color ); } } }