MCPcopy Create free account
hub / github.com/Card-Forge/forge / draw

Method draw

forge-gui-mobile/src/forge/toolbox/FProgressBar.java:138–200  ·  view source on GitHub ↗
(Graphics g)

Source from the content-addressed store, hash-verified

136 }
137
138 @Override
139 public void draw(Graphics g) {
140 float w = getWidth();
141 float h = getHeight();
142
143 //draw background and progress
144 List<Pair<Float, Float>> selTextRegions = new ArrayList<>();
145 if (showProgressTrail) {
146 long now = new Date().getTime();
147 if (progressTrailStart == -1) {
148 progressTrailStart = now;
149 }
150 float halfWidth = w / 2;
151 float trailPercent = ((now - progressTrailStart) % TRAIL_INTERVAL) / TRAIL_INTERVAL;
152 if (trailPercent == 0) {
153 g.fillGradientRect(getBackColor(), getSelBackColor(), false, 0, 0, w, h);
154 selTextRegions.add(Pair.of(halfWidth, halfWidth));
155 }
156 else {
157 float trailX = trailPercent * w;
158 g.startClip(0, 0, w, h);
159 g.fillGradientRect(getBackColor(), getSelBackColor(), false, trailX - w, 0, w, h);
160 g.fillGradientRect(getBackColor(), getSelBackColor(), false, trailX, 0, w, h);
161 g.endClip();
162 if (trailX >= halfWidth) {
163 selTextRegions.add(Pair.of(trailX - halfWidth, halfWidth));
164 }
165 else {
166 selTextRegions.add(Pair.of(0f, trailX));
167 float x = trailX + halfWidth;
168 selTextRegions.add(Pair.of(x, w - x));
169 }
170 }
171 }
172 else {
173 g.fillRect(getBackColor(), 0, 0, w, h);
174
175 float selWidth = Math.round(w * (float)value / (float)maximum);
176 if (selWidth > 0) {
177 g.fillRect(getSelBackColor(), 0, 0, selWidth, h);
178 selTextRegions.add(Pair.of(0f, selWidth));
179 }
180 }
181
182 //draw message
183 if (MSG_FONT == null) { //must wait to initialize until after FSkin initialized
184 MSG_FONT = FSkinFont.get(11);
185 }
186
187 g.drawText(message, MSG_FONT, getForeColor(), 0, 0, w, h, false, Align.center, true);
188
189 //draw text using selection fore color in needed regions over top of regular text using clipping
190 if (!getSelForeColor().equals(getForeColor())) {
191 for (Pair<Float, Float> region : selTextRegions) {
192 g.startClip(region.getLeft(), 0, region.getRight(), h);
193 g.drawText(message, MSG_FONT, getSelForeColor(), 0, 0, w, h, false, Align.center, true);
194 g.endClip();
195 }

Callers

nothing calls this directly

Calls 15

getBackColorMethod · 0.95
getSelBackColorMethod · 0.95
getMethod · 0.95
getForeColorMethod · 0.95
getSelForeColorMethod · 0.95
scaleMethod · 0.95
fillGradientRectMethod · 0.80
ofMethod · 0.80
endClipMethod · 0.80
fillRectMethod · 0.80
getLeftMethod · 0.80
getRightMethod · 0.80

Tested by

no test coverage detected