Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
HandySimple.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_Led_HandySimple_h_
5#define _Stroika_Frameworks_Led_HandySimple_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9/*
10@MODULE: LedHandySimple
11@DESCRIPTION:
12 <p>A collection of fairly simple, hopefully (for some) handy utility claasses
13 and routines using various parts of Led.This module will probably end up requiring
14 linking in alot of Led - as its fairly diverse in nature. Perhaps that will
15 get fixed in a future release?</p>
16 */
17
18#include "Stroika/Frameworks/Led/ChunkedArrayTextStore.h"
19#include "Stroika/Frameworks/Led/GDI.h"
20#include "Stroika/Frameworks/Led/WordProcessor.h"
21
22namespace Stroika::Frameworks::Led {
23
24 template <typename WORDWRAPPEDTEXTIMAGER, typename SIMPLETEXTIMAGER, typename TEXTSTORE>
25 Led_Size GetTextExtent (Tablet* tablet, const Led_tString& text, const Led_Rect& r, bool wordWrap);
26
27 template <typename WORDWRAPPEDTEXTIMAGER, typename SIMPLETEXTIMAGER, typename TEXTSTORE>
28 void DrawTextBox (Tablet* tablet, const Led_tString& text, const Led_Rect& r, bool wordWrap);
29
30 /*
31 @CLASS: WaterMarkHelper<TEXTSTORE,WORDPROCESSOR>
32 @DESCRIPTION: <p>TEXTSTORE defaults to @'ChunkedArrayTextStore' and WORDPROCESSOR defaults to @'WordProcessor' </p>
33 <p>This can be used to draw a bit of styled (or other) as a watermark background. For example, you can
34 override @'TextImager::EraseBackground' () like this:
35 <code><pre>
36 void MyLedBasedView::EraseBackground (Tablet* tablet, const Led_Rect& subsetToDraw, bool printing)
37 {
38 inherited::EraseBackground (tablet, subsetToDraw, printing);
39 static WaterMarkHelper<> waterMarkerImager (LED_TCHAR_OF ("Demo Mode")); // make this static - just as a performance hack. Also could be an instance variable of 'this'.
40 waterMarkerImager.DrawWatermark (tablet, GetWindowRect (), subsetToDraw);
41 }
42 </pre></code>
43 </p>
44 <p>Note - if you do this - you should also call
45 <code><pre>
46 SetUseBitmapScrollingOptimization (false);
47 </pre></code>
48 in your view's constructor, since scrolling bits won't work with a watermark background.
49 </p>
50 */
51 template <typename TEXTSTORE = ChunkedArrayTextStore, typename WORDPROCESSOR = WordProcessor>
52 class WaterMarkHelper {
53 public:
54 WaterMarkHelper (const Led_tString& watermMarkText);
55 ~WaterMarkHelper ();
56
57 public:
58 nonvirtual Color GetWatermarkColor () const;
59 nonvirtual void SetWatermarkColor (const Color& c);
60
61 private:
62 Color fWatermarkColor;
63
64 public:
65 nonvirtual void DrawWatermark (Tablet* tablet, const Led_Rect& intoRect, const Led_Rect& subsetToDraw);
66
67 private:
68 struct MyTrivImager : public TrivialImager_Interactor<TEXTSTORE, WORDPROCESSOR> {
69 using inherited = TrivialImager_Interactor<TEXTSTORE, WORDPROCESSOR>;
70 MyTrivImager (Tablet* t, Led_Rect bounds, const Led_tString& initialText)
71 : inherited (t, bounds, initialText)
72 {
73 /*
74 * Good performance hack (shutting off ImageUsingOffscreenBitmaps), plus critical for
75 * how we do the EraseBackground () below.
76 */
77 this->SetImageUsingOffscreenBitmaps (false);
78 }
79 virtual void EraseBackground ([[maybe_unused]] Tablet* tablet, [[maybe_unused]] const Led_Rect& subsetToDraw, [[maybe_unused]] bool printing) override
80 {
81 // Do no erasing - just draw the text...
82 // Note - its CRITICAL that we shutoff offscreen bitmaps for this imager so that we don't get garbage bits
83 // from that offscreen bitmap being copied back to the original tablet.
84 }
85 virtual void GetLayoutMargins (typename WORDPROCESSOR::RowReference row, CoordinateType* lhs, CoordinateType* rhs) const override
86 {
87 // Make the layout right margin of each line (paragraph) equal to the windowrect. Ie, wrap to the
88 // edge of the window.
89 CoordinateType l = 0;
90 CoordinateType r = 0;
91 inherited::GetLayoutMargins (row, &l, &r);
92 r = max (static_cast<CoordinateType> (this->GetWindowRect ().GetWidth ()), l + 1);
93 Ensure (r > l);
94 if (lhs != NULL) {
95 *lhs = l;
96 }
97 if (rhs != NULL) {
98 *rhs = r;
99 }
100 }
101 };
102
103 private:
104 Led_tString fWatermarkText;
105 MyTrivImager* fCachedImager;
106 Led_Rect fCachedIntoRect;
107 Tablet* fCachedIntoTablet;
108 };
109
110}
111
112/*
113 ********************************************************************************
114 ***************************** Implementation Details ***************************
115 ********************************************************************************
116 */
117#include "HandySimple.inl"
118
119#endif /*_Stroika_Frameworks_Led_HandySimple_h_*/