-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f1dacd
commit d981bbc
Showing
6 changed files
with
75 additions
and
45 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
local util_decorator = require('src/lib/util/decorator') | ||
|
||
local deafult_font_name = 'Tiresias' | ||
local previous_font_name = deafult_font_name | ||
local previous_font_size = 9 | ||
local current_font_name = deafult_font_name | ||
local current_font_size = 8 | ||
|
||
local function apply_font() | ||
previous_font_name = current_font_name | ||
previous_font_size = current_font_size | ||
canvas:attrFont(current_font_name, current_font_size) | ||
end | ||
|
||
local function text_print(std, engine, canvas, pos_x, pos_y, text) | ||
if previous_font_name ~= current_font_name or previous_font_size ~= current_font_size then | ||
apply_font() | ||
end | ||
|
||
local x = engine.offset_x + pos_x | ||
local y = engine.offset_y + pos_y | ||
canvas:drawText(x, y, text) | ||
end | ||
|
||
local function text_mensure(canvas, text) | ||
apply_font() | ||
local w, h = canvas:measureText(text) | ||
return w, h | ||
end | ||
|
||
local function font_size(std, engine, size) | ||
current_font_size = size | ||
end | ||
|
||
local function font_name(std, engine, name) | ||
current_font_name = name | ||
end | ||
|
||
local function font_default(std, engine, font_id) | ||
current_font_name = deafult_font_name | ||
end | ||
|
||
local function font_previous() | ||
current_font_name = previous_font_name | ||
current_font_size = previous_font_size | ||
canvas:attrFont(current_font_name, current_font_size) | ||
end | ||
|
||
local function install(std, engine) | ||
std.text = std.text or {} | ||
std.text.print = util_decorator.prefix3(std, engine, engine.canvas, text_print) | ||
std.text.font_size = util_decorator.prefix2(std, engine, font_size) | ||
std.text.font_name = util_decorator.prefix2(std, engine, font_name) | ||
std.text.font_default = util_decorator.prefix2(std, engine, font_default) | ||
std.text.mensure = util_decorator.prefix1(canvas, text_mensure) | ||
end | ||
|
||
local P = { | ||
install=install, | ||
font_previous=font_previous | ||
} | ||
|
||
return P |
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
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
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