OpenTTD Source 20241224-master-gf74b0cf984
CargoesField Struct Reference

Data about a single field in the IndustryCargoesWindow panel. More...

Public Types

using Cargoes = uint16_t
 

Public Member Functions

void MakeEmpty (CargoesFieldType type)
 Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).
 
void MakeIndustry (IndustryType ind_type)
 Make an industry type field.
 
int ConnectCargo (CargoID cargo, bool producer)
 Connect a cargo from an industry to the CFT_CARGO column.
 
bool HasConnection ()
 Does this CFT_CARGO field have a horizontal connection?
 
void MakeCargo (const std::span< const CargoID > cargoes)
 Make a piece of cargo column.
 
void MakeCargoLabel (const std::span< const CargoID > cargoes, bool left_align)
 Make a field displaying cargo type names.
 
void MakeHeader (StringID textid)
 Make a header above an industry column.
 
int GetCargoBase (int xpos) const
 For a CFT_CARGO, compute the left position of the left-most vertical cargo connection.
 
void Draw (int xpos, int ypos) const
 Draw the field.
 
CargoID CargoClickedAt (const CargoesField *left, const CargoesField *right, Point pt) const
 Decide which cargo was clicked at in a CFT_CARGO field.
 
CargoID CargoLabelClickedAt (Point pt) const
 Decide what cargo the user clicked in the cargo label field.
 

Data Fields

CargoesFieldType type
 Type of field.
 
union { 
 
   struct { 
 
      IndustryType   ind_type 
 Industry type (NUM_INDUSTRYTYPES means 'houses'). More...
 
      CargoID   other_produced [MAX_CARGOES
 Cargoes produced but not used in this figure. More...
 
      CargoID   other_accepted [MAX_CARGOES
 Cargoes accepted but not used in this figure. More...
 
   }   industry 
 Industry data (for CFT_INDUSTRY).
 
   struct { 
 
      CargoID   vertical_cargoes [MAX_CARGOES
 Cargoes running from top to bottom (cargo ID or INVALID_CARGO). More...
 
      Cargoes   supp_cargoes 
 Cargoes in vertical_cargoes entering from the left. More...
 
      Cargoes   cust_cargoes 
 Cargoes in vertical_cargoes leaving to the right. More...
 
      uint8_t   num_cargoes 
 Number of cargoes. More...
 
      uint8_t   top_end 
 Stop at the top of the vertical cargoes. More...
 
      uint8_t   bottom_end 
 Stop at the bottom of the vertical cargoes. More...
 
   }   cargo 
 Cargo data (for CFT_CARGO).
 
   struct { 
 
      CargoID   cargoes [MAX_CARGOES
 Cargoes to display (or INVALID_CARGO). More...
 
      bool   left_align 
 Align all cargo texts to the left (else align to the right). More...
 
   }   cargo_label 
 Label data (for CFT_CARGO_LABEL).
 
   StringID   header 
 Header text (for CFT_HEADER). More...
 
u 
 

Static Public Attributes

static int vert_inter_industry_space
 Amount of space between two industries in a column.
 
static int blob_distance
 Distance of the industry legend colour from the edge of the industry box.
 
static Dimension legend
 Dimension of the legend blob.
 
static Dimension cargo_border
 Dimensions of border between cargo lines and industry boxes.
 
static Dimension cargo_line
 Dimensions of cargo lines.
 
static Dimension cargo_space
 Dimensions of space between cargo lines.
 
static Dimension cargo_stub
 Dimensions of cargo stub (unconnected cargo line.)
 
static const int INDUSTRY_LINE_COLOUR = PC_YELLOW
 Line colour of the industry type box.
 
static const int CARGO_LINE_COLOUR = PC_YELLOW
 Line colour around the cargo.
 
static int small_height
 Height of the header row.
 
static int normal_height
 Height of the non-header rows.
 
static int cargo_field_width
 Width of a cargo field.
 
static int industry_width
 Width of an industry field.
 
static uint max_cargoes
 Largest number of cargoes actually on any industry.
 

Static Private Member Functions

static void DrawHorConnection (int left, int right, int top, const CargoSpec *csp)
 Draw a horizontal cargo connection.
 

Detailed Description

Data about a single field in the IndustryCargoesWindow panel.

Definition at line 2001 of file industry_gui.cpp.

Member Typedef Documentation

◆ Cargoes

using CargoesField::Cargoes = uint16_t

Definition at line 2019 of file industry_gui.cpp.

Member Function Documentation

◆ CargoClickedAt()

CargoID CargoesField::CargoClickedAt ( const CargoesField left,
const CargoesField right,
Point  pt 
) const
inline

Decide which cargo was clicked at in a CFT_CARGO field.

Parameters
leftLeft industry neighbour if available (else nullptr should be supplied).
rightRight industry neighbour if available (else nullptr should be supplied).
ptClick position in the cargo field.
Returns
Cargo clicked at, or INVALID_CARGO if none.

Definition at line 2313 of file industry_gui.cpp.

References cargo_border, cargo_label, cargo_line, cargo_space, cargoes, CFT_CARGO, CFT_CARGO_LABEL, CFT_INDUSTRY, FS_NORMAL, GetCargoBase(), GetCharacterHeight(), HasBit(), industry, left_align, MAX_CARGOES, other_accepted, other_produced, type, and vert_inter_industry_space.

◆ CargoLabelClickedAt()

CargoID CargoesField::CargoLabelClickedAt ( Point  pt) const
inline

Decide what cargo the user clicked in the cargo label field.

Parameters
ptClick position in the cargo label field.
Returns
Cargo clicked at, or INVALID_CARGO if none.

Definition at line 2371 of file industry_gui.cpp.

References cargo_border, cargo_space, CFT_CARGO_LABEL, FS_NORMAL, GetCharacterHeight(), MAX_CARGOES, and vert_inter_industry_space.

◆ ConnectCargo()

int CargoesField::ConnectCargo ( CargoID  cargo,
bool  producer 
)
inline

Connect a cargo from an industry to the CFT_CARGO column.

Parameters
cargoCargo to connect.
producerCargo is produced (if false, cargo is assumed to be accepted).
Returns
Horizontal connection index, or -1 if not accepted at all.

Definition at line 2072 of file industry_gui.cpp.

References cargo, CFT_CARGO, HasBit(), IsValidCargoID(), and SetBit().

Referenced by CargoesRow::ConnectIndustryAccepted(), CargoesRow::ConnectIndustryProduced(), and CargoesRow::MakeCargoLabel().

◆ Draw()

◆ DrawHorConnection()

static void CargoesField::DrawHorConnection ( int  left,
int  right,
int  top,
const CargoSpec csp 
)
inlinestaticprivate

Draw a horizontal cargo connection.

Parameters
leftLeft-most coordinate to draw.
rightRight-most coordinate to draw.
topTop coordinate of the cargo connection.
cspCargo to draw.

Definition at line 2394 of file industry_gui.cpp.

References cargo_line, CARGO_LINE_COLOUR, FILLRECT_OPAQUE, and GfxFillRect().

Referenced by Draw().

◆ GetCargoBase()

int CargoesField::GetCargoBase ( int  xpos) const
inline

For a CFT_CARGO, compute the left position of the left-most vertical cargo connection.

Parameters
xposLeft position of the field.
Returns
Left position of the left-most vertical cargo column.

Definition at line 2157 of file industry_gui.cpp.

References cargo_field_width, cargo_line, cargo_space, and CFT_CARGO.

Referenced by CargoClickedAt(), and Draw().

◆ HasConnection()

bool CargoesField::HasConnection ( )
inline

Does this CFT_CARGO field have a horizontal connection?

Returns
true if a horizontal connection exists, false otherwise.

Definition at line 2101 of file industry_gui.cpp.

References CFT_CARGO.

◆ MakeCargo()

void CargoesField::MakeCargo ( const std::span< const CargoID cargoes)
inline

Make a piece of cargo column.

Parameters
cargoesSpan of CargoID (may contain INVALID_CARGO).
Note
supp_cargoes and cust_cargoes should be filled in later.

Definition at line 2113 of file industry_gui.cpp.

References cargoes, CFT_CARGO, and IsValidCargoID().

◆ MakeCargoLabel()

void CargoesField::MakeCargoLabel ( const std::span< const CargoID cargoes,
bool  left_align 
)
inline

Make a field displaying cargo type names.

Parameters
cargoesSpan of CargoID (may contain INVALID_CARGO).
left_alignALign texts to the left (else to the right).

Definition at line 2133 of file industry_gui.cpp.

References cargoes, CFT_CARGO_LABEL, and left_align.

Referenced by CargoesRow::MakeCargoLabel().

◆ MakeEmpty()

void CargoesField::MakeEmpty ( CargoesFieldType  type)
inline

Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).

Parameters
typeType of empty field.

Definition at line 2048 of file industry_gui.cpp.

References type.

Referenced by IndustryCargoesWindow::ComputeCargoDisplay(), and IndustryCargoesWindow::ComputeIndustryDisplay().

◆ MakeHeader()

void CargoesField::MakeHeader ( StringID  textid)
inline

Make a header above an industry column.

Parameters
textidText to display.

Definition at line 2146 of file industry_gui.cpp.

References CFT_HEADER.

Referenced by IndustryCargoesWindow::ComputeCargoDisplay(), and IndustryCargoesWindow::ComputeIndustryDisplay().

◆ MakeIndustry()

void CargoesField::MakeIndustry ( IndustryType  ind_type)
inline

Make an industry type field.

Parameters
ind_typeIndustry type (NUM_INDUSTRYTYPES means 'houses').
Note
other_accepted and other_produced should be filled later.

Definition at line 2058 of file industry_gui.cpp.

References CFT_INDUSTRY, and ind_type.

Field Documentation

◆ blob_distance

int CargoesField::blob_distance
static

Distance of the industry legend colour from the edge of the industry box.

Definition at line 2003 of file industry_gui.cpp.

Referenced by Draw(), and IndustryCargoesWindow::OnInit().

◆ bottom_end

uint8_t CargoesField::bottom_end

Stop at the bottom of the vertical cargoes.

Definition at line 2035 of file industry_gui.cpp.

◆ cargo_border

Dimension CargoesField::cargo_border
static

Dimensions of border between cargo lines and industry boxes.

Definition at line 2006 of file industry_gui.cpp.

Referenced by CargoClickedAt(), CargoLabelClickedAt(), Draw(), and IndustryCargoesWindow::OnInit().

◆ cargo_field_width

◆ cargo_line

Dimension CargoesField::cargo_line
static

Dimensions of cargo lines.

Definition at line 2007 of file industry_gui.cpp.

Referenced by CargoClickedAt(), Draw(), DrawHorConnection(), GetCargoBase(), and IndustryCargoesWindow::OnInit().

◆ CARGO_LINE_COLOUR

const int CargoesField::CARGO_LINE_COLOUR = PC_YELLOW
static

Line colour around the cargo.

Definition at line 2012 of file industry_gui.cpp.

Referenced by Draw(), and DrawHorConnection().

◆ cargo_space

Dimension CargoesField::cargo_space
static

Dimensions of space between cargo lines.

Definition at line 2008 of file industry_gui.cpp.

Referenced by CargoClickedAt(), CargoLabelClickedAt(), Draw(), GetCargoBase(), and IndustryCargoesWindow::OnInit().

◆ cargo_stub

Dimension CargoesField::cargo_stub
static

Dimensions of cargo stub (unconnected cargo line.)

Definition at line 2009 of file industry_gui.cpp.

Referenced by Draw(), and IndustryCargoesWindow::OnInit().

◆ cargoes

CargoID CargoesField::cargoes[MAX_CARGOES]

Cargoes to display (or INVALID_CARGO).

Definition at line 2038 of file industry_gui.cpp.

Referenced by CargoClickedAt(), MakeCargo(), and MakeCargoLabel().

◆ cust_cargoes

Cargoes CargoesField::cust_cargoes

Cargoes in vertical_cargoes leaving to the right.

Definition at line 2032 of file industry_gui.cpp.

Referenced by CargoesRow::ConnectIndustryAccepted().

◆ header

StringID CargoesField::header

Header text (for CFT_HEADER).

Definition at line 2041 of file industry_gui.cpp.

◆ ind_type

IndustryType CargoesField::ind_type

◆ INDUSTRY_LINE_COLOUR

const int CargoesField::INDUSTRY_LINE_COLOUR = PC_YELLOW
static

Line colour of the industry type box.

Definition at line 2011 of file industry_gui.cpp.

Referenced by Draw().

◆ industry_width

int CargoesField::industry_width
static

◆ left_align

bool CargoesField::left_align

Align all cargo texts to the left (else align to the right).

Definition at line 2039 of file industry_gui.cpp.

Referenced by CargoClickedAt(), and MakeCargoLabel().

◆ legend

Dimension CargoesField::legend
static

Dimension of the legend blob.

Definition at line 2005 of file industry_gui.cpp.

Referenced by Draw(), and IndustryCargoesWindow::OnInit().

◆ max_cargoes

uint CargoesField::max_cargoes
static

Largest number of cargoes actually on any industry.

Definition at line 2017 of file industry_gui.cpp.

Referenced by CargoesRow::ConnectIndustryAccepted(), CargoesRow::ConnectIndustryProduced(), Draw(), and IndustryCargoesWindow::OnInit().

◆ normal_height

int CargoesField::normal_height
static

◆ num_cargoes

uint8_t CargoesField::num_cargoes

◆ other_accepted

CargoID CargoesField::other_accepted[MAX_CARGOES]

Cargoes accepted but not used in this figure.

Definition at line 2027 of file industry_gui.cpp.

Referenced by CargoClickedAt(), and CargoesRow::ConnectIndustryAccepted().

◆ other_produced

CargoID CargoesField::other_produced[MAX_CARGOES]

Cargoes produced but not used in this figure.

Definition at line 2026 of file industry_gui.cpp.

Referenced by CargoClickedAt(), and CargoesRow::ConnectIndustryProduced().

◆ small_height

◆ supp_cargoes

Cargoes CargoesField::supp_cargoes

Cargoes in vertical_cargoes entering from the left.

Definition at line 2031 of file industry_gui.cpp.

Referenced by CargoesRow::ConnectIndustryProduced().

◆ top_end

uint8_t CargoesField::top_end

Stop at the top of the vertical cargoes.

Definition at line 2034 of file industry_gui.cpp.

◆ type

◆ vert_inter_industry_space

int CargoesField::vert_inter_industry_space
static

Amount of space between two industries in a column.

Definition at line 2002 of file industry_gui.cpp.

Referenced by CargoClickedAt(), CargoLabelClickedAt(), Draw(), and IndustryCargoesWindow::OnInit().

◆ vertical_cargoes

CargoID CargoesField::vertical_cargoes[MAX_CARGOES]

Cargoes running from top to bottom (cargo ID or INVALID_CARGO).

Definition at line 2030 of file industry_gui.cpp.

Referenced by CargoesRow::ConnectIndustryAccepted(), CargoesRow::ConnectIndustryProduced(), and CargoesRow::MakeCargoLabel().


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