Replies: 2 comments
-
By the way... it could be cold to add CUnit to nana and the corresponding widget NumUnitUpDown which combine a number and a unit with automatic conversions. see how the concentrations are easily expresed in nM, µM, mM, and the temperature including °F |
Beta Was this translation helpful? Give feedback.
-
The coordinates and all related problems: multimonitors, DPI, scaling..all posible coordinate-system ( CoordSys ). The scaling is part of the definition of the CoordSys. There could be arbitrary scaling, but we will fix two special cases:
The CoordSys is also defined by the Origin (where the
void basic_window::_m_init_pos_and_size(basic_window* parent, const rectangle& r)
{
pos_owner = pos_root = r.position();
dimension = r.dimension();
if (parent) pos_root += parent->pos_root;
} or this: // Copy the graphics of the parent widget to the glass buffer
glass_buffer.bitblt(::nana::rectangle{ wd->dimension },
wd->parent->drawer.graphics,
wd->pos_owner);
In a more general situation we may need to include rotations of one CoordSys with respect tp other. Simple 90°/-90° or even 'free angle' rotation. |
Beta Was this translation helpful? Give feedback.
-
Thinking about how to fix the DPI scaling problem and after reviewing a lot of code I would like to discuss here how we can really fix all of this: DPI, scaling, multi-monitors, screens, windows, client areas... float, int, size_t, UINT... (See #698 , specially Where to put the frontier original/scaled coordinates for PER_MONITOR_AWARE_V2 ?)
I think the core problem is much more general: coordinates are just meaningless numbers if we don't have an explicit reference to a coordinate system. We can take the speed in km/h of a car, with respect to the surface of the Earth. But if we launch ourselves to the Moon, the reference will work only at the beginning. Then we will want to measure the velocity with respect to a system that involves both the Earth and the Moon and that also allows us to calculate the escape velocity from Earth's gravity. At the time of dawn we will again prefer a reference to some point on the surface of the Moon. We will need that clear reference to the coordinate system all the time and know how to go from one system to another.
Here we have a similar problem: each position/size or rectangle need an explicit reference to a coordinate system. We need to define each coordinate system only once, but each coordinate need a reference to that. Then, we will need a simple and efficient way to convert from one to any other system: this will be a kind of small function object that efficiently make the conversion on both directions.
We have many 'coordinate system': the system coordinates of the whole screen, including all monitors (the origin or 0 point is on the left/top point of the principal monitor), that same but with a system scaling - system DPI. The system af each monitor with a 0 at left/top. That scaled (like in DPI_awareness). Each window have own system (client), and non-client, and the parent system, Each scaled too. Etc. It is very easy to make mistakes if not using some systematic approach, like the function objects for conversion, at run-time.
I have some similar experience transforming physical units at run time.
See: github qPCR4vir ProgParam Units.hpp
There we have a CUnit object (Conversion of Units) that take two units and make a conversion of quantities between then. This uses a conversion object that can be lineal or not. The lineal conversion take a Coefficient and a Summand. The non-lineal an std:function.
CUnit keep a map to find how two units are converted. The first time a program invoke one conversion it is generated combining all the intermediary units and saved into that map for efficient use the next time. We convert from inches to meters by first combining the conversion inch/cm and then cm/m in one new inch/m wich is then used for the repeated calculations.
Similarly, instead of Units (or apart from units) we may work with different 'windows-coordinate system', each atached to one widget_base, monitor or screen with the associated scaling or DPI. In extreme situations that conversion objects will include not only changing origin and scale (dpi) independently for each direction, but also rotation and even 3D. All in one general solution and a lot less error prone. nana could add the possibility of easy scaling and even rotation each widget separately or in combination.
Beta Was this translation helpful? Give feedback.
All reactions