1 module w95.border;
2 
3 import fluid.style;
4 import fluid.utils;
5 import fluid.border;
6 import fluid.backend;
7 
8 @safe:
9 
10 
11 W95Border w95Border(Color topLeftCorner, Color bottomRightCorner, Color shadow = color("#000")) {
12 
13     auto result = new W95Border;
14     result.color = [
15         topLeftCorner, bottomRightCorner,
16         topLeftCorner, bottomRightCorner
17     ];
18     result.shadowColor = shadow;
19     return result;
20 
21 }
22 
23 class W95Border : ColorBorder {
24 
25     Color shadowColor = .color("#000");
26     Color shineColor = .color("#0000");
27 
28     override void apply(FluidBackend io, Rectangle borderBox, float[4] size) const @trusted {
29 
30         const boxStart = borderBox.start;
31         const boxEnd = borderBox.end;
32         const boxSize = boxEnd - boxStart;
33 
34         // Draw regular lines
35         if (size.sideTop) {
36             io.drawRectangle(
37                 Rectangle(
38                     boxStart.x,    boxStart.y,
39                     boxSize.x - 1, 1
40                 ),
41                 color[Style.Side.top]
42             );
43         }
44         if (size.sideLeft) {
45             io.drawRectangle(
46                 Rectangle(
47                     boxStart.x, boxStart.y,
48                     1,          boxSize.y  - 1,
49                 ),
50                 color[Style.Side.left]
51             );
52         }
53         if (size.sideRight) {
54             io.drawRectangle(
55                 Rectangle(
56                     boxEnd.x - 2, boxStart.y + 1,
57                     1,            boxSize.y - 2,
58                 ),
59                 color[Style.Side.right]
60             );
61         }
62         if (size.sideBottom) {
63             io.drawRectangle(
64                 Rectangle(
65                     boxStart.x + 1, boxEnd.y - 2,
66                     boxSize.x  - 2,  1,
67                 ),
68                 color[Style.Side.bottom]
69             );
70         }
71 
72         // Draw shine lines
73         if (size.sideTop) {
74             io.drawRectangle(
75                 Rectangle(
76                     boxStart.x + 1, boxStart.y + 1,
77                     boxSize.x - 2,  1
78                 ),
79                 shineColor
80             );
81         }
82         if (size.sideLeft) {
83             io.drawRectangle(
84                 Rectangle(
85                     boxStart.x + 1, boxStart.y + 1,
86                     1,              boxSize.y  - 2,
87                 ),
88                 shineColor
89             );
90         }
91 
92         // Draw the shadow lines
93         if (size.sideRight) {
94             io.drawRectangle(
95                 Rectangle(
96                     boxEnd.x - 1, boxStart.y,
97                     1,            boxSize.y,
98                 ),
99                 shadowColor
100             );
101         }
102         if (size.sideBottom) {
103             io.drawRectangle(
104                 Rectangle(
105                     boxStart.x, boxEnd.y - 1,
106                     boxSize.x,  1,
107                 ),
108                 shadowColor
109             );
110         }
111 
112     }
113 
114     W95Border setShine(Color color) return {
115 
116         shineColor = color;
117         return this;
118 
119     }
120 
121     W95Border setShadow(Color color) return {
122 
123         shadowColor = color;
124         return this;
125 
126     }
127 
128 }