void Grafik::OnLButtonDown(UINT nFlags, CPoint point) { if (!PtInRect(&drawable, point)) return; int x_hit = scale_point(point.x, drawable_width, value_width); int y_hit = scale_point(point.y, drawable_height, value_height); for (int row = 0; row < DemoData.get_anz_z(); row++) { if (!isSelected(row)) continue; for (int column = von_value; column < bis_value; column++) { int x = scale_point(column, value_width, drawable_width); int y = scale_point(DemoData.get_wert(row, column), value_height, drawable_height); CRect hit; hit.SetRect(x - 2 * 5, y - 2 * 5, x + 2 * 5, y + 2 * 5); if (PtInRect(&hit, point)) //CPoint(x, y))) { highlighted[row] = !highlighted[row]; } } } RedrawWindow(); CDialog::OnLButtonDown(nFlags, point); }
// _InsertPoint void PathManipulator::_InsertPoint(BPoint where, int32 index) { double scale; BPoint point; BPoint pointIn; BPoint pointOut; BPoint previous; BPoint previousOut; BPoint next; BPoint nextIn; if (fPath->FindBezierScale(index - 1, where, &scale) && scale >= 0.0 && scale <= 1.0 && fPath->GetPoint(index - 1, scale, point)) { fPath->GetPointAt(index - 1, previous); fPath->GetPointOutAt(index - 1, previousOut); fPath->GetPointAt(index, next); fPath->GetPointInAt(index, nextIn); where = scale_point(previousOut, nextIn, scale); previousOut = scale_point(previous, previousOut, scale); nextIn = scale_point(next, nextIn, 1 - scale); pointIn = scale_point(previousOut, where, scale); pointOut = scale_point(nextIn, where, 1 - scale); if (fPath->AddPoint(point, index)) { fPath->SetPointIn(index, pointIn); fPath->SetPointOut(index, pointOut); delete fInsertPointCommand; fInsertPointCommand = new InsertPointCommand(fPath, index, fSelection->Items(), fSelection->CountItems()); fPath->SetPointOut(index - 1, previousOut); fPath->SetPointIn(index + 1, nextIn); fCurrentPathPoint = index; _ShiftSelection(fCurrentPathPoint, 1); _Select(fCurrentPathPoint, fShiftDown); } } }
void SoftwareRendererImp::rasterize_triangle( float x0, float y0, float x1, float y1, float x2, float y2, Color color ) { //modify task 2: scale up the point location: /* x0 = 100.0 + 000.0; y0 = 000.0; x1 = 100.0 + 000.0; y1 = 100.0; x2 = 100.0 + 100.0; y2 = 100.0; */ //printf("Color: (%f, %f, %f, %f)\n", color.r, color.g, color.b, color.a); scale_point(x0, y0, sample_rate); scale_point(x1, y1, sample_rate); scale_point(x2, y2, sample_rate); // Task 2: // Implement triangle rasterization // Method 1: use bounding box, does not consider "edge rule" if (!cclock(x0, y0, x1, y1, x2, y2)) { //printf("before swap: (%f, %f, %f, %f)", x0, y0, x1, y1); swapPoints(x1, y1, x2, y2); //printf("after swap: (%f, %f, %f, %f)", x0, y0, x1, y1); } float lowX, highX, lowY, highY; lowX = (floor(min(min(x0, x1), x2))) + 0.5; lowY = (floor(min(min(y0, y1), y2))) + 0.5; highX = (ceil(max(max(x0, x1), x2))) - 0.5; highY = (ceil(max(max(y0, y1), y2))) - 0.5; for ( float x = lowX; x <= highX; x += 1 ) { for (float y = lowY; y <= highY; y += 1 ) { if (lineSide(x, y, x0, y0, x1, y1) && lineSide(x, y, x1, y1, x2, y2) && lineSide(x, y, x2, y2, x0, y0)) { rasterize_point(x, y, color); } } } }
void Grafik::OnLButtonDblClk(UINT nFlags, CPoint point) { if (!PtInRect(&drawable, point)) return; int x_hit = scale_point(point.x, drawable_width, value_width); int y_hit = scale_point(point.y, drawable_height, value_height); for (int row = 0; row < DemoData.get_anz_z(); row++) { if (!isSelected(row)) continue; for (int column = von_value; column < bis_value; column++) { int x = scale_point(column, value_width, drawable_width); int y = scale_point(DemoData.get_wert(row, column), value_height, drawable_height); CRect hit; hit.SetRect(x - 2 * 5, y - 2 * 5, x + 2 * 5, y + 2 * 5); if (PtInRect(&hit, point)) //CPoint(x, y))) { //Auswahl -> Datenreihe //TODO: Get this to work EinDaten ed; ed.auswahl = row; ed.nummer = column; ed.wert = DemoData.get_wert(y_hit, x_hit); if (ed.DoModal())// == IDOK) { RedrawWindow(); } } } } CDialog::OnLButtonDblClk(nFlags, point); }
void SoftwareRendererImp::rasterize_line( float x0, float y0, float x1, float y1, Color color) { // Task 1: // Implement line rasterization scale_point(x0, y0, sample_rate); scale_point(x1, y1, sample_rate); if (x0 > x1) { swapPoints(x0, y0, x1, y1); } int sx0 = (int) floor(x0); int sy0 = (int) floor(y0); int sx1 = (int) floor(x1); int sy1 = (int) floor(y1); float k; if (sx1 == sx0) { int low = min(sy0, sy1); int high = max(sy0, sy1); for ( int y = low; y <= high; y++ ) { SoftwareRendererImp::rasterize_point((float) x0, (float) y, color); } } else { k = (y1 - y0)/(x1 - x0); //fitst positive oct if (0.0 <= k && k <= 1.0) { int dx = sx1 - sx0, dy = sy1 - sy0, y = sy0, eps = 0; for ( int x = sx0; x <= sx1; x++ ) { SoftwareRendererImp::rasterize_point((float) x, (float) y, color); eps += dy; if ( (eps << 1) >= dx ) { y++; eps -= dx; } } } //second positive oct if (k > 1.0 && sx1 != sx0) { int dx = sx1 - sx0, dy = sy1 - sy0, x = sx0, eps = 0; for ( int y = sy0; y <= sy1; y++ ) { SoftwareRendererImp::rasterize_point((float) x, (float) y, color); eps += dx; if ( (eps << 1) >= dy ) { x++; eps -= dy; } } } if (k <= -1.0) { int dx = sx1 - sx0, dy = sy1 - sy0, x = sx0, eps = 0; for ( int y = sy0; y >= sy1; y-- ) { SoftwareRendererImp::rasterize_point((float) x, (float) y, color); eps -= dx; if ( (eps << 1) <= dy ) { x++; eps -= dy; } } } if (-1.0 <= k && k <= 0.0) { int dx = sx1 - sx0, dy = sy1 - sy0, y = sy0, eps = 0; for ( int x = sx0; x <= sx1; x++ ) { SoftwareRendererImp::rasterize_point((float) x, (float) y, color); eps += dy; if ( (eps << 1) <= -dx ) { y--; eps += dx; } } } } }
int svg_plot(config *cfg, plot_info *pi, data_set *ds) { svg_theme *theme = cfg->svg_theme; svg_printf_header(pi->w, pi->h); svg_printf_frame(pi->w, pi->h, theme->bg_color, theme->border_width, theme->border_color); if (cfg->axis) { draw_calc_axis_pos(pi); svg_printf_axis(pi, theme); } transform_t transform = scale_get_transform(pi->log_x, pi->log_y); for (uint8_t c = 0; c < ds->columns; c++) { char *color = get_color(c, theme); point *column = ds->pairs[c]; if (cfg->mode == MODE_LINE) { bool beginning_line = true; for (size_t i = 0; i < ds->rows; i++) { point *p = &column[i]; if (IS_EMPTY(p->x) || IS_EMPTY(p->y)) { if (!beginning_line) { svg_printf_end_polyline(color, theme->line_width); } beginning_line = true; continue; } if (beginning_line) { svg_printf_begin_polyline(); beginning_line = false; } scaled_point sp; scale_point(pi, p, &sp, transform); svg_printf_polyline_point(sp.x, sp.y); } svg_printf_end_polyline(color, theme->line_width); } else { for (size_t i = 0; i < ds->rows; i++) { point *p = &column[i]; scaled_point sp; scale_point(pi, p, &sp, transform); if (IS_EMPTY(p->x) || IS_EMPTY(p->y)) { continue; } size_t point_size = SVG_DEF_POINT_SIZE; if (pi->counters) { size_t count = counter_get(pi->counters[c], sp.x, sp.y); point_size = SVG_DEF_POINT_SIZE + (cfg->log_count ? log(count) : count); } svg_printf_circle(sp.x, sp.y, point_size, color); } } if (cfg->regression) { double slope = 0; double intercept = 0; regression(column, ds->rows, transform, &slope, &intercept); svg_printf_regression_line(pi, color, slope, intercept); } } svg_printf_end(); return 0; }
void Grafik::OnPaint() { CPaintDC dc(this); dc.FillRect(&drawable, &stdbrush.white); dc.FrameRect(&drawable, &stdbrush.black); int min_value = INT_MAX; int max_value = INT_MIN; for (int i = 0; i < DemoData.get_anz_z(); i++) { if (DemoData.minimum(i) < min_value) min_value = DemoData.minimum(i); if (DemoData.maximum(i) > max_value) max_value = DemoData.maximum(i); } drawable_height = CSize(drawable.bottom, drawable.top); value_height = CSize(min_value, max_value); drawable_width = CSize(drawable.left, drawable.right); value_width = CSize(0, (bis_value - von_value - 1)); dc.SelectObject(&stdpen.gray1); for (int column = von_value + 1; column < bis_value; column++) { int x = scale_point(column, value_width, drawable_width); dc.MoveTo(x, drawable.bottom); dc.LineTo(x, drawable.top); } dc.SelectObject(&stdpen.black7); //For highlighting for (int row = 0; row < DemoData.get_anz_z(); row++) { if (!isSelected(row)) continue; if (!highlighted[row]) continue; int x = scale_point(von_value, value_width, drawable_width); int y = scale_point(DemoData.get_wert(row, von_value), value_height, drawable_height); dc.MoveTo(x, y); for (int column = von_value + 1; column < bis_value; column++) { int x = scale_point(column, value_width, drawable_width); int y = scale_point(DemoData.get_wert(row, column), value_height, drawable_height); dc.LineTo(x, y); } } for (int row = 0; row < DemoData.get_anz_z(); row++) { if (!isSelected(row)) continue; dc.SelectObject(&stdpen.pen[row]); int x = scale_point(von_value, value_width, drawable_width); int y = scale_point(DemoData.get_wert(row, von_value), value_height, drawable_height); dc.MoveTo(x, y); for (int column = von_value + 1; column < bis_value; column++) { int x = scale_point(column, value_width, drawable_width); int y = scale_point(DemoData.get_wert(row, column), value_height, drawable_height); dc.LineTo(x, y); //Infobox if (highlighted[row]) { CRect infobox; infobox.SetRect(x, y, 0, 0); CString text; text.Format(CString("%d"), DemoData.get_wert(row, column)); dc.DrawText(text, &infobox, DT_CALCRECT); infobox.OffsetRect(0, -infobox.Height()); infobox.right += 6; dc.FillRect(infobox, &stdbrush.yellow); dc.DrawText(text, &infobox, DT_CENTER | DT_SINGLELINE | DT_VCENTER); dc.FrameRect(infobox, &stdbrush.black); } } } }
static void * ucb1x00tsEventThread( DirectThread *thread, void *driver_data ) { ucb1x00TSData *data = (ucb1x00TSData*) driver_data; TS_EVENT ts_event; int readlen; unsigned short old_x = -1; unsigned short old_y = -1; unsigned short old_pressure = 0; while ((readlen = read(data->fd, &ts_event, sizeof(TS_EVENT))) > 0 || errno == EINTR) { DFBInputEvent evt; direct_thread_testcancel( thread ); if (readlen < 1) continue; filter_event( &ts_event ); scale_point( &ts_event ); ts_event.pressure = (ts_event.pressure > config.zthresh ); if (ts_event.pressure) { if (ts_event.x != old_x) { evt.type = DIET_AXISMOTION; evt.flags = DIEF_AXISABS; evt.axis = DIAI_X; evt.axisabs = ts_event.x; dfb_input_dispatch( data->device, &evt ); old_x = ts_event.x; } if (ts_event.y != old_y) { evt.type = DIET_AXISMOTION; evt.flags = DIEF_AXISABS; evt.axis = DIAI_Y; evt.axisabs = ts_event.y; dfb_input_dispatch( data->device, &evt ); old_y = ts_event.y; } } if ((ts_event.pressure && !old_pressure) || (!ts_event.pressure && old_pressure)) { evt.type = (ts_event.pressure ? DIET_BUTTONPRESS : DIET_BUTTONRELEASE); evt.flags = DIEF_NONE; evt.button = DIBI_LEFT; dfb_input_dispatch( data->device, &evt ); old_pressure = ts_event.pressure; } } if (readlen <= 0) D_PERROR ("ucb1x00 Touchscreen thread died\n"); return NULL; }