Ejemplo n.º 1
0
void PaintSquare(Canvas *c, uint8_t layer, uint8_t color, uint8_t fill, VGF_Square *square) {
  if ((square->x_start >= c->x_size) || (square->y_start >= c->y_size)) {
    return;
  }
  if (square->x_start + square->x_len >= c->x_size) {
    return;
  }
  if (square->y_start + square->x_len >= c->y_size) {
    return;
  }

  if (square->x_len == 0) {
    return;
  }

  ConnectPoints(c, layer, color, square->x_start, square->y_start, square->x_start, square->y_start + square->x_len);
  ConnectPoints(c, layer, color, square->x_start, square->y_start + square->x_len, square->x_start + square->x_len, square->y_start + square->x_len);
  ConnectPoints(c, layer, color, square->x_start + square->x_len, square->y_start, square->x_start + square->x_len, square->y_start + square->x_len);
  ConnectPoints(c, layer, color, square->x_start, square->y_start, square->x_start + square->x_len, square->y_start );

  // Fill if necessary
  if ((fill == 1) && (square->x_len > 1)) {
    for (uint16_t y_position = 1; y_position < square->x_len; y_position++) {
      ConnectPoints(c, layer, color, square->x_start + 1, square->y_start + y_position, square->x_start + square->x_len - 1, square->y_start + y_position);
    }
  }

}
Ejemplo n.º 2
0
void PaintRectangle(Canvas *c, uint8_t layer, uint8_t color, uint8_t fill, VGF_Rectangle *rectangle) {
  if ((rectangle->x_start >= c->x_size) || (rectangle->y_start >= c->y_size)) {
    return;
  }
  if (rectangle->x_start + rectangle->x_len >= c->x_size) {
    return;
  }
  if (rectangle->y_start + rectangle->y_len >= c->y_size) {
    return;
  }

  if (rectangle->x_len == 0 && rectangle->y_len == 0) {
    return;
  }

  ConnectPoints(c, layer, color, rectangle->x_start, rectangle->y_start, rectangle->x_start, rectangle->y_start + rectangle->y_len);
  ConnectPoints(c, layer, color, rectangle->x_start, rectangle->y_start + rectangle->y_len, rectangle->x_start + rectangle->x_len, rectangle->y_start + rectangle->y_len);
  ConnectPoints(c, layer, color, rectangle->x_start + rectangle->x_len, rectangle->y_start, rectangle->x_start + rectangle->x_len, rectangle->y_start + rectangle->y_len);
  ConnectPoints(c, layer, color, rectangle->x_start, rectangle->y_start, rectangle->x_start + rectangle->x_len, rectangle->y_start );

  // Fill if necessary
  if ((fill == 1) && (rectangle->x_len > 1)) {
    for (uint16_t y_position = 1; y_position < rectangle->y_len; y_position++) {
      ConnectPoints(c, layer, color, rectangle->x_start + 1, rectangle->y_start + y_position, rectangle->x_start + rectangle->x_len - 1, rectangle->y_start + y_position);
    }
  }

}
Ejemplo n.º 3
0
void PaintLine(Canvas *c, uint8_t layer, uint8_t color, uint8_t fill, VGF_Line *line) {
  if ((line->x_start >= c->x_size) || (line->x_start > line->x_end)) {
    return;
  }
  if ((line->y_start >= c->y_size) || (line->y_start > line->y_end)) {
    return;
  }
  if ((line->y_end >= c->y_size) || (line->x_end >= c->x_size)) {
    return;
  }
  ConnectPoints(c, layer, color, line->x_start, line->y_start, line->x_end, line->y_end);
}
Ejemplo n.º 4
0
LRESULT CMFC_DEMOView::OnWTPacket(WPARAM wSerial, LPARAM hCtx)
{
	// Read the packet
	PACKET pkt;
	gpWTPacket( (HCTX)hCtx, wSerial, &pkt );

	// Process packets in order, one at a time
	CSingleLock lock( pWTMutex, TRUE );

	CDC *pDC = GetDC();
	
	// Get window size
	RECT window_rect;
	GetWindowRect( &window_rect );
	POINT size;
	size.x = window_rect.right - window_rect.left;
	size.y = window_rect.bottom - window_rect.top;

	// Erase the old cursor
	if( csr.x >= 0 ) {
		CRgn r;
		r.CreateRectRgn( csr.x - 2, csr.y - 2, csr.x + 2, csr.y + 2 );
		pDC->InvertRgn( &r );
	}

	csr.x = (size.x * pkt.pkX) / lc.lcInExtX;
	csr.y = size.y - (size.y * pkt.pkY) / lc.lcInExtY;

	if( pkt.pkButtons ) {
		
		CMFC_DEMODoc *pDoc = GetDocument();
		list<point> * lst = pDoc->GetLst();

		if( prev_pkButtons ) {
			
			list<point>::iterator i = lst->end();
			i--;
			pDC->MoveTo(abs(i->x),abs(i->y));

			lst->push_back(csr);
			pDC->LineTo(csr);


		/*********************  Write something below  ********************/

			
				new_time = clock();		//	some problems...
				
				SetSerial();

				
				int x = csr.x - DISPLAY_OFFSET_X;
				int y = csr.y - DISPLAY_OFFSET_Y;

				if(start == 1 && (double)(new_time - old_time) / CLOCKS_PER_SEC > 2) {
					WacomTrace("Time diff: %f\n", (double)(new_time - old_time) / CLOCKS_PER_SEC);
					start = 0;
					ConnectPoints();
					if((double)(new_time - old_time) / CLOCKS_PER_SEC > 4) {
						Output();
						Reset();
					} else {
						Set(x, y);
					}
				} else {
					if(start == 0 || (double)(new_time - old_time) / CLOCKS_PER_SEC > 0.15) {
					WacomTrace("Time diff: %f\n", (double)(new_time - old_time) / CLOCKS_PER_SEC);
						Set(x, y);
					}
					start = 1;
				}
				old_time = new_time;


				
		/*********************  Write something above  ********************/
			
		} else {
			
			POINT pt;
			pt.x = -csr.x;
			pt.y = -csr.y;
			lst->push_back(pt);
			

		}
		
	}

	prev_pkButtons = pkt.pkButtons;

	// Draw a new cursor
	CRgn r;
	r.CreateRectRgn( csr.x - 2, csr.y - 2, csr.x + 2, csr.y + 2 );
	pDC->InvertRgn( &r );

	ReleaseDC( pDC );

	return TRUE;
}
Ejemplo n.º 5
0
void PaintTriangle(Canvas *c, uint8_t layer, uint8_t color, uint8_t fill, VGF_Triangle *triangle) {
  if (triangle->x0 >= c->x_size || triangle->x1 >= c->x_size || triangle->x2 >= c->x_size) {
    return;
  }
  if (triangle->y0 >= c->y_size || triangle->y1 >= c->y_size || triangle->y2 >= c->y_size) {
    return;
  }

  if (fill == 0) {
    // Draw outline
    ConnectPoints(c, layer, color, triangle->x0, triangle->y0, triangle->x1, triangle->y1);
    ConnectPoints(c, layer, color, triangle->x2, triangle->y2, triangle->x0, triangle->y0);
    ConnectPoints(c, layer, color, triangle->x1, triangle->y1, triangle->x2, triangle->y2);
  } else {
    // Fill triangle
    // Sort points top to bottom
    uint16_t *x0, *y0, *x1, *y1, *x2, *y2;

    if (triangle->y0 > triangle->y1) {
      x0 = &triangle->x1;
      y0 = &triangle->y1;
      x1 = &triangle->x0;
      y1 = &triangle->y0;
    } else {
      x0 = &triangle->x0;
      y0 = &triangle->y0;
      x1 = &triangle->x1;
      y1 = &triangle->y1;
    }
    if (*y1 > triangle->y2) {
      x2 = x1;
      y2 = y1;
      if (*y0 > triangle->y2) {
        x1 = x0;
        y1 = y0;
        x0 = &triangle->x2;
        y0 = &triangle->y2;
      }
      else {
        x1 = &triangle->x2;
        y1 = &triangle->y2;
      }
    } else {
      x2 = &triangle->x2;
      y2 = &triangle->y2;
    }

    // ...
    uint32_t last_y, x_low, x_high;
    uint32_t y;

    x_low = *x0;
    x_high = *x0;

    if (*x1 < x_low) {
      x_low = *x1;
    } else if (*x1 > x_high) {
      x_high = *x1;
    } 
    if (*x2 < x_low) {
      x_low = *x2;
    } else if (*x2 > x_high) {
      x_high = *x2;
    }

    // Flat triangle
    if (*y2 == *y0) {
      if (x_high > x_low) {
        ConnectPoints(c, layer, color, x_low, *y0, x_high - 1, *y0);
      }
      return;
    }
   
    if (*y1 == *y2) {
      last_y = *y1;
    } else {
      last_y = *y1 - 1;
    }

    int step_low, step_high;
    step_low = 0;
    step_high = 0;

    if (*y0 == *y1) {
      // Draw base of triangle
      x_low = *x0;
      x_high = *x1;
      if (x_low > x_high) {
        x_high = *x0;
        x_low = *x1;
      }
      if (x_high > x_low) {
        ConnectPoints(c, layer, color, x_low, *y0, x_high - 1, *y0);
      }
      y = *y1;
    } else {
      y = *y0;
      while (y <= last_y) {
        x_high = *x0 + step_high / (*y2 - *y0);
        x_low = *x0 + step_low / (*y1 - *y0);

        step_high += *x2 - *x0;
        step_low += *x1 - *x0;

        if (x_low > x_high) {
          int swap = x_low;
          x_low = x_high;
          x_high = swap;
        }

        if (x_high > x_low) {
          ConnectPoints(c, layer, color, x_low, y, x_high - 1, y);
        }
        y++;
      }
    }

    step_high = (*x2 - *x0) * (y - *y0);
    step_low = (*x2 - *x1) * (y - *y1);

    while (y <= *y2) {
      x_high = *x0 + step_high / (*y2 - *y0);
      x_low = *x1 + step_low / (*y2 - *y1);

      step_high += *x2 - *x0;
      step_low += *x2 - *x1;

      if (x_low > x_high) {
        int swap = x_low;
        x_low = x_high;
        x_high = swap;
      }

      if (x_high > x_low) {
        ConnectPoints(c, layer, color, x_low, y, x_high - 1, y);
      }
      y++;
    }
  } 
}
Ejemplo n.º 6
0
void PaintCircle(Canvas *c, uint8_t layer, uint8_t color, uint8_t fill, VGF_Circle *circle) {

  if ((circle->x_start >= c->x_size) || (circle->y_start >= c->y_size)) {
    return;
  }
  if ((circle->x_start + circle->radius >= c->x_size) ||
    (circle->y_start + circle->radius >= c->y_size)) {
    return;
  }
   if ((circle->x_start - circle->radius < 0) ||
    (circle->y_start - circle->radius < 0)) {
    return;
  }
  int x, y, x_pos, y_pos;
  x = 0;
  y = circle->radius;
  int radius_error = 1 - circle->radius;
  int ddf_x, ddf_y;
  ddf_x = 1;
  ddf_y = -2 * circle->radius;
  x_pos = circle->x_start;
  y_pos = circle->y_start;

  if (fill == 0) {
    SetColor(c, y_pos + circle->radius, x_pos, layer, color);
    SetColor(c, y_pos - circle->radius, x_pos, layer, color);
    SetColor(c, y_pos, x_pos + circle->radius, layer, color);
    SetColor(c, y_pos, x_pos - circle->radius, layer, color);
  } else {
    ConnectPoints(c, layer, color, x_pos, y_pos - y, x_pos, y_pos + y - 1);
  }
  while (x < y) {
    if (radius_error >= 0) {
      y--;
      ddf_y += 2;
      radius_error += ddf_y;
    }
    x++;
    ddf_x += 2;
    radius_error += ddf_x;

    if (fill == 0) {
      // Draw outline
      SetColor(c, y_pos + y, x_pos + x, layer, color);
      SetColor(c, y_pos + y, x_pos - x, layer, color);
      SetColor(c, y_pos - y, x_pos + x, layer, color);
      SetColor(c, y_pos - y, x_pos - x, layer, color);
      
      SetColor(c, y_pos + x, x_pos + y, layer, color);
      SetColor(c, y_pos + x, x_pos - y, layer, color);
      SetColor(c, y_pos - x, x_pos + y, layer, color);
      SetColor(c, y_pos - x, x_pos - y, layer, color);
    } else {
      // Fill circle
      if (y > 0) { 
        ConnectPoints(c, layer, color, x_pos + x, y_pos - y, x_pos + x, y_pos + y - 1);
        ConnectPoints(c, layer, color, x_pos - x, y_pos - y, x_pos - x, y_pos + y - 1);
      } 
      if (x > 0) {
        ConnectPoints(c, layer, color, x_pos + y, y_pos - x, x_pos + y, y_pos + x - 1);
        ConnectPoints(c, layer, color, x_pos - y, y_pos - x, x_pos - y, y_pos + x - 1);
      }
    }
  }
}