// Draw a line using the current pen color. void ScrollView::Line(int x1, int y1, int x2, int y2) { if (!points_->xcoords.empty() && x1 == points_->xcoords.back() && TranslateYCoordinate(y1) == points_->ycoords.back()) { // We are already at x1, y1, so just draw to x2, y2. DrawTo(x2, y2); } else if (!points_->xcoords.empty() && x2 == points_->xcoords.back() && TranslateYCoordinate(y2) == points_->ycoords.back()) { // We are already at x2, y2, so just draw to x1, y1. DrawTo(x1, y1); } else { // This is a new line. SetCursor(x1, y1); DrawTo(x2, y2); } }
// Send an image of type Pix. void ScrollView::Image(struct Pix* image, int x_pos, int y_pos) { l_uint8* data; size_t size; pixWriteMem(&data, &size, image, IFF_PNG); int base64_len = (size + 2) / 3 * 4; y_pos = TranslateYCoordinate(y_pos); SendMsg("readImage(%d,%d,%d)", x_pos, y_pos, base64_len); // Base64 encode the data. const char kBase64Table[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', }; char* base64 = new char[base64_len + 1]; memset(base64, '=', base64_len); base64[base64_len] = '\0'; int remainder = 0; int bits_left = 0; int code_len = 0; for (size_t i = 0; i < size; ++i) { int code = (data[i] >> (bits_left + 2)) | remainder; base64[code_len++] = kBase64Table[code & 63]; bits_left += 2; remainder = data[i] << (6 - bits_left); if (bits_left == 6) { base64[code_len++] = kBase64Table[remainder & 63]; bits_left = 0; remainder = 0; } } if (bits_left > 0) base64[code_len++] = kBase64Table[remainder & 63]; SendRawMessage(base64); delete [] base64; lept_free(data); }
// Zoom the window to the rectangle given upper left corner and // lower right corner. void ScrollView::ZoomToRectangle(int x1, int y1, int x2, int y2) { y1 = TranslateYCoordinate(y1); y2 = TranslateYCoordinate(y2); SendMsg("zoomRectangle(%d,%d,%d,%d)", std::min(x1, x2), std::min(y1, y2), std::max(x1, x2), std::max(y1, y2)); }
// Open and draw an image given a name at (x,y). void ScrollView::Image(const char* image, int x_pos, int y_pos) { SendMsg("openImage('%s')", image); SendMsg("drawImage('%s',%d,%d)", image, x_pos, TranslateYCoordinate(y_pos)); }
// Draw text at the given coordinates. void ScrollView::Text(int x, int y, const char* mystring) { SendMsg("drawText(%d,%d,'%s')", x, TranslateYCoordinate(y), mystring); }
// Draw an ellipse using the current pen color. // The ellipse is filled with the current brush color. void ScrollView::Ellipse(int x1, int y1, int width, int height) { SendMsg("drawEllipse(%d,%d,%u,%u)", x1, TranslateYCoordinate(y1), width, height); }
// Draw a rectangle using the current pen color. // The rectangle is filled with the current brush color. void ScrollView::Rectangle(int x1, int y1, int x2, int y2) { if (x1 == x2 && y1 == y2) return; // Scrollviewer locks up. SendMsg("drawRectangle(%d,%d,%d,%d)", x1, TranslateYCoordinate(y1), x2, TranslateYCoordinate(y2)); }
// Draws from the current position to (x,y) and sets the new position to it. void ScrollView::DrawTo(int x, int y) { points_->xcoords.push_back(x); points_->ycoords.push_back(TranslateYCoordinate(y)); points_->empty = false; }
// Zoom the window to the rectangle given upper left corner and // lower right corner. void ScrollView::ZoomToRectangle(int x1, int y1, int x2, int y2) { y1 = TranslateYCoordinate(y1); y2 = TranslateYCoordinate(y2); SendMsg("zoomRectangle(%d,%d,%d,%d)", MIN(x1, x2), MIN(y1, y2), MAX(x1, x2), MAX(y1, y2)); }
// Draw a rectangle using the current pen color. // The rectangle is filled with the current brush color. void ScrollView::Rectangle(int x1, int y1, int x2, int y2) { SendMsg("drawRectangle(%d,%d,%d,%d)", x1, TranslateYCoordinate(y1), x2, TranslateYCoordinate(y2)); }