Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit 2988087

Browse files
Merge pull request #6 from OpenTabletDriver/wiki
Add Wiki
2 parents d75ff43 + f1a5699 commit 2988087

20 files changed

Lines changed: 1125 additions & 4 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
.idea/
99
.apikey
1010

11+
# IDE User Files
12+
*.[Dd]ot[Ss]ettings.[Uu]ser
13+
1114
# Libraries
1215
*/wwwroot/lib/

OpenTabletDriver.Web/Controllers/PluginsController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public PluginsController(IPluginMetadataService pluginMetadataService)
1313

1414
private IPluginMetadataService pluginMetadataService;
1515

16+
[ResponseCache(Duration = 300)]
1617
public async Task<IActionResult> Index()
1718
{
1819
var metadata = await pluginMetadataService.GetPlugins();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace OpenTabletDriver.Web.Controllers
4+
{
5+
public class WikiController : Controller
6+
{
7+
[ResponseCache(Duration = 300)]
8+
public IActionResult Index()
9+
{
10+
return View();
11+
}
12+
13+
[ResponseCache(Duration = 300)]
14+
[Route("Wiki/{category}/{page}")]
15+
public IActionResult Wiki(string category, string page)
16+
{
17+
return View($"{category}/{page}");
18+
}
19+
}
20+
}

OpenTabletDriver.Web/OpenTabletDriver.Web.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111

1212
<ItemGroup Label="NuGet Packages">
1313
<PackageReference Include="Markdig" Version="0.25.0" />
14-
</ItemGroup>
15-
16-
<ItemGroup>
17-
<_ContentIncludedByDefault Remove="Views\Wiki\Index.cshtml" />
14+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.8" />
1815
</ItemGroup>
1916

2017
</Project>
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Immutable;
4+
using System.IO.Pipes;
5+
using System.Linq;
6+
using System.Text.RegularExpressions;
7+
using System.Threading.Tasks;
8+
using Microsoft.AspNetCore.Html;
9+
using Microsoft.AspNetCore.Razor.TagHelpers;
10+
using Microsoft.CodeAnalysis;
11+
12+
namespace OpenTabletDriver.Web.TagHelpers
13+
{
14+
[HtmlTargetElement("codeblock")]
15+
public class CodeBlockTagHelper : TagHelper
16+
{
17+
public string Language { set; get; }
18+
19+
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
20+
{
21+
output.TagName = "pre";
22+
23+
if (output.Attributes.TryGetAttribute("class", out var classAttr))
24+
output.Attributes.SetAttribute("class", $"{classAttr.Value} card card-body");
25+
else
26+
output.Attributes.Add("class", $"card card-body");
27+
28+
29+
var content = await output.GetChildContentAsync();
30+
var innerHtml = content.GetContent().Trim('\n');
31+
32+
var body = TrimPreceding(innerHtml, ' ');
33+
output.Content.SetHtmlContent(body);
34+
}
35+
36+
private string TrimPreceding(string value, char character)
37+
{
38+
var lines = value.Split(Environment.NewLine);
39+
int preceding = CountPreceding(lines, character);
40+
var trimmedLines = from line in lines
41+
select TrimPrecedingLine(line, character, preceding);
42+
43+
var formattedLines = LanguageFormat(trimmedLines.ToArray(), Language);
44+
45+
return string.Join(Environment.NewLine, formattedLines);
46+
}
47+
48+
private IEnumerable<string> LanguageFormat(IList<string> lines, string language)
49+
{
50+
switch (language)
51+
{
52+
case "sh":
53+
case "bash":
54+
case "nix":
55+
{
56+
for (int i = 0; i < lines.Count; i++)
57+
{
58+
var line = lines[i];
59+
if (line.TrimStart().StartsWith("#"))
60+
{
61+
var nextLine = lines[i + 1];
62+
const string tag = "span";
63+
yield return $"<{tag} class=\"text-muted\">{line}</{tag}>{nextLine}";
64+
i++;
65+
}
66+
else
67+
{
68+
yield return line;
69+
}
70+
}
71+
72+
break;
73+
}
74+
case "ini":
75+
{
76+
for (int i = 0; i < lines.Count; i++)
77+
{
78+
var line = lines[i];
79+
if (Regex.IsMatch(line, @"^\[.+?\]$"))
80+
{
81+
var nextLine = lines[i + 1];
82+
const string tag = "span";
83+
yield return $"<{tag} class=\"text-info\">{line}</{tag}>{nextLine}";
84+
i++;
85+
}
86+
else
87+
{
88+
yield return line;
89+
}
90+
}
91+
92+
break;
93+
}
94+
default:
95+
{
96+
foreach (var line in lines)
97+
yield return line;
98+
break;
99+
}
100+
}
101+
}
102+
103+
private int CountPreceding(IEnumerable<string> lines, char leadingCharacter)
104+
{
105+
foreach (var line in lines)
106+
{
107+
// Make sure that the line actually starts with the leading character
108+
if (line.StartsWith(leadingCharacter) == false)
109+
continue;
110+
111+
// Determine last index of leading character, return if something else is found
112+
for (var i = 0; i < line.Length; i++)
113+
{
114+
var character = line[i];
115+
if (character != leadingCharacter)
116+
return i;
117+
}
118+
119+
// Assume that this line is the template for trimming
120+
return line.Length;
121+
}
122+
123+
throw new ArgumentException("No lines match the target leading character.", nameof(lines));
124+
}
125+
126+
private string TrimPrecedingLine(string line, char character, int amount)
127+
{
128+
return line.StartsWith(character) ? new string(line.Skip(amount).ToArray()) : line;
129+
}
130+
}
131+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<section class="py-3">
2+
<h2>@ViewBag.Title</h2>
3+
<hr/>
4+
</section>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div class="ms-4 w-15" style="width: 15%">
2+
<div class="card">
3+
<div class="card-header text-center">
4+
<h6 class="mt-2">Navigation</h6>
5+
</div>
6+
<ul class="list-group list-group-flush text-muted text-center" id="wiki-navigation"></ul>
7+
</div>
8+
</div>
9+
10+
<script type="text/javascript">
11+
document.onreadystatechange = function () {
12+
if (document.readyState == 'complete') {
13+
let navList = document.getElementById('wiki-navigation');
14+
let navItems = document.querySelectorAll('.wiki-nav-item');
15+
navItems.forEach(function (item) {
16+
let itemName = item.textContent;
17+
let id = item.id;
18+
navList.innerHTML +=
19+
'<li class=\'list-group-item\'>' +
20+
'<a class=\' link-light\' href=\'#' + id + '\'>' + itemName + '</a>' +
21+
'</li>';
22+
});
23+
}
24+
}
25+
</script>

OpenTabletDriver.Web/Views/Shared/_Layout.cshtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<title>@pageTitle</title>
1414
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch@5.0.2/dist/darkly/bootstrap.min.css" integrity="sha256-IzD7YgcFC7mrH3sadY/G75Gc49OgfS5IVOgFlxtdoUI=" crossorigin="anonymous"></link>
1515
<link rel="stylesheet" href="~/css/site.css"></link>
16+
@await RenderSectionAsync("Styles", required: false)
1617
</head>
1718
<body>
1819
<header>
@@ -35,6 +36,9 @@
3536
<li class="nav-item">
3637
<a class="nav-link text-light" asp-area="" asp-controller="Plugins" asp-action="Index">Plugins</a>
3738
</li>
39+
<li class="nav-item">
40+
<a class="nav-link text-light" asp-area="" asp-controller="Wiki" asp-action="Index">Wiki</a>
41+
</li>
3842
<li class="nav-item">
3943
<a class="nav-link text-light" asp-area="" asp-controller="Changelog" asp-action="Index">Changelog</a>
4044
</li>
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
@{
2+
ViewBag.Title = "FAQ";
3+
}
4+
5+
<partial name="Wiki/_Header"/>
6+
7+
<div class="d-flex px-4">
8+
<div class="flex-fill">
9+
<h3 class="wiki-nav-item pb-2" id="appdata">
10+
Application Data Directory
11+
</h3>
12+
<table class="table">
13+
<tr>
14+
<th class="text-center">Operating System</th>
15+
<th>Path</th>
16+
</tr>
17+
<tr>
18+
<td class="text-center">Windows</td>
19+
<td>
20+
<code class="user-select-all">%localappdata%\OpenTabletDriver</code>
21+
</td>
22+
</tr>
23+
<tr>
24+
<td class="text-center">Linux</td>
25+
<td>
26+
<code class="user-select-all">~/.config/OpenTabletDriver</code>
27+
</td>
28+
</tr>
29+
<tr>
30+
<td class="text-center">macOS</td>
31+
<td>
32+
<code class="user-select-all">~/Library/Application Support/OpenTabletDriver</code>
33+
</td>
34+
</tr>
35+
</table>
36+
37+
<hr/>
38+
39+
<h3 class="wiki-nav-item pb-2" id="command-line-args">
40+
Command Line Arguments
41+
</h3>
42+
<h4>
43+
UI
44+
</h4>
45+
<table class="table">
46+
<tr>
47+
<th>Argument</th>
48+
<th>Description</th>
49+
</tr>
50+
<tr>
51+
<td><code class="user-select-all">--minimized</code> or <code class="user-select-all">-m</code></td>
52+
<td>Starts the application in a minimized state.</td>
53+
</tr>
54+
</table>
55+
<h4>
56+
Daemon
57+
</h4>
58+
<table class="table">
59+
<tr>
60+
<th>Argument</th>
61+
<th>Description</th>
62+
</tr>
63+
<tr>
64+
<td><code class="user-select-all">--appdata</code> or <code class="user-select-all">-a</code></td>
65+
<td>Specifies the application data directory.</td>
66+
</tr>
67+
<tr>
68+
<td><code class="user-select-all">--config</code> or <code class="user-select-all">-c</code></td>
69+
<td>Specifies the configurations directory.</td>
70+
</tr>
71+
</table>
72+
73+
<hr/>
74+
75+
<h3 class="wiki-nav-item pb-2" id="area-conversion">
76+
Proprietary Driver Area Conversions
77+
</h3>
78+
<p>
79+
This can be performed from the UI or calculated manually.
80+
</p>
81+
<h4>
82+
OpenTabletDriver UI
83+
</h4>
84+
<ol>
85+
<li>Right click the tablet area editor</li>
86+
<li>Click the <code>convert item</code> menu item</li>
87+
<li>Select the OEM driver and insert your area values</li>
88+
</ol>
89+
<h4>
90+
Manual Area Conversion
91+
</h4>
92+
<p class="mb-2">
93+
Check the configuration file for your tablet
94+
<a href="https://github.com/OpenTabletDriver/OpenTabletDriver/tree/master/OpenTabletDriver/Configurations">here</a>
95+
or within the driver for properly calculated digitizer dimensions in millimeters.
96+
</p>
97+
<div class="text-muted px-3 mb-3">
98+
<small>
99+
<strong>Note:</strong> Huion and Gaomon areas use a &quot;percentage area&quot;, which uses a percentage
100+
of the tablet&#39;s maximum area to calculate the area.<br/>
101+
You must know your tablet&#39;s digitizer dimensions in millimeters in order to properly convert these areas.<br/>
102+
This is automatically handled in the UI, for the best results it is recommended to use it for converting from these proprietary drivers.<br/>
103+
</small>
104+
</div>
105+
<table class="table">
106+
<tr>
107+
<th class="text-center">Driver</th>
108+
<th>Formulas</th>
109+
</tr>
110+
<tr>
111+
<td class="text-center">Wacom, VEIKK</td>
112+
<td>
113+
<code>Width = (Right - Left) / 100</code><br/>
114+
<code>Height = (Bottom - Top) / 100</code><br/>
115+
<code>X Offset = (Left / 100) + (Width / 2)</code><br/>
116+
<code>Y Offset = (Top / 100) + (Height / 2)</code>
117+
</td>
118+
</tr>
119+
<tr>
120+
<td class="text-center">XP-Pen</td>
121+
<td>
122+
<code>Width = W / 3.937</code><br/>
123+
<code>Height = H / 3.937</code><br/>
124+
<code>X Offset = (Width / 2) + (X / 3.937)</code><br/>
125+
<code>Y Offset = (Height / 2) + (Y / 3.937)</code>
126+
</td>
127+
</tr>
128+
<tr>
129+
<td class="text-center">Huion, Gaomon</td>
130+
<td>
131+
<code>Width = (Right - Left) * tabletWidth</code><br/>
132+
<code>Height = (Bottom - Top) * tabletHeight</code><br/>
133+
<code>X Offset = (Width / 2) + (Left * tabletWidth)</code><br/>
134+
<code>Y Offset = (Height / 2) + (Top * tabletHeight)</code>
135+
</td>
136+
</tr>
137+
</table>
138+
</div>
139+
<partial name="Wiki/_Navigation"/>
140+
</div>

0 commit comments

Comments
 (0)