diff --git a/ee/engine/core/ginga/draw.lua b/ee/engine/core/ginga/draw.lua index b6bd3e7..004b736 100644 --- a/ee/engine/core/ginga/draw.lua +++ b/ee/engine/core/ginga/draw.lua @@ -1,10 +1,6 @@ local math = require('math') local util_decorator = require('src/lib/util/decorator') -local deafult_font_name = 'Tiresias' -local current_font_name = deafult_font_name -local current_font_size = 8 - local function color(std, engine, canvas, tint) local c = tint local R = math.floor(c/0x1000000) @@ -29,37 +25,6 @@ local function rect(std, engine, canvas, mode, pos_x, pos_y, width, height) canvas:drawRect(mode == 0 and 'fill' or 'frame', x, y, width, height) end -local function text(std, engine, canvas, pos_x, pos_y, text) - if pos_x and pos_y then - local x = engine.offset_x + pos_x - local y = engine.offset_y + pos_y - canvas:drawText(x, y, text) - end - return canvas:measureText(text or pos_x) -end - -local function tui_text(std, engine, canvas, pos_x, pos_y, size, text) - local hem = engine.current.data.width / 80 - local vem = engine.current.data.height / 24 - local x = engine.offset_x + (pos_x * hem) - local y = engine.offset_y + (pos_y * vem) - local font_size = hem * size - - canvas:attrFont(current_font_name, font_size) - canvas:drawText(x, y, text) - canvas:attrFont(current_font_name, current_font_size) -end - -local function font(std, engine, canvas, name, size) - if type(name) == 'number' and not size then - size = name - name = current_font_name - end - current_font_name = name - current_font_size = size - canvas:attrFont(name, size) -end - local function line(std, engine, canvas, x1, y1, x2, y2) local ox = engine.offset_x local oy = engine.offset_y @@ -82,21 +47,13 @@ local function image(std, engine, canvas, src, pos_x, pos_y) end local function install(std, engine) - std = std or {} std.draw = std.draw or {} std.draw.image = util_decorator.prefix3(std, engine, engine.canvas, image) std.draw.clear = util_decorator.prefix3(std, engine, engine.canvas, clear) std.draw.color = util_decorator.prefix3(std, engine, engine.canvas, color) std.draw.rect = util_decorator.prefix3(std, engine, engine.canvas, rect) - std.draw.text = util_decorator.prefix3(std, engine, engine.canvas, text) - std.draw.font = util_decorator.prefix3(std, engine, engine.canvas, font) std.draw.line = util_decorator.prefix3(std, engine, engine.canvas, line) - std.text.put = util_decorator.prefix3(std, engine, engine.canvas, tui_text) - - return { - draw=std.draw - } end local P = { diff --git a/ee/engine/core/ginga/main.lua b/ee/engine/core/ginga/main.lua index de105cb..f15ff96 100644 --- a/ee/engine/core/ginga/main.lua +++ b/ee/engine/core/ginga/main.lua @@ -1,6 +1,7 @@ local zeebo_module = require('src/lib/common/module') -- local core_draw = require('ee/engine/core/ginga/draw') +local core_text = require('ee/engine/core/ginga/text') local core_keys = require('ee/engine/core/ginga/keys') -- local engine_encoder = require('src/lib/engine/api/encoder') @@ -12,6 +13,7 @@ local engine_keys = require('src/lib/engine/api/key') local engine_math = require('src/lib/engine/api/math') local engine_draw_ui = require('src/lib/engine/draw/ui') local engine_draw_fps = require('src/lib/engine/draw/fps') +local engine_draw_text = require('src/lib/engine/draw/text') local engine_draw_poly = require('src/lib/engine/draw/poly') local engine_bus = require('src/lib/engine/raw/bus') local engine_fps = require('src/lib/engine/raw/fps') @@ -68,6 +70,10 @@ local cfg_fps_control = { uptime=event.uptime } +local cfg_text = { + font_previous = core_text.font_previous +} + local system_language = function() return 'pt-BR' end @@ -107,6 +113,8 @@ local function install(evt, gamefile) :package('@keys1', engine_keys) :package('@keys2', core_keys) :package('@draw', core_draw) + :package('@draw.text', core_text) + :package('@draw.text2', engine_draw_text, cfg_text) :package('@draw.ui', engine_draw_ui) :package('@draw.fps', engine_draw_fps) :package('@draw.poly', engine_draw_poly, cfg_poly) diff --git a/ee/engine/core/ginga/text.lua b/ee/engine/core/ginga/text.lua new file mode 100644 index 0000000..d607d10 --- /dev/null +++ b/ee/engine/core/ginga/text.lua @@ -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 diff --git a/src/engine/core/love/text.lua b/src/engine/core/love/text.lua index 94cdd8f..000b999 100644 --- a/src/engine/core/love/text.lua +++ b/src/engine/core/love/text.lua @@ -30,7 +30,6 @@ end local function install(std, engine) std.text = std.text or {} - std.text.put = util_decorator.prefix2(std, engine, text_put) std.text.print = util_decorator.prefix2(std, engine, text_print) std.text.font_size = util_decorator.prefix2(std, engine, font_size) std.text.font_name = util_decorator.prefix2(std, engine, function() end) diff --git a/src/lib/engine/draw/text.lua b/src/lib/engine/draw/text.lua index 38197bc..2574705 100644 --- a/src/lib/engine/draw/text.lua +++ b/src/lib/engine/draw/text.lua @@ -56,6 +56,9 @@ local util_decorator = require('src/lib/util/decorator') --! @short std.text.put --! @renamefunc put +--! @hideparam std +--! @hideparam engine +--! @hideparam font_previous --! @brief print text grid in based 80x24 --! @par Example --! @code{.java} diff --git a/src/lib/object/std.lua b/src/lib/object/std.lua index aa60833..0396e2c 100644 --- a/src/lib/object/std.lua +++ b/src/lib/object/std.lua @@ -22,7 +22,7 @@ local P = { mensure = function() end, font_size = function() end, font_name = function() end, - font_defaullt = function() end + font_default = function() end }, app = { width = 1280,