rightclick now pops position (useful for href navigation)
[xreader.git] / xreadercfg.d
blob792900f976436d5cff8f7ae69cf5c7be03c47a17
1 /* Written by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module xreadercfg;
19 import arsd.simpledisplay;
20 import arsd.color;
21 import arsd.png;
22 import arsd.jpeg;
24 import iv.nanovg;
25 import iv.strex;
26 import iv.vfs;
27 import iv.vfs.io;
29 import xiniz;
30 import xmodel;
31 import booktext;
34 // ////////////////////////////////////////////////////////////////////////// //
35 __gshared string RcDir = "~/.xreader";
36 __gshared string stateFileName;
38 shared static this () {
39 import std.path;
40 RcDir = RcDir.expandTilde.absolutePath;
41 //writeln(RcDir);
44 __gshared float shipAngle = 0;
45 __gshared bool showShip = false;
47 __gshared EliteModel shipModel;
50 // ////////////////////////////////////////////////////////////////////////// //
51 __gshared string textFontName = "~/ttf/ms/arial.ttf:noaa";
52 __gshared string textiFontName = "~/ttf/ms/ariali.ttf:noaa";
53 __gshared string textbFontName = "~/ttf/ms/arialbd.ttf:noaa";
54 __gshared string textzFontName = "~/ttf/ms/arialbi.ttf:noaa";
55 __gshared string monoFontName = "~/ttf/ms/cour.ttf:noaa";
56 __gshared string monoiFontName = "~/ttf/ms/couri.ttf:noaa";
57 __gshared string monobFontName = "~/ttf/ms/courbd.ttf:noaa";
58 __gshared string monozFontName = "~/ttf/ms/courbi.ttf:noaa";
59 __gshared string uiFontName = "~/ttf/ms/verdana.ttf:noaa";
60 __gshared string galmapFontName = "~/ttf/ms/verdana.ttf:noaa";
61 __gshared int GWidth = 900;
62 __gshared int GHeight = 1024;
63 __gshared int fsizeText = 24;
64 __gshared int fsizeUI = 16;
65 __gshared int fGalMapSize = 16;
66 __gshared bool sbLeft = false;
67 __gshared bool interAllowed = false;
69 __gshared bool flagNanoAA = false;
70 __gshared bool flagNanoSS = false;
72 __gshared NVGColor colorDim = NVGColor(0, 0, 0, 0);
73 __gshared NVGColor colorBack = NVGColor(0x2a, 0x2a, 0x2a);
74 __gshared NVGColor colorText = NVGColor(0xff, 0x7f, 0x00);
75 __gshared NVGColor colorTextHi = NVGColor(0xff, 0xff, 0x00);
76 __gshared NVGColor colorTextHref = NVGColor(0, 0, 0x80);
78 __gshared int uiFont, galmapFont;
79 __gshared int textFont, textiFont, textbFont, textzFont;
80 __gshared int monoFont, monoiFont, monobFont, monozFont;
82 __gshared bool optJustify = false;
85 // ////////////////////////////////////////////////////////////////////////// //
86 BookInfo[] loadDetailedHistory () {
87 BookInfo[] res;
88 try {
89 import std.path;
90 foreach (string line; VFile(buildPath(RcDir, ".lastfile")).byLineCopy) {
91 line = xstrip(line);
92 if (line.length == 0 || line[0] == '#' || line[0] == ';') continue;
93 try {
94 res ~= loadBookInfo(line);
95 res[$-1].diskfile = line.idup;
96 } catch (Exception) {}
98 } catch (Exception) {}
99 return res;
103 // ////////////////////////////////////////////////////////////////////////// //
104 __gshared string[] eliteShipFiles;
107 void loadEliteShips () {
108 import std.path;
109 import std.path : extension;
110 vfsAddPak(buildPath(RcDir, "eliteships.zip"), "oxm:");
111 //scope(exit) vfsRemovePack(buildPath(RcDir, "eliteships.zip"), "oxm:");
112 foreach (immutable idx, ref de; vfsFileList) {
113 //writeln("<", de.name, ">");
114 if (de.name.length > 4 && de.name[0..4] == "oxm:" && strEquCI(de.name.extension, ".oxm")) {
116 import core.memory : GC;
117 try {
118 auto mdl = new EliteModel(de.name);
119 mdl.freeData();
120 mdl.destroy;
121 //eliteShips ~= mdl;
122 eliteShipFiles ~= de.name;
123 } catch (Exception e) {}
124 GC.collect();
126 eliteShipFiles ~= de.name;
132 // ////////////////////////////////////////////////////////////////////////// //
133 VFile fwritef(A...) (VFile fl, string fmt, /*lazy*/ A args) {
134 import std.string : format;
135 auto s = format(fmt, args);
136 if (s.length) fl.rawWriteExact(s[]);
137 return fl;
141 // ////////////////////////////////////////////////////////////////////////// //
142 void readConfig () {
143 import std.path;
144 VFile fl;
145 try {
146 fl = VFile(buildPath(RcDir, ".config.ui"));
147 } catch (Exception) {
148 try {
149 try { import std.file; mkdirRecurse(RcDir); } catch (Exception) {}
150 fl = VFile(buildPath(RcDir, ".config.ui"), "w");
151 fl.fwritef("width=%s\n", GWidth);
152 fl.fwritef("height=%s\n", GHeight);
153 fl.fwritef("font-text=%s\n", textFontName);
154 fl.fwritef("font-text-italic=%s\n", textiFontName);
155 fl.fwritef("font-text-bold=%s\n", textbFontName);
156 fl.fwritef("font-text-bold-italic=%s\n", textzFontName);
157 fl.fwritef("font-mono=%s\n", monoFontName);
158 fl.fwritef("font-mono-italic=%s\n", monoiFontName);
159 fl.fwritef("font-mono-bold=%s\n", monobFontName);
160 fl.fwritef("font-mono-bold-italic=%s\n", monozFontName);
161 fl.fwritef("font-ui=%s\n", uiFontName);
162 fl.fwritef("font-galmap=%s\n", galmapFontName);
163 fl.fwritef("text-size=%s\n", fsizeText);
164 fl.fwritef("ui-text-size=%s\n", fsizeUI);
165 fl.fwritef("galmap-text-size=%s\n", fGalMapSize);
166 fl.fwritef("scrollbar-on-left=%s\n", sbLeft);
167 fl.fwritef("interference=%s\n", interAllowed);
168 fl.fwritef("color-dim=0x%08x\n", colorDim.asUintHtml);
169 fl.fwritef("color-back=0x%08x\n", colorBack.asUintHtml);
170 fl.fwritef("color-text=0x%08x\n", colorText.asUintHtml);
171 fl.fwritef("color-text-hi=0x%08x\n", colorTextHi.asUintHtml);
172 fl.fwritef("color-text-href=0x%08x\n", colorTextHref.asUintHtml);
173 fl.fwritef("nano-aa=%s\n", flagNanoAA);
174 fl.fwritef("nano-ss=%s\n", flagNanoSS);
175 fl.fwritef("justify-text=%s\n", optJustify);
176 } catch (Exception) {}
177 return;
179 xiniParse(fl,
180 "font-text", &textFontName,
181 "font-text-italic", &textiFontName,
182 "font-text-bold", &textbFontName,
183 "font-text-bold-italic", &textzFontName,
184 "font-text-italic-bold", &textzFontName,
185 "font-mono", &monoFontName,
186 "font-mono-italic", &monoiFontName,
187 "font-mono-bold", &monobFontName,
188 "font-mono-bold-italic", &monozFontName,
189 "font-mono-italic-bold", &monozFontName,
190 "font-ui", &uiFontName,
191 "font-galmap", &galmapFontName,
192 "width", &GWidth,
193 "height", &GHeight,
194 "text-size", &fsizeText,
195 "ui-text-size", &fsizeUI,
196 "galmap-text-size", &fGalMapSize,
197 "scrollbar-on-left", &sbLeft,
198 "interference", &interAllowed,
199 "color-dim", &colorDim,
200 "color-back", &colorBack,
201 "color-text", &colorText,
202 "color-text-hi", &colorTextHi,
203 "color-text-href", &colorTextHref,
204 "nano-aa", &flagNanoAA,
205 "nano-ss", &flagNanoSS,
206 "justify-text", &optJustify,
211 // ////////////////////////////////////////////////////////////////////////// //
212 bool isComment (const(char)[] s) {
213 while (s.length && s.ptr[0] <= ' ') s = s[1..$];
214 return (s.length > 0 && s.ptr[0] == '#');