Skip to content

Commit

Permalink
Add top for Primary
Browse files Browse the repository at this point in the history
  • Loading branch information
lomirus committed Jul 30, 2023
1 parent 8918901 commit 4905d05
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
21 changes: 14 additions & 7 deletions lib/common/character/mod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'primary/a_anchor.dart';
import 'primary/b_anchor.dart';
import 'primary/c_anchor.dart';
import 'primary/d_anchor.dart';
import 'primary/top.dart';
import 'primary/utils.dart';
import 'secondary/core.dart';
import 'secondary/extension.dart';
Expand All @@ -14,7 +15,7 @@ import 'secondary/utils.dart';
sealed class Character {
const Character();

(String, double) getSvg(double baseX, double height, String fillColor);
(String, double) getSvg(double baseX, double baseY, String fillColor);
}

class Secondary extends Character {
Expand Down Expand Up @@ -70,12 +71,12 @@ class Secondary extends Character {
}

@override
(String, double) getSvg(double baseX, double height, String fillColor) {
(String, double) getSvg(double baseX, double baseY, String fillColor) {
final Secondary(:core, :start, :end, :startAnchor, :endAnchor) = this;

final secondaryBoundary = getSecondaryBoundary(this);
final coreX = baseX - secondaryBoundary.$1;
final coreY = height / 2;
final coreY = baseY;
final extStartX = coreX + startAnchor.coord.x;
final extStartY = coreY + startAnchor.coord.y;
final extEndX = coreX + endAnchor.coord.x + 0;
Expand Down Expand Up @@ -107,6 +108,7 @@ class Secondary extends Character {

class Primary extends Character {
final Specification specification;
final Context context;
// Properties for A Anchor
final Essence essence;
final Affiliation affiliation;
Expand All @@ -124,6 +126,7 @@ class Primary extends Character {

const Primary({
required this.specification,
required this.context,
required this.essence,
required this.affiliation,
required this.perspective,
Expand All @@ -137,26 +140,30 @@ class Primary extends Character {
});

@override
(String, double) getSvg(double baseX, double height, String fillColor) {
(String, double) getSvg(double baseX, double baseY, String fillColor) {
final (left, right) = getPrimaryBoundary(this);
final width = right - left;
final topName = context.name;
final aAnchorName = '${essence.name}_${affiliation.name}';
final bAnchorName = '${perspective.name}_${extension.name}';
final cAnchorName = '${separability.name}_${similarity.name}';
final dAnchorName = '${function.name}_${version.name}_${plexity.name}_${stem.name}';
final specificationX = baseX - left;
final specificationY = height / 2;
final specificationY = baseY;
final topX = specificationX + specification.centerX;
final topY = specificationY;
final aAnchorX = specificationX + specification.centerX;
final aAnchorY = specificationY + 0;
final aAnchorY = specificationY;
final bAnchorX = specificationX + specification.bAnchor.x;
final bAnchorY = specificationY + specification.bAnchor.y;
final cAnchorX = specificationX + specification.centerX;
final cAnchorY = specificationY + 0;
final cAnchorY = specificationY;
final dAnchorX = specificationX + specification.dAnchor.x;
final dAnchorY = specificationY + specification.dAnchor.y;
return (
'''
<use href="#${specification.name}" x="$specificationX" y="$specificationY" fill="$fillColor" />
<use href="#$topName" x="$topX" y="$topY" fill="$fillColor" />
<use href="#$aAnchorName" x="$aAnchorX" y="$aAnchorY" fill="$fillColor" />
<use href="#$bAnchorName" x="$bAnchorX" y="$bAnchorY" fill="$fillColor" />
<use href="#$cAnchorName" x="$cAnchorX" y="$cAnchorY" fill="$fillColor" />
Expand Down
20 changes: 20 additions & 0 deletions lib/common/character/primary/top.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
enum Context {
/// The Existential Context
exs,

/// The Functional Context
fnc,

/// The Representational Context
rps,

/// The Amalgamative Context
amg;
}

const Map<String, String> topData = {
"exs": "",
"fnc": "M -7.50 -40.00 L 0.00 -32.50 7.50 -40.00 0.00 -47.50 -7.50 -40.00 Z",
"rps": "M 10.00 -40.00 L 20.00 -50.00 -10.00 -50.00 -20.00 -40.00 10.00 -40.00 Z",
"amg": "M -13.75 -51.25 L 6.25 -31.25 13.75 -38.75 -6.25 -58.75 -13.75 -51.25 Z"
};
23 changes: 17 additions & 6 deletions lib/common/ithkuil_svg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'character/primary/a_anchor.dart';
import 'character/primary/b_anchor.dart';
import 'character/primary/c_anchor.dart';
import 'character/primary/d_anchor.dart';
import 'character/primary/top.dart';
import 'utils.dart';

class IthkuilSvg extends StatelessWidget {
Expand All @@ -19,15 +20,20 @@ class IthkuilSvg extends StatelessWidget {
// core letter height = 2 unit height = 70
// full letter height = 4 unit height = 140
// full letter with padding height = 6 unit height = 210
const double baseHeight = 140;
const double unitHeight = 35;
const double verticalPadding = unitHeight;
const double horizontalPadding = 20;
const double horizontalGap = 10;
final String fillColor = colorToHex(Theme.of(context).textTheme.titleLarge!.color!);
// final String fillColor = "#e6e1e6";

final usedSpecifications =
characters.whereType<Primary>().map((s) => s.specification).toSet().toList();

final List<(String, String)> usedPrimaryTops = characters
.whereType<Primary>()
.map((s) => (s.context.name, topData[s.context.name]!))
.toSet()
.toList();
final List<(String, String)> usedAAnchors = characters
.whereType<Primary>()
.map(
Expand Down Expand Up @@ -99,23 +105,28 @@ class IthkuilSvg extends StatelessWidget {
for (int i = 0; i < characters.length; i++) {
final character = characters[i];
if (character is Primary) {
final (svgString, svgWidth) = character.getSvg(leftCoord, baseHeight, fillColor);
final (svgString, svgWidth) =
character.getSvg(leftCoord, verticalPadding + unitHeight * 2, fillColor);
charImages.add(svgString);
leftCoord += svgWidth + horizontalGap;
} else if (character is Secondary) {
final (svgString, svgWidth) = character.getSvg(leftCoord, baseHeight, fillColor);
final (svgString, svgWidth) =
character.getSvg(leftCoord, verticalPadding + unitHeight * 2, fillColor);
charImages.add(svgString);
leftCoord += svgWidth + horizontalGap;
}
}
final baseWidth = leftCoord - horizontalGap + horizontalPadding;

return SvgPicture.string(
'''<svg width="$baseWidth" height="$baseHeight">
'''<svg width="$baseWidth" height="${unitHeight * 6}">
<defs>
${usedSpecifications.map(
(e) => '<path stroke="none" id="${e.name}" d="${e.path}" />',
).join('')}
${usedPrimaryTops.map(
(e) => '<path stroke="none" id="${e.$1}" d="${e.$2}" />',
).join('')}
${usedAAnchors.map(
(e) => '<path stroke="none" id="${e.$1}" d="${e.$2}" />',
).join('')}
Expand All @@ -136,7 +147,7 @@ class IthkuilSvg extends StatelessWidget {
(e) => '<path stroke="none" id="${e.$1}" d="${e.$2}" />',
).join('')}
</defs>
<rect x="0" y="0" height="$baseHeight" width="$baseWidth" style="fill: transparent" />
<rect x="0" y="0" height="${unitHeight * 6}" width="$baseWidth" style="fill: transparent" />
${charImages.join('\n')}
</svg>''',
width: MediaQuery.of(context).size.width - 32,
Expand Down
8 changes: 5 additions & 3 deletions lib/pages/construct.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:enthrirch/common/character/primary/top.dart';
import 'package:flutter/material.dart';

import 'package:enthrirch/common/character/mod.dart';
Expand Down Expand Up @@ -26,16 +27,17 @@ class _ConstructPageState extends State<ConstructPage> {
[
const Primary(
specification: Specification.cte,
essence: Essence.nrm,
affiliation: Affiliation.coa,
context: Context.fnc,
essence: Essence.rpv,
affiliation: Affiliation.var$,
perspective: Perspective.m,
extension: Extension.prx,
similarity: Similarity.d,
separability: Separability.s,
function: Function$.sta,
version: Version.prc,
plexity: Plexity.um,
stem: Stem.s2,
stem: Stem.s1,
),
Secondary.from("zčw")!,
Secondary.from("zxr")!,
Expand Down

0 comments on commit 4905d05

Please sign in to comment.