diff --git a/cre.cpp b/cre.cpp index 7ec155d21..bde307520 100644 --- a/cre.cpp +++ b/cre.cpp @@ -57,9 +57,25 @@ static int openDocument(lua_State *L) { doc->text_view->LoadDocument(file_name); doc->text_view->Render(); + printf("gamma: %d\n", fontMan->GetGammaIndex()); + return 1; } +static int getGammaIndex(lua_State *L) { + lua_pushinteger(L, fontMan->GetGammaIndex()); + + return 1; +} + +static int setGammaIndex(lua_State *L) { + int index = luaL_checkint(L, 1); + + fontMan->SetGammaIndex(index); + + return 0; +} + static int closeDocument(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); delete doc->text_view; @@ -284,6 +300,8 @@ static int drawCurrentPage(lua_State *L) { static const struct luaL_Reg cre_func[] = { {"openDocument", openDocument}, {"getFontFaces", getFontFaces}, + {"getGammaIndex", getGammaIndex}, + {"setGammaIndex", setGammaIndex}, {NULL, NULL} }; diff --git a/crereader.lua b/crereader.lua index 55196c265..ba1d77e86 100644 --- a/crereader.lua +++ b/crereader.lua @@ -6,6 +6,7 @@ CREReader = UniReader:new{ pos = 0, percent = 0, + gamma_index = 15, font_face = nil, } @@ -36,10 +37,15 @@ function CREReader:loadSpecialSettings() local font_face = self.settings:readSetting("font_face") self.font_face = font_face or "FreeSerif" self.doc:setFontFace(self.font_face) + + local gamma_index = self.settings:readSetting("gamma_index") + self.gamma_index = gamma_index or self.gamma_index + cre.setGammaIndex(self.gamma_index) end function CREReader:saveSpecialSettings() self.settings:savesetting("font_face", self.font_face) + self.settings:savesetting("gamma_index", self.gamma_index) end function CREReader:getLastPageOrPos() @@ -60,6 +66,7 @@ function CREReader:setzoom(page, preCache) end function CREReader:addJump(pos, notes) + return end function CREReader:goto(pos) @@ -196,4 +203,20 @@ function CREReader:adjustCreReaderCommands() cr:redrawCurrentPage() end ) + self.commands:add(KEY_VPLUS, nil, "vol+", + "increase gamma", + function(cr) + cre.setGammaIndex(self.gamma_index + 1) + self.gamma_index = cre.getGammaIndex() + cr:redrawCurrentPage() + end + ) + self.commands:add(KEY_VMINUS, nil, "vol-", + "decrease gamma", + function(cr) + cre.setGammaIndex(self.gamma_index - 1) + self.gamma_index = cre.getGammaIndex() + cr:redrawCurrentPage() + end + ) end