aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/unix
diff options
context:
space:
mode:
authorGravatar Scroggo <Scroggo@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-24 18:35:50 +0000
committerGravatar Scroggo <Scroggo@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-24 18:35:50 +0000
commit0f185c2709f638c0f4d452cb38b434cadfd15ab9 (patch)
tree2dc1240e0e24aa72ea57848be704a4374a1c63a2 /src/utils/unix
parent7f5875d33462f0f1b96a36ac530fb1f2edb1d535 (diff)
Move zoomer into SampleApp
git-svn-id: http://skia.googlecode.com/svn/trunk@1002 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils/unix')
-rw-r--r--src/utils/unix/SkOSWindow_Unix.cpp146
1 files changed, 3 insertions, 143 deletions
diff --git a/src/utils/unix/SkOSWindow_Unix.cpp b/src/utils/unix/SkOSWindow_Unix.cpp
index 8e348acdf0..83db6ad5c9 100644
--- a/src/utils/unix/SkOSWindow_Unix.cpp
+++ b/src/utils/unix/SkOSWindow_Unix.cpp
@@ -9,20 +9,14 @@
#include "SkCanvas.h"
#include "SkColor.h"
#include "SkEvent.h"
-#include "SkTypeface.h"
SkOSWindow::SkOSWindow(void* unused)
{
fUnixWindow.fDisplay = NULL;
- fMouseX = fMouseY = 0;
- fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold);
- fShowZoomer = false;
- fScale = 4;
}
SkOSWindow::~SkOSWindow()
{
- fTypeface->unref();
}
void SkOSWindow::setUnixWindow(Display* dsp, Window win, size_t screenNumber, GC gc)
@@ -48,29 +42,6 @@ void SkOSWindow::presentGL()
}
-bool SkOSWindow::zoomIn()
-{
- // Arbitrarily decided
- if (fScale == 25) return false;
- fScale++;
- inval(NULL);
- return true;
-}
-
-bool SkOSWindow::zoomOut()
-{
- if (fScale == 1) return false;
- fScale--;
- inval(NULL);
- return true;
-}
-
-void SkOSWindow::toggleZoomer()
-{
- fShowZoomer = !fShowZoomer;
- inval(NULL);
-}
-
void SkOSWindow::onSetTitle(const char title[])
{
if (!fUnixWindow.fDisplay) return;
@@ -117,33 +88,6 @@ static bool convertBitmapToXImage(XImage& image, const SkBitmap& bitmap)
return XInitImage(&image);
}
-void SkOSWindow::updatePointer(int x, int y)
-{
- fMouseX = x;
- fMouseY = y;
- inval(NULL);
-}
-
-static void drawText(SkCanvas& canvas, SkString string, SkScalar left, SkScalar top, SkPaint& paint)
-{
- SkColor desiredColor = paint.getColor();
- paint.setColor(SK_ColorWHITE);
- const char* c_str = string.c_str();
- size_t size = string.size();
- SkRect bounds;
- paint.measureText(c_str, size, &bounds);
- bounds.offset(left, top);
- SkScalar inset = SkIntToScalar(-2);
- bounds.inset(inset, inset);
- canvas.drawRect(bounds, paint);
- if (desiredColor != SK_ColorBLACK) {
- paint.setColor(SK_ColorBLACK);
- canvas.drawText(c_str, size, left + SK_Scalar1, top + SK_Scalar1, paint);
- }
- paint.setColor(desiredColor);
- canvas.drawText(c_str, size, left, top, paint);
-}
-
void SkOSWindow::doPaint() {
if (!fUnixWindow.fDisplay) return;
// Draw the bitmap to the screen.
@@ -151,94 +95,10 @@ void SkOSWindow::doPaint() {
int width = bitmap.width();
int height = bitmap.height();
- if (!fShowZoomer) {
- XImage image;
- if (!convertBitmapToXImage(image, bitmap)) return;
+ XImage image;
+ if (!convertBitmapToXImage(image, bitmap)) return;
- XPutImage(fUnixWindow.fDisplay, fUnixWindow.fWin, fUnixWindow.fGc, &image, 0, 0, 0, 0, width, height);
- } else {
- // Ensure the mouse position is on screen.
- if (fMouseX >= width) fMouseX = width - 1;
- else if (fMouseX < 0) fMouseX = 0;
- if (fMouseY >= height) fMouseY = height - 1;
- else if (fMouseY < 0) fMouseY = 0;
- // zoomedBitmap will show the original bitmap, plus a zoomed in view (fat bits).
- SkBitmap zoomedBitmap;
- bitmap.copyTo(&zoomedBitmap, bitmap.getConfig());
- SkCanvas canvas(zoomedBitmap);
- // Find the size of the zoomed in view, forced to be odd, so the examined pixel is in the middle.
- int zoomedWidth = (width >> 2) | 1;
- int zoomedHeight = (height >> 2) | 1;
- SkIRect src;
- src.set(0, 0, zoomedWidth / fScale, zoomedHeight / fScale);
- src.offset(fMouseX - (src.width()>>1), fMouseY - (src.height()>>1));
- SkRect dest;
- dest.set(0, 0, SkIntToScalar(zoomedWidth), SkIntToScalar(zoomedHeight));
- dest.offset(SkIntToScalar(width - zoomedWidth), SkIntToScalar(height - zoomedHeight));
- SkPaint paint;
- // Clear the background behind our zoomed in view
- paint.setColor(SK_ColorWHITE);
- canvas.drawRect(dest, paint);
- canvas.drawBitmapRect(bitmap, &src, dest);
- paint.setColor(SK_ColorBLACK);
- paint.setStyle(SkPaint::kStroke_Style);
- // Draw a border around the pixel in the middle
- SkRect originalPixel;
- originalPixel.set(SkIntToScalar(fMouseX), SkIntToScalar(fMouseY), SkIntToScalar(fMouseX + 1), SkIntToScalar(fMouseY + 1));
- SkMatrix matrix;
- SkRect scalarSrc;
- scalarSrc.set(src);
- SkColor color = bitmap.getColor(fMouseX, fMouseY);
- if (matrix.setRectToRect(scalarSrc, dest, SkMatrix::kFill_ScaleToFit)) {
- SkRect pixel;
- matrix.mapRect(&pixel, originalPixel);
- // TODO Perhaps measure the values and make the outline white if it's "dark"
- if (color == SK_ColorBLACK) {
- paint.setColor(SK_ColorWHITE);
- }
- canvas.drawRect(pixel, paint);
- }
- paint.setColor(SK_ColorBLACK);
- // Draw a border around the destination rectangle
- canvas.drawRect(dest, paint);
- paint.setStyle(SkPaint::kStrokeAndFill_Style);
- // Identify the pixel and its color on screen
- paint.setTypeface(fTypeface);
- paint.setAntiAlias(true);
- SkScalar lineHeight = paint.getFontMetrics(NULL);
- SkString string;
- string.appendf("(%i, %i)", fMouseX, fMouseY);
- SkScalar left = dest.fLeft + SkIntToScalar(3);
- SkScalar i = SK_Scalar1;
- drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
- // Alpha
- i += SK_Scalar1;
- string.reset();
- string.appendf("A: %X", SkColorGetA(color));
- drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
- // Red
- i += SK_Scalar1;
- string.reset();
- string.appendf("R: %X", SkColorGetR(color));
- paint.setColor(SK_ColorRED);
- drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
- // Green
- i += SK_Scalar1;
- string.reset();
- string.appendf("G: %X", SkColorGetG(color));
- paint.setColor(SK_ColorGREEN);
- drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
- // Blue
- i += SK_Scalar1;
- string.reset();
- string.appendf("B: %X", SkColorGetB(color));
- paint.setColor(SK_ColorBLUE);
- drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
- // Finally, put our bitmap on the screen
- XImage zoomedImage;
- convertBitmapToXImage(zoomedImage, zoomedBitmap);
- XPutImage(fUnixWindow.fDisplay, fUnixWindow.fWin, fUnixWindow.fGc, &zoomedImage, 0, 0, 0, 0, width, height);
- }
+ XPutImage(fUnixWindow.fDisplay, fUnixWindow.fWin, fUnixWindow.fGc, &image, 0, 0, 0, 0, width, height);
}
bool SkOSWindow::onHandleChar(SkUnichar)