Implement a policy of marking DFHack-owned screens with a signature.

develop
Alexander Gavrilov 2012-08-22 12:28:01 +04:00
parent 8969fc9435
commit 2b79582e99
5 changed files with 33 additions and 2 deletions

@ -1211,6 +1211,8 @@ The screen module implements support for drawing to the tiled screen of the game
Note that drawing only has any effect when done from callbacks, so it can only
be feasibly used in the core context.
Basic painting functions:
* ``dfhack.screen.getWindowSize()``
Returns *width, height* of the screen.
@ -1277,7 +1279,12 @@ be feasibly used in the core context.
In order to actually be able to paint to the screen, it is necessary
to create and register a viewscreen (basically a modal dialog) with
the game. Screens are managed with the following functions:
the game.
**NOTE**: As a matter of policy, in order to avoid user confusion, all
interface screens added by dfhack should bear the "DFHack" signature.
Screens are managed with the following functions:
* ``dfhack.screen.show(screen[,below])``

@ -1391,6 +1391,7 @@ Returns <em>true, was_only_planned</em> if removed; or <em>false</em> if none fo
<p>The screen module implements support for drawing to the tiled screen of the game.
Note that drawing only has any effect when done from callbacks, so it can only
be feasibly used in the core context.</p>
<p>Basic painting functions:</p>
<ul>
<li><p class="first"><tt class="docutils literal">dfhack.screen.getWindowSize()</tt></p>
<p>Returns <em>width, height</em> of the screen.</p>
@ -1455,7 +1456,10 @@ functions in this section, this may be used at any time.</p>
</ul>
<p>In order to actually be able to paint to the screen, it is necessary
to create and register a viewscreen (basically a modal dialog) with
the game. Screens are managed with the following functions:</p>
the game.</p>
<p><strong>NOTE</strong>: As a matter of policy, in order to avoid user confusion, all
interface screens added by dfhack should bear the &quot;DFHack&quot; signature.</p>
<p>Screens are managed with the following functions:</p>
<ul>
<li><p class="first"><tt class="docutils literal"><span class="pre">dfhack.screen.show(screen[,below])</span></tt></p>
<p>Displays the given screen, possibly placing it below a different one.

@ -245,9 +245,18 @@ end
-- Framed screen object --
------------------------
-- Plain grey-colored frame.
GREY_FRAME = {
frame_pen = { ch = ' ', fg = COLOR_BLACK, bg = COLOR_GREY },
title_pen = { fg = COLOR_BLACK, bg = COLOR_WHITE },
signature_pen = { fg = COLOR_BLACK, bg = COLOR_GREY },
}
-- The usual boundary used by the DF screens. Often has fancy pattern in tilesets.
BOUNDARY_FRAME = {
frame_pen = { ch = 0xDB, fg = COLOR_DARKGREY, bg = COLOR_BLACK },
title_pen = { fg = COLOR_BLACK, bg = COLOR_GREY },
signature_pen = { fg = COLOR_BLACK, bg = COLOR_DARKGREY },
}
function paint_frame(x1,y1,x2,y2,style,title)
@ -260,6 +269,7 @@ function paint_frame(x1,y1,x2,y2,style,title)
dscreen.fillRect(style.b_frame_pen or style.h_frame_pen or pen,x1+1,y2,x2-1,y2)
dscreen.fillRect(style.l_frame_pen or style.v_frame_pen or pen,x1,y1+1,x1,y2-1)
dscreen.fillRect(style.r_frame_pen or style.v_frame_pen or pen,x2,y1+1,x2,y2-1)
dscreen.paintString(style.signature_pen or style.title_pen or pen,x2-7,y2,"DFHack")
if title then
local x = math.max(0,math.floor((x2-x1-3-#title)/2)) + x1

@ -163,6 +163,12 @@ function MenuOverlay:onRender()
local menu = self.df_layout.menu
if menu then
-- Paint signature on the frame.
dscreen.paintString(
{fg=COLOR_BLACK,bg=COLOR_DARKGREY},
menu.x1+1, menu.y2+1, "DFHack"
)
self:onRenderBody(gui.Painter.new(menu))
end
end

@ -158,6 +158,7 @@ bool Screen::drawBorder(const std::string &title)
int dimx = gps->dimx, dimy = gps->dimy;
Pen border(0xDB, 8);
Pen text(0, 0, 7);
Pen signature(0, 0, 8);
for (int x = 0; x < dimx; x++)
{
@ -169,6 +170,9 @@ bool Screen::drawBorder(const std::string &title)
doSetTile(border, 0 * dimy + y);
doSetTile(border, (dimx - 1) * dimy + y);
}
paintString(signature, dimx-8, dimy-1, "DFHack");
return paintString(text, (dimx - title.length()) / 2, 0, title);
}