1 package net.mograsim.logic.ui.serializing.snippets.symbolrenderers;
3 import net.haspamelodica.swt.helper.gcs.GeneralGC;
4 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
5 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
6 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
7 import net.mograsim.logic.ui.model.components.GUIComponent;
8 import net.mograsim.logic.ui.model.components.submodels.SubmodelComponent;
9 import net.mograsim.logic.ui.serializing.CodeSnippetSupplier;
10 import net.mograsim.logic.ui.serializing.snippets.Renderer;
11 import net.mograsim.logic.ui.serializing.snippets.SnippetSupplier;
12 import net.mograsim.preferences.ColorDefinition;
13 import net.mograsim.preferences.ColorManager;
14 import net.mograsim.preferences.Preferences;
17 * Renders a text (<code>"text"</code>) with a given font height (<code>"height"</code>) in the center of the component.
19 * @author Daniel Kirschten
21 public class CenteredTextSymbolRenderer implements Renderer
23 private final GUIComponent component;
24 private final CenteredTextParams params;
26 public CenteredTextSymbolRenderer(SubmodelComponent component, CenteredTextParams params)
28 this.component = component;
34 public void render(GeneralGC gc, Rectangle visibleRegion)
36 Font oldFont = gc.getFont();
37 gc.setFont(new Font(oldFont.getName(), params.fontHeight, oldFont.getStyle()));
38 ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.text");
40 gc.setForeground(ColorManager.current().toColor(fg));
41 Point idSize = gc.textExtent(params.text);
42 Rectangle bounds = component.getBounds();
43 gc.drawText(params.text, bounds.x + (bounds.width - idSize.x) / 2, bounds.y + (bounds.height - idSize.y) / 2, true);
47 public static class CenteredTextParams
50 public double fontHeight;
55 CodeSnippetSupplier.symbolRendererProviderSupplier.setSnippetProvider(CenteredTextSymbolRenderer.class.getCanonicalName(),
56 SnippetSupplier.create(CenteredTextParams.class, CenteredTextSymbolRenderer::new));