Skip to content

12. Scale & Rotate

RhettTR edited this page Apr 8, 2024 · 4 revisions

Resources are now uploaded just once in the new IO class.

Access to the host file system is only done through this class.

An important issue is how the identify each resource so that the engine can use them. A simple way to do this is to use the file path.

All resources are located in the standard ./images and ./__images directories. The ./images directory contains all resources the module developer creates such as maps, counters, cards, etc. The ./__images directory (two underlines) contain all the system resources the engine itself needs, such as the moved-marker and various other icons.

The resource directories currently look like this:

directories

The identifier of each resource looks like this

_moved
Map
VAGLmap
German/38-94_f
German/38-94
German/12R-51R_f
German/12R-51R
French/BRIGADE-3_f
French/VII-40
French/VII-40_f
French/BRIGADE-3

If the full path of a counter can look like this:

/home/me/Utvikling/Alben/scale/images/German/12R-51R.jpg

then the identifier is the part of the path beneath the images directory stripped of the file ending, like this:

German/12R-51R

A counter can be placed in the repository like this (in module.luau):

Repository["German/12R-51R"] = Repository:new({"German/12R-51R", "German/12R-51R_f"})

A counter can be placed directly on the map like this:

Counter["1000"] = Counter:new("1000", {"German/12R-51R", "German/12R-51R_f"} , 1, 0, -1, 100, 100)

The '1000' is an arbitrary value. The only rule is that this key is unique. Likewise the '-1' for zorder must be unlike any other zorder value and can not be a positive integer because dragged counters onto the map start with zero zorder. Later, zorder values may very well be generated automatically so that the user need not keep track of them.

The '100, 100' is the coordinate position on the map in pixels.


An actual map is now loaded. It looks like this:

mao

Note that the window has scroll bars. In addition to scrolling with the bars it is now possible to scroll by holding down the left-click mouse button and dragging the map (with counters) in any direction you want.

The map before dragging:

drag

The map after dragging:

drag

Note that the counters have not moved, only the map has moved.


Here is a summary of the mouse functions as they are now. Counter can both be a single counter and a stack of counters.

Counter         Hoover                                  Displays stack contents

Counter         Left-Click              No-drag         Select
Counter         Left-Click              Drag            Move

Counter         Ctrl + Left-Click                       Open stack        
Counter         Shift + Left-Click                      Add to selection


Non-counter     Left-Click             No-drag          Unselect
Non-counter     Left-Click             Drag             Drag map

Non-Counter     Ctrl + Left-Click                       <defaults to non-counter left-click>  
Non-Counter     Shift + Left-Click                      <defaults to non-counter left-click>


Counter         Right-Click                             Open context menu
Counter         Ctrl + Right-Click                      <defaults to counter right-click>          
Counter         Shift + Right-Click                     <defaults to counter right-click>

Non-counter     Right-Click                             <not used>
Non-Counter     Ctrl + Right-Click                      <not used>
Non-Counter     Shift + Right-Click                     <not used>

There are many unused slots. In addition, all Alt + Click slots are free.

Selecting counters by dragging out a rectangle will be implemented, likely using the Non-Counter Shift + Left-Click slot.


A new class Scale (scale.cpp) can now scale and rotate the map.

The scale and rotation is set in scale.h:

#ifndef SCALE_H
#define SCALE_H

#include "io.h"


#include <string>


class Scale
{
    
    public:
    
	    static constexpr float ratio = 1.0/1.0;
	    static constexpr int rotation = 0; 
	    
	    Scale();
	    
	    QImage& getScaledImage(std::string str);
	    QSize getScaledSize(std::string str);

	    void resourceScaleRotate(std::string id);
	    void coordinatesScaleRotate();
	    
	    
	    
    private:
	    
	    std::map<std::string, IO::Resource> _scaledResources;	
	    
};



#endif // SCALE_H

With

static constexpr float ratio = 2.0/3.0;
static constexpr int rotation = 0;

the map looks like this:

scale

With

static constexpr float ratio = 2.0/3.0;
static constexpr int rotation = 90; 

the map looks like this:

scale

It is important to rotate counters around their center in order to keep their relative position. It is unlikely that rotations of any other angle than -90, 0, 90 and 180 have any meaning.

For the time being scaling and rotation can not be changed during run-time. You need to change the value of static constexpr float ratio and static constexpr int rotation and recompile.


It is useful to look at how rotation of counters have been implemented. Below is a figure that describes how the calculation is done. The map with width w and height h (the rectangle with solid lines) is rotated 90 degrees clockwise, the rectangle with dotted lines and width w' and height h'. In this case w' = h and h' = w.

rotation

The main point is to recognize that the length r is the same no matter how the board is rotated. r is the length from the center to the coordinates x,y of a counter. It is important to note that the x,y coordinate is the center of the counter.

It is possible to calculate r, which can then be used to calculate x',y', the coordinates of the center of the rotated counter. The angle alpha is the angle of the unrotated r. The angle alpha + beta is the angle of the rotated r. beta is also the rotation of the map, in this illustration 90 degrees.


I have upgrade Luau.

Note the different names of the luau libraries: Luau.VM, Luau.Compiler, Luau.Ast

I have also upgraded Qt to 6.6.2.

The code can be found here.


CPLUS_INCLUDE_PATH=/home/me/Qt/6.6.2/gcc_64/include;export CPLUS_INCLUDE_PATH

LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/home/me/Qt/6.6.2/gcc_64/lib;export LD_LIBRARY_PATH

g++ -Wall -o main main.cpp luau.cpp counter.cpp window.cpp frame.cpp overlay.cpp io.cpp scale.cpp -I/home/me/luau/VM/include -I/home/me/luau/Compiler/include -I/home/me/Qt/6.6.2/gcc_64/include/QtWidgets -Wl,--copy-dt-needed-entries -L/home/me/Qt/6.6.2/gcc_64/lib -lQt6Core -lQt6Widgets -L/home/me/luau -lLuau.VM -lLuau.Compiler -lLuau.Ast -lisocline

Clone this wiki locally