Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
HandySimple.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. 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 DISABLE_COMPILER_MSC_WARNING_START (4250) // inherits via dominance warning
31 /*
32 @CLASS: WaterMarkHelper<TEXTSTORE,WORDPROCESSOR>
33 @DESCRIPTION: <p>TEXTSTORE defaults to @'ChunkedArrayTextStore' and WORDPROCESSOR defaults to @'WordProcessor' </p>
34 <p>This can be used to draw a bit of styled (or other) as a watermark background. For example, you can
35 override @'TextImager::EraseBackground' () like this:
36 <code><pre>
37 void MyLedBasedView::EraseBackground (Tablet* tablet, const Led_Rect& subsetToDraw, bool printing)
38 {
39 inherited::EraseBackground (tablet, subsetToDraw, printing);
40 static WaterMarkHelper<> waterMarkerImager (LED_TCHAR_OF ("Demo Mode")); // make this static - just as a performance hack. Also could be an instance variable of 'this'.
41 waterMarkerImager.DrawWatermark (tablet, GetWindowRect (), subsetToDraw);
42 }
43 </pre></code>
44 </p>
45 <p>Note - if you do this - you should also call
46 <code><pre>
47 SetUseBitmapScrollingOptimization (false);
48 </pre></code>
49 in your view's constructor, since scrolling bits won't work with a watermark background.
50 </p>
51 */
52 template <typename TEXTSTORE = ChunkedArrayTextStore, typename WORDPROCESSOR = WordProcessor>
53 class WaterMarkHelper {
54 public:
55 WaterMarkHelper (const Led_tString& watermMarkText);
56 ~WaterMarkHelper ();
57
58 public:
59 nonvirtual Color GetWatermarkColor () const;
60 nonvirtual void SetWatermarkColor (const Color& c);
61
62 private:
63 Color fWatermarkColor;
64
65 public:
66 nonvirtual void DrawWatermark (Tablet* tablet, const Led_Rect& intoRect, const Led_Rect& subsetToDraw);
67
68 private:
69 struct MyTrivImager : public TrivialImager_Interactor<TEXTSTORE, WORDPROCESSOR> {
70 using inherited = TrivialImager_Interactor<TEXTSTORE, WORDPROCESSOR>;
71 MyTrivImager (Tablet* t, Led_Rect bounds, const Led_tString& initialText)
72 : inherited (t, bounds, initialText)
73 {
74 /*
75 * Good performance hack (shutting off ImageUsingOffscreenBitmaps), plus critical for
76 * how we do the EraseBackground () below.
77 */
78 this->SetImageUsingOffscreenBitmaps (false);
79 }
80 virtual void EraseBackground ([[maybe_unused]] Tablet* tablet, [[maybe_unused]] const Led_Rect& subsetToDraw, [[maybe_unused]] bool printing) override
81 {
82 // Do no erasing - just draw the text...
83 // Note - its CRITICAL that we shutoff offscreen bitmaps for this imager so that we don't get garbage bits
84 // from that offscreen bitmap being copied back to the original tablet.
85 }
86 virtual void GetLayoutMargins (typename WORDPROCESSOR::RowReference row, CoordinateType* lhs, CoordinateType* rhs) const override
87 {
88 // Make the layout right margin of each line (paragraph) equal to the windowrect. Ie, wrap to the
89 // edge of the window.
90 CoordinateType l = 0;
91 CoordinateType r = 0;
92 inherited::GetLayoutMargins (row, &l, &r);
93 r = max (static_cast<CoordinateType> (this->GetWindowRect ().GetWidth ()), l + 1);
94 Ensure (r > l);
95 if (lhs != NULL) {
96 *lhs = l;
97 }
98 if (rhs != NULL) {
99 *rhs = r;
100 }
101 }
102 };
103
104 private:
105 Led_tString fWatermarkText;
106 MyTrivImager* fCachedImager;
107 Led_Rect fCachedIntoRect;
108 Tablet* fCachedIntoTablet;
109 };
110 DISABLE_COMPILER_MSC_WARNING_END (4250)
111
112}
113
114/*
115 ********************************************************************************
116 ***************************** Implementation Details ***************************
117 ********************************************************************************
118 */
119#include "HandySimple.inl"
120
121#endif /*_Stroika_Frameworks_Led_HandySimple_h_*/