import net.mograsim.logic.model.model.ViewModel;
import net.mograsim.logic.model.model.components.GUIComponent;
import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.preferences.Preferences;
public class LogicUIRenderer
{
{
gc.setAntialias(SWT.ON);
gc.setClipping(visibleRegion);
- gc.setLineWidth(.5);
+ gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth"));
model.getWiresByName().values().forEach(w ->
{
Rectangle bounds = w.getBounds();
import net.mograsim.logic.model.serializing.SubmodelComponentSerializer;
import net.mograsim.logic.model.snippets.Renderer;
import net.mograsim.logic.model.util.JsonHandler;
+import net.mograsim.preferences.Preferences;
/**
* A {@link GUIComponent} consisting of another model. A <code>SubmodelComponent</code> can have so-called "interface pins" connecting the
public void render(GeneralGC gc, Rectangle visibleRegion)
{
GCConfig conf = new GCConfig(gc);
- TranslatedGC tgc = new TranslatedGC(gc, getPosX(), getPosY(), submodelScale, true);
+ GeneralGC tgc = new TranslatedGC(gc, getPosX(), getPosY(), submodelScale, true);
conf.reset(tgc);
double visibleRegionFillRatio = Math.max(getWidth() / visibleRegion.width, getHeight() / visibleRegion.height);
double alphaFactor = map(visibleRegionFillRatio, maxVisibleRegionFillRatioForAlpha0, minVisibleRegionFillRatioForAlpha1, 0, 1);
renderSymbol(gc, visibleRegion);
}
conf.reset(gc);
+ // reset line width explicitly to avoid rounding errors causing weird glitches
+ gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth"));
// draw the outline after all other operations to make interface pins look better
renderOutline(gc, visibleRegion);
}
import org.eclipse.ui.themes.ITheme;
import net.mograsim.preferences.ColorDefinition;
+import net.mograsim.preferences.DefaultPreferences;
import net.mograsim.preferences.Preferences;
+// TODO proper getInt/getDouble implementation, maybe via own preferences page?
public class ThemePreferences extends Preferences
{
private final ITheme theme;
this.theme = theme;
}
+ @Override
+ public int getInt(String name)
+ {
+ return new DefaultPreferences().getInt(name);
+ }
+
+ @Override
+ public double getDouble(String name)
+ {
+ return new DefaultPreferences().getDouble(name);
+ }
+
@Override
public ColorDefinition getColorDefinition(String name)
{
public class DefaultPreferences extends Preferences
{
+ @Override
+ public int getInt(String name)
+ {
+ switch (name)
+ {
+ default:
+ throw new IllegalArgumentException("Unknown int preference name: " + name);
+ }
+ }
+
+ @Override
+ public double getDouble(String name)
+ {
+ switch (name)
+ {
+ case "net.mograsim.logic.model.linewidth":
+ return 0.5;
+ default:
+ throw new IllegalArgumentException("Unknown double preference name: " + name);
+ }
+ }
+
@Override
public ColorDefinition getColorDefinition(String name)
{
case "net.mograsim.logic.model.color.text":
return new ColorDefinition(BuiltInColor.COLOR_BLACK);
default:
- // TODO proper logging here...
- System.err.println("Unknown color name: " + name);
- return null;
+ throw new IllegalArgumentException("Unknown color preference name: " + name);
}
}
}
\ No newline at end of file
package net.mograsim.preferences;
+import java.util.Objects;
+
import org.eclipse.swt.graphics.Color;
public abstract class Preferences
public static void setPreferences(Preferences preferences)
{
- if (preferences == null)
- throw new NullPointerException();
- currentPreferences = preferences;
+ currentPreferences = Objects.requireNonNull(preferences);
}
public static Preferences current()
return currentPreferences;
}
+ public abstract int getInt(String name);
+
+ public abstract double getDouble(String name);
+
public abstract ColorDefinition getColorDefinition(String name);
public Color getColor(String name)