Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes

StoryBookWindow Struct Reference

Inheritance diagram for StoryBookWindow:
Window ZeroedMemoryAllocator

Public Member Functions

 StoryBookWindow (WindowDesc *desc, WindowNumber window_number)
void UpdatePrevNextDisabledState ()
 Updates the disabled state of the prev/next buttons.
void SetSelectedPage (uint16 page_index)
 Sets the selected page.
virtual void SetStringParameters (int widget) const
 Initialize string parameters for a widget.
virtual void OnPaint ()
 The window must be repainted.
virtual void DrawWidget (const Rect &r, int widget) const
 Draw the contents of a nested widget.
virtual void UpdateWidgetSize (int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 Update size and resize step of a widget in the window.
virtual void OnResize ()
 Called after the window got resized.
virtual void OnClick (Point pt, int widget, int click_count)
 A click with the left mouse button has been made on the window.
virtual void OnDropdownSelect (int widget, int index)
 A dropdown option associated to this window has been selected.
virtual void OnInvalidateData (int data=0, bool gui_scope=true)
 Some data on this window has become invalid.

Protected Member Functions

void BuildStoryPageList ()
 (Re)Build story page list.
void BuildStoryPageElementList ()
 (Re)Build story page element list.
bool IsPageAvailable (const StoryPage *page) const
StoryPageGetSelPage () const
 Get instance of selected page.
int GetSelPageNum () const
 Get the page number of selected page.
bool IsFirstPageSelected ()
 Check if the selected page is also the first available page.
bool IsLastPageSelected ()
 Check if the selected page is also the last available page.
void RefreshSelectedPage ()
 Updates the content of selected page.
void SelectPrevPage ()
 Selects the previous available page before the currently selected page.
void SelectNextPage ()
 Selects the next available page after the currently selected page.
DropDownListBuildDropDownList () const
 Builds the page selector drop down list.
uint GetAvailablePageContentWidth ()
 Get the width available for displaying content on the page panel.
uint GetHeadHeight (int max_width) const
 Counts how many pixels of height that are used by Date and Title (excluding marginal after Title, as each body element has an empty row before the elment).
SpriteID GetPageElementSprite (const StoryPageElement &pe) const
 Decides which sprite to display for a given page element.
uint GetPageElementHeight (const StoryPageElement &pe, int max_width)
 Get the height in pixels used by a page element.
uint GetContentHeight ()
 Get the total height of the content displayed in this window.
void DrawActionElement (int &y_offset, int width, int line_height, SpriteID action_sprite, StringID string_id=STR_JUST_RAW_STRING) const
 Draws a page element that is composed of a sprite to the left and a single line of text after that.
void OnPageElementClick (const StoryPageElement &pe)
 Internal event handler for when a page element is clicked.

Static Protected Member Functions

static int CDECL PageOrderSorter (const StoryPage *const *a, const StoryPage *const *b)
 Sort story pages by order value.
static int CDECL PageElementOrderSorter (const StoryPageElement *const *a, const StoryPageElement *const *b)
 Sort story page elements by order value.

Protected Attributes

Scrollbarvscroll
 Scrollbar of the page text.
GUIStoryPageList story_pages
 Sorted list of pages.
GUIStoryPageElementList story_page_elements
 Sorted list of page elements that belong to the current page.
StoryPageID selected_page_id
 Pool index of selected page.
char selected_generic_title [255]
 If the selected page doesn't have a custom title, this buffer is used to store a generic page title.

Static Protected Attributes

static
GUIStoryPageList::SortFunction
*const 
page_sorter_funcs []
static
GUIStoryPageElementList::SortFunction
*const 
page_element_sorter_funcs []

Detailed Description

Definition at line 37 of file story_gui.cpp.


Member Function Documentation

void StoryBookWindow::BuildStoryPageList (  )  [inline, protected]
void StoryBookWindow::DrawActionElement ( int &  y_offset,
int  width,
int  line_height,
SpriteID  action_sprite,
StringID  string_id = STR_JUST_RAW_STRING 
) const [inline, protected]

Draws a page element that is composed of a sprite to the left and a single line of text after that.

These page elements are generally clickable and are thus called action elements.

Parameters:
y_offset Current y_offset which will get updated when this method has completed its drawing.
width Width of the region available for drawing.
line_height Height of one line of text.
action_sprite The sprite to draw.
string_id The string id to draw.
Returns:
the number of lines.

Definition at line 374 of file story_gui.cpp.

References DrawSprite(), DrawString(), GetSpriteSize(), max(), and WD_FRAMETEXT_LEFT.

Referenced by DrawWidget().

virtual void StoryBookWindow::DrawWidget ( const Rect r,
int  widget 
) const [inline, virtual]
uint StoryBookWindow::GetContentHeight (  )  [inline, protected]

Get the total height of the content displayed in this window.

Returns:
the height in pixels

Definition at line 343 of file story_gui.cpp.

References SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), GetAvailablePageContentWidth(), GetHeadHeight(), GetPageElementHeight(), GetSelPage(), Window::height, and story_page_elements.

Referenced by OnPaint(), OnResize(), and RefreshSelectedPage().

uint StoryBookWindow::GetHeadHeight ( int  max_width  )  const [inline, protected]

Counts how many pixels of height that are used by Date and Title (excluding marginal after Title, as each body element has an empty row before the elment).

Parameters:
max_width Available width to display content.
Returns:
the height in pixels.

Definition at line 277 of file story_gui.cpp.

References GetSelPage(), GetStringHeight(), Window::height, SetDParamStr(), and StoryPage::title.

Referenced by GetContentHeight(), and OnClick().

uint StoryBookWindow::GetPageElementHeight ( const StoryPageElement pe,
int  max_width 
) [inline, protected]

Get the height in pixels used by a page element.

Parameters:
pe The story page element.
max_width Available width to display content.
Returns:
the height in pixels.

Definition at line 318 of file story_gui.cpp.

References GetPageElementSprite(), GetSpriteSize(), GetStringHeight(), SetDParamStr(), SPET_GOAL, SPET_LOCATION, SPET_TEXT, StoryPageElement::text, and StoryPageElement::type.

Referenced by GetContentHeight(), and OnClick().

SpriteID StoryBookWindow::GetPageElementSprite ( const StoryPageElement pe  )  const [inline, protected]

Decides which sprite to display for a given page element.

Parameters:
pe The page element.
Returns:
The SpriteID of the sprite to display.
Precondition:
pe.type must be SPET_GOAL or SPET_LOCATION.

Definition at line 297 of file story_gui.cpp.

References Goal::completed, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_goal_pool >::Get(), StoryPageElement::referenced_id, SPET_GOAL, SPET_LOCATION, and StoryPageElement::type.

Referenced by DrawWidget(), and GetPageElementHeight().

StoryPage* StoryBookWindow::GetSelPage (  )  const [inline, protected]
int StoryBookWindow::GetSelPageNum (  )  const [inline, protected]

Get the page number of selected page.

Returns:
Number of available pages before to the selected one, or -1 if no page is selected.

Definition at line 128 of file story_gui.cpp.

References SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, and story_pages.

Referenced by RefreshSelectedPage().

virtual void StoryBookWindow::OnClick ( Point  pt,
int  widget,
int  click_count 
) [inline, virtual]
virtual void StoryBookWindow::OnDropdownSelect ( int  widget,
int  index 
) [inline, virtual]

A dropdown option associated to this window has been selected.

Parameters:
widget the widget (button) that the dropdown is associated with.
index the element in the dropdown that is selected.

Reimplemented from Window.

Definition at line 666 of file story_gui.cpp.

References SetSelectedPage(), and WID_SB_SEL_PAGE.

virtual void StoryBookWindow::OnInvalidateData ( int  data = 0,
bool  gui_scope = true 
) [inline, virtual]

Some data on this window has become invalid.

Parameters:
data Information about the changed data. -1 Rebuild page list and refresh current page; >= 0 Id of the page that needs to be refreshed. If it is not the current page, nothing happens.
gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See InvalidateWindowData() for details.

Reimplemented from Window.

Definition at line 681 of file story_gui.cpp.

References BuildStoryPageList(), GUIList< T, F >::ForceRebuild(), INVALID_STORY_PAGE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::IsValidID(), SmallVector< T, S >::Length(), RefreshSelectedPage(), selected_generic_title, selected_page_id, SetSelectedPage(), Window::SetWidgetDirty(), Window::SetWidgetDisabledState(), story_pages, UpdatePrevNextDisabledState(), and WID_SB_SEL_PAGE.

void StoryBookWindow::OnPageElementClick ( const StoryPageElement pe  )  [inline, protected]

Internal event handler for when a page element is clicked.

Parameters:
pe The clicked page element.

Definition at line 392 of file story_gui.cpp.

References _ctrl_pressed, StoryPageElement::referenced_id, ScrollMainWindowToTile(), ShowExtraViewPortWindow(), ShowGoalsList(), SPET_GOAL, SPET_LOCATION, SPET_TEXT, StoryPageElement::type, and Window::window_number.

Referenced by OnClick().

virtual void StoryBookWindow::OnPaint (  )  [inline, virtual]

The window must be repainted.

Note:
This method should not change any state, it should only use drawing functions.

Reimplemented from Window.

Definition at line 483 of file story_gui.cpp.

References Window::DrawWidgets(), GetContentHeight(), Scrollbar::GetCount(), Scrollbar::SetCount(), Window::SetWidgetDirty(), vscroll, WID_SB_PAGE_PANEL, and WID_SB_SCROLLBAR.

virtual void StoryBookWindow::OnResize (  )  [inline, virtual]

Called after the window got resized.

For nested windows with a viewport, call NWidgetViewport::UpdateViewportCoordinates.

Reimplemented from Window.

Definition at line 605 of file story_gui.cpp.

References GetContentHeight(), Scrollbar::SetCapacityFromWidget(), Scrollbar::SetCount(), vscroll, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_TOP, and WID_SB_PAGE_PANEL.

static int CDECL StoryBookWindow::PageElementOrderSorter ( const StoryPageElement *const *  a,
const StoryPageElement *const *  b 
) [inline, static, protected]

Sort story page elements by order value.

Definition at line 99 of file story_gui.cpp.

static int CDECL StoryBookWindow::PageOrderSorter ( const StoryPage *const *  a,
const StoryPage *const *  b 
) [inline, static, protected]

Sort story pages by order value.

Definition at line 70 of file story_gui.cpp.

void StoryBookWindow::SetSelectedPage ( uint16  page_index  )  [inline]

Sets the selected page.

Parameters:
page_index pool index of the page to select.

Definition at line 455 of file story_gui.cpp.

References RefreshSelectedPage(), selected_page_id, and UpdatePrevNextDisabledState().

Referenced by OnDropdownSelect(), OnInvalidateData(), SelectNextPage(), and SelectPrevPage().

virtual void StoryBookWindow::SetStringParameters ( int  widget  )  const [inline, virtual]

Initialize string parameters for a widget.

Calls to this function are made during initialization to measure the size (that is as part of InitNested()), during drawing, and while re-initializing the window. Only for widgets that render text initializing is requested.

Parameters:
widget Widget number.

Reimplemented from Window.

Definition at line 464 of file story_gui.cpp.

References GetSelPage(), INVALID_COMPANY, SetDParam(), SetDParamStr(), StoryPage::title, WID_SB_CAPTION, and WID_SB_SEL_PAGE.

virtual void StoryBookWindow::UpdateWidgetSize ( int  widget,
Dimension size,
const Dimension padding,
Dimension fill,
Dimension resize 
) [inline, virtual]

Update size and resize step of a widget in the window.

After retrieval of the minimal size and the resize-steps of a widget, this function is called to allow further refinement, typically by computing the real maximal size of the content. Afterwards, size is taken to be the minimal size of the widget and resize is taken to contain the resize steps. For the convenience of the callee, padding contains the amount of padding between the content and the edge of the widget. This should be added to the returned size.

Parameters:
widget Widget number.
size Size of the widget.
padding Recommended amount of space between the widget content and the widget edge.
fill Fill step of the widget.
resize Resize step of the widget.

Reimplemented from Window.

Definition at line 562 of file story_gui.cpp.

References GetStringBoundingBox(), SmallVector< T, S >::Length(), maxdim(), selected_generic_title, SetDParamStr(), story_pages, StoryPage::title, WD_FRAMETEXT_TOP, WID_SB_PAGE_PANEL, and WID_SB_SEL_PAGE.


Field Documentation

GUIStoryPageElementList::SortFunction *const StoryBookWindow::page_element_sorter_funcs [static, protected]
Initial value:
 {
  &PageElementOrderSorter,
}

Definition at line 47 of file story_gui.cpp.

GUIStoryPageList::SortFunction *const StoryBookWindow::page_sorter_funcs [static, protected]
Initial value:
 {
  &PageOrderSorter,
}

Definition at line 46 of file story_gui.cpp.


The documentation for this struct was generated from the following file: