Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_dimension.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_DIMENSION_H
7 #define TB_DIMENSION_H
8 
9 #include "tb_types.h"
10 #include "tb_debug.h"
11 #include "tb_str.h"
12 
13 namespace tb {
14 
17 #define TB_INVALID_DIMENSION -5555
18 
19 class TBTempBuffer;
20 class TBValue;
21 
27 {
28  int m_src_dpi;
29  int m_dst_dpi;
30  TBStr m_dst_dpi_str;
31 public:
32  TBDimensionConverter() : m_src_dpi(100), m_dst_dpi(100) {}
33 
35  void SetDPI(int src_dpi, int dst_dpi);
36 
38  int GetSrcDPI() const { return m_src_dpi; }
39 
41  int GetDstDPI() const { return m_dst_dpi; }
42 
45  const TBStr & GetDstDPIStr() const { return m_dst_dpi_str; }
46 
49  void GetDstDPIFilename(const char *filename, TBTempBuffer *tempbuf) const;
50 
52  bool NeedConversion() const { return m_src_dpi != m_dst_dpi; }
53 
55  int DpToPx(int dp) const;
56 
58  int MmToPx(int mm) const;
59 
66  int GetPxFromString(const TBStr & str, int def_value) const;
67 
74  int GetPxFromValue(TBValue *value, int def_value) const;
75 };
76 
77 } // namespace tb
78 
79 #endif // TB_DIMENSION_H
int GetPxFromValue(TBValue *value, int def_value) const
Get a pixel value from TBValue.
Definition: tb_dimension.cpp:79
int GetPxFromString(const TBStr &str, int def_value) const
Get a pixel value from string in any of the following formats: str may be nullptr.
Definition: tb_dimension.cpp:63
int DpToPx(int dp) const
Convert device independant point to pixel.
Definition: tb_dimension.cpp:39
void SetDPI(int src_dpi, int dst_dpi)
Set the source and destination DPI that will affect the conversion.
Definition: tb_dimension.cpp:18
int GetSrcDPI() const
Get the source DPI.
Definition: tb_dimension.h:38
void GetDstDPIFilename(const char *filename, TBTempBuffer *tempbuf) const
Get the file name with destination DPI suffix (F.ex "foo.png" becomes "foo@192.png").
Definition: tb_dimension.cpp:27
TBDimensionConverter converts device independant points to pixels, based on two DPI values...
Definition: tb_dimension.h:26
int MmToPx(int mm) const
Convert millimeter to pixel.
Definition: tb_dimension.cpp:55
TBStr is a simple string class.
Definition: tb_str.h:62
TBValue holds value of a specific type.
Definition: tb_value.h:59
const TBStr & GetDstDPIStr() const
Get the file name suffix that should be used to load bitmaps in the destination DPI.
Definition: tb_dimension.h:45
int GetDstDPI() const
Get the destination DPI.
Definition: tb_dimension.h:41
bool NeedConversion() const
Return true if the source and destinatin DPI are different.
Definition: tb_dimension.h:52
TBTempBuffer manages a buffer that will be deleted on destruction.
Definition: tb_tempbuffer.h:18