Created
July 21, 2016 20:19
-
-
Save jerstlouis/40436aa5832ed1f90bfd9b521407179d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "ecere" | |
SyntaxColorScheme colorScheme | |
{ | |
keywordColors = [ skyBlue, skyBlue ]; | |
commentColor = Color { 125, 125, 125 }; | |
charLiteralColor = Color { 245, 50, 245 }; | |
stringLiteralColor = Color { 245, 50, 245 }; | |
preprocessorColor = { 120, 220, 140 }; | |
numberColor = Color { 0, 192, 192 }; | |
}; | |
Array<float> sizes { [ 6, 7, 8.25f, 9, 10, 10.5f, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30, 32, 36, 40, 44, 48, 54, 60, 66, 72, 80, 88, 96 ] }; | |
Array<const String> fonts | |
{ [ | |
"Bitstream Vera Sans Mono", | |
"Consolas", | |
"Courier New", | |
"DejaVu Sans Mono", | |
"Lucida Console", | |
"Monaco", | |
"Monoid", | |
"OCR-A II", | |
"OCR B MT" | |
// "Terminal" | |
] }; | |
const String sampleText = "The Quick Brown Fox Jumps Over The Lazy Dog"; | |
Array<FontResource> fontResources { }; | |
class DisplayedFace : FontResource | |
{ | |
void OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags) | |
{ | |
surface.font = font; | |
faceName.OnDisplay(surface, x, y, width, fieldData, alignment, displayFlags); | |
} | |
}; | |
class FontDialog : Window | |
{ | |
caption = $"Font Picker"; | |
background = formColor; | |
borderStyle = sizable; | |
hasMaximize = true; | |
hasMinimize = true; | |
hasClose = true; | |
size = { 664, 426 }; | |
anchor = { horz = 9, vert = -26 }; | |
void loadText() | |
{ | |
File f = FileOpen("fontDialog.ec", read); | |
if(f) | |
{ | |
int size = f.GetSize(); | |
char * t = new char[size + 1]; | |
f.Read(t, 1, size); | |
t[size] = 0; | |
delete f; | |
sample.contents = t; | |
delete t; | |
} | |
} | |
FontResource curFont { "Consolas", 12}; | |
DataField dfSize { class(float) }; | |
DropBox dbSize | |
{ | |
this, caption = $"dropBox1", size = { 56, 24 }, anchor = { left = 16, bottom = 14 }; | |
bool NotifySelect(DropBox dropBox, DataRow row, Modifiers mods) | |
{ | |
curFont.size = row.GetData(dfSize); | |
for(f : fontResources) | |
{ | |
RemoveResource(f); | |
f.size = Min(20, curFont.size); | |
AddResource(f); | |
} | |
listFonts.font = fontResources[0]; | |
OnLoadGraphics(); | |
listFonts.OnLoadGraphics(); | |
listFonts.size = listFonts.size; // Fix for scrollbar? | |
listFonts.Update(null); | |
sample.font = curFont; | |
return true; | |
} | |
}; | |
EditBox sample | |
{ | |
this, anchor = { left = 0.439024, top = 16, right = 18, bottom = 0.464824 }, contents = sampleText, font = curFont; | |
textVertScroll = true; | |
hasVertScroll = true; | |
hasHorzScroll = true; | |
freeCaret = true; | |
syntaxHighlighting = true; | |
syntaxColorScheme = colorScheme; | |
foreground = ivory; | |
selectionText = Color { 30, 40, 50 }; | |
background = black; | |
selectionColor = lightYellow; | |
multiLine = true; | |
}; | |
ListBox listFonts | |
{ | |
this, anchor = { left = 16, top = 16, right = 0.591463, bottom = 58 }, alwaysHighLight = true; | |
hasVertScroll = true; | |
dontHideScroll = true; | |
bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods) | |
{ | |
if(row) | |
{ | |
FontResource fr = row.GetData(dfFace); | |
curFont.faceName = fr.faceName; | |
} | |
sample.font = curFont; | |
return true; | |
} | |
}; | |
DataField dfFace { class(DisplayedFace) }; | |
bool OnLoadGraphics() | |
{ | |
int maxH = 12; | |
for(f : fontResources) | |
{ | |
Font font = f.font; | |
int h; | |
displaySystem.FontExtent(font, "W", 1, null, &h); | |
//int h = font.ascent + font.descent; | |
maxH = Max(maxH, h + 5); | |
} | |
listFonts.rowHeight = maxH; | |
return true; | |
} | |
FontDialog() | |
{ | |
loadText(); | |
dbSize.AddField(dfSize); | |
for(s : sizes) | |
{ | |
DataRow row = dbSize.AddRow(); | |
row.SetData(dfSize, s); | |
if(s == curFont.size) | |
dbSize.currentRow = row; | |
} | |
listFonts.AddField(dfFace); | |
fontResources.minAllocSize = fonts.size; | |
for(f : fonts) | |
{ | |
FontResource fr { f, curFont.size, window = this }; | |
DataRow row = listFonts.AddRow(); | |
incref fr; | |
row.SetData(dfFace, fr); | |
if(!strcmp(f, curFont.faceName)) | |
listFonts.currentRow = row; | |
fontResources.Add(fr); | |
} | |
btnBold.checked = curFont.bold; | |
btnItalic.checked = curFont.italic; | |
btnUnderline.checked = curFont.underline; | |
} | |
Button btnBold | |
{ | |
this, caption = "B", font = { "Bitstream Vera Serif", 10, bold = true }, size = { 29, 24 }, anchor = { left = 80, bottom = 14 }, toggle = true; | |
bool NotifyClicked(Button button, int x, int y, Modifiers mods) | |
{ | |
curFont.bold = button.checked; | |
sample.font = curFont; | |
return true; | |
} | |
}; | |
Button btnItalic | |
{ | |
this, caption = "I", font = { "Bitstream Vera Serif", 10, italic = true }, size = { 29, 24 }, anchor = { left = 112, bottom = 14 }, toggle = true; | |
bool NotifyClicked(Button button, int x, int y, Modifiers mods) | |
{ | |
curFont.italic = button.checked; | |
sample.font = curFont; | |
return true; | |
} | |
}; | |
Button btnUnderline | |
{ | |
this, caption = "U", font = { "Bitstream Vera Serif", 10, underline = true }, size = { 29, 24 }, anchor = { left = 144, bottom = 14 }, toggle = true; | |
bool NotifyClicked(Button button, int x, int y, Modifiers mods) | |
{ | |
curFont.underline = button.checked; | |
sample.font = curFont; | |
return true; | |
} | |
}; | |
Button btnOpenGL | |
{ | |
this, caption = "OpenGL", font = { "Bitstream Vera Serif", 10, bold = true }, size = { w = 80, h = 24 }, anchor = { left = 190, bottom = 14 }, toggle = true; | |
bool NotifyClicked(Button button, int x, int y, Modifiers mods) | |
{ | |
size = size; | |
position = position; | |
Destroy(0); | |
displayDriver = button.checked ? "OpenGL" : "Default"; | |
Create(); | |
return true; | |
} | |
}; | |
} | |
FontDialog fontDialog {}; | |
/* | |
Color selectionColor = lightYellow; | |
Color selectionText = Color { 30, 40, 50 }; | |
Color viewsBackground = Color { 30, 40, 50 }; | |
Color viewsText = lightGray; | |
Color outputBackground = black; | |
Color outputText = lime; | |
Color projectViewBackground = Color { 30, 40, 50 }; | |
Color projectViewText = lightGray; | |
Color codeEditorBG = black; | |
Color codeEditorFG = ivory; | |
Color marginColor = Color {24, 24, 24}; | |
Color selectedMarginColor = Color {64, 64, 64}; | |
Color lineNumbersColor = Color {160, 160, 160}; | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment