1 // Copyright 2021 Google LLC. 2 #ifndef Cursor_DEFINED 3 #define Cursor_DEFINED 4 #include <sstream> 5 #include "experimental/sktext/editor/Defaults.h" 6 #include "experimental/sktext/include/Text.h" 7 #include "experimental/sktext/include/Types.h" 8 #include "experimental/sktext/src/Paint.h" 9 #include "include/core/SkCanvas.h" 10 #include "include/core/SkSurface.h" 11 #include "include/core/SkTime.h" 12 #include "tools/sk_app/Application.h" 13 #include "tools/sk_app/Window.h" 14 #include "tools/skui/ModifierKey.h" 15 16 namespace skia { 17 namespace editor { 18 19 using namespace skia::text; 20 21 class Cursor { 22 public: 23 static std::unique_ptr<Cursor> Make(); 24 Cursor(); 25 virtual ~Cursor() = default; place(SkPoint xy,SkSize size)26 void place(SkPoint xy, SkSize size) { 27 if (size.width() < DEFAULT_CURSOR_WIDTH) { 28 size.fWidth = DEFAULT_CURSOR_WIDTH; 29 } 30 fXY = xy; 31 fSize = size; 32 } 33 place(SkRect rect)34 void place(SkRect rect) { 35 if (rect.width() < DEFAULT_CURSOR_WIDTH) { 36 rect.fRight = rect.fLeft + DEFAULT_CURSOR_WIDTH; 37 } 38 fXY = SkPoint::Make(rect.fLeft, rect.fTop); 39 fSize = SkSize::Make(rect.width(), rect.height()); 40 } 41 blink()42 void blink() { 43 fBlink = !fBlink; 44 } 45 getPosition()46 SkPoint getPosition() const { return fXY; } getCenterPosition()47 SkPoint getCenterPosition() const { 48 return fXY + SkPoint::Make(0, fSize.fHeight / 2); 49 } 50 51 void paint(SkCanvas* canvas); 52 53 private: 54 SkPaint fLinePaint; 55 SkPaint fRectPaint; 56 SkPoint fXY; 57 SkSize fSize; 58 bool fBlink; 59 }; 60 61 } // namespace editor 62 } // namespace skia 63 #endif // Cursor_DEFINED 64