Screen Resolution
1.2.0.2
1.2.0.2
By Sevion
Very efficient method of getting a player's screen resolution. Requires players to "calibrate" the screen.
V1.3.0.0 will appear with a separate module library to allow for the easier creation of dialogs (eliminates the scripters' need to multiply all values by aspect ratio).
Docs
- What Screen Resolution does:
Screen Resolution allows scripters to get a player's screen resolution and aspect ratio to easily display the correct sizes and x/y offests for dialogs and other on-screen objects. - How Screen Resolution was made:
While making some dialogs, I got the idea that while they display correctly in my 1920 x 1080 resolution, it may not display correctly in any others. So, I tested around and was correct. With this, you just have to use the getAsPercent functions and you'll get the proper values.
- Get a player's screen properties:
- [ljass]lib_sr_getResX( EventPlayer() )[/ljass]
- [ljass]lib_sr_getResY( EventPlayer() )[/ljass]
- [ljass]lib_sr_getRatio( EventPlayer() )[/ljass]
- [ljass]lib_sr_isCalibrated( EventPlayer() )[/ljass]
- [ljass]lib_sr_getXAsPercent( value, EventPlayer() )[/ljass]
- [ljass]lib_sr_getYAsPercent( value, EventPlayer() )[/ljass]
- Calibrate a player's screen:
[ljass]lib_sr_calibrate( EventPlayer() )[/ljass]
JASS:
//==================================================================================================
//
// Library
//
// Name: Screen Resolution
// Author: Sevion
//
//==================================================================================================
include "TriggerLibs/NativeLib"
include "Libraries/DebugMode"
//==================================================================================================
//
// System Globals
//
//==================================================================================================
static bank[16] lib_sr__banks;
static bool[16] lib_sr__calibrated;
static int[16] lib_sr__resX;
static int[16] lib_sr__resY;
static fixed[16] lib_sr__ratio;
static bool[16] lib_sr__gettingResolution;
static const int lib_sr__RESOLUTION_COUNT = 97;
static int[lib_sr__RESOLUTION_COUNT][2] lib_sr__resolutions;
//==================================================================================================
//
// System Script
//
//==================================================================================================
int lib_sr_getResX ( int whichPlayer ) {
if ( !lib_sr__calibrated[whichPlayer] ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution Width!");
}
return -1;
}
return lib_sr__resX[whichPlayer];
}
int lib_sr_getResY ( int whichPlayer ) {
if ( !lib_sr__calibrated[whichPlayer] ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution Height!");
}
return -1;
}
return lib_sr__resY[whichPlayer];
}
fixed lib_sr_getRatio ( int whichPlayer ) {
if ( !lib_sr__calibrated[whichPlayer] ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution Ratio!");
}
return -1;
}
return lib_sr__ratio[whichPlayer];
}
int lib_sr_getXAsPercent ( int value, int whichPlayer ) {
if ( !lib_sr__calibrated[whichPlayer] ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution X Percentage!");
}
return -1;
}
return value / lib_sr__resX[whichPlayer];
}
int lib_sr_getYAsPercent ( int value, int whichPlayer ) {
if ( !lib_sr__calibrated[whichPlayer] ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution Y Percentage!");
}
return -1;
}
return value / lib_sr__resY[whichPlayer];
}
bool lib_sr_isCalibrated ( int whichPlayer ) {
return lib_sr__calibrated[whichPlayer];
}
bool lib_sr_getResolutions (bool testConds, bool runActions) {
int lv_x;
int lv_y;
int lv_p;
int lv_i;
int lv_temp;
if (!runActions) {
return true;
}
lv_x = EventMouseClickedPosXUI() + 1;
lv_y = EventMouseClickedPosYUI() + 1;
lv_p = EventPlayer();
lv_i = lib_sr__RESOLUTION_COUNT - 1;
lv_temp = 0;
while ( lv_i >= 0 ) {
if ( lv_x == lib_sr__resolutions[lv_i][0] && lv_y == lib_sr__resolutions[lv_i][1] ) {
lv_temp = lv_i;
lv_i = -1;
}
if ( lv_x > lib_sr__resolutions[lv_i][0] || lv_y > lib_sr__resolutions[lv_i][1] ) {
lv_temp = lv_i;
}
lv_i -= 1;
}
lib_sr__resX[lv_p] = lib_sr__resolutions[lv_temp][0];
lib_sr__resY[lv_p] = lib_sr__resolutions[lv_temp][1];
lib_sr__ratio[lv_p] = lib_sr__resX[lv_p] / lib_sr__resY[lv_p];
BankValueSetFromInt(lib_sr__banks[lv_p], "screenData", "resolutionX", lib_sr__resX[lv_p]);
BankValueSetFromInt(lib_sr__banks[lv_p], "screenData", "resolutionY", lib_sr__resY[lv_p]);
BankValueSetFromFixed(lib_sr__banks[lv_p], "screenData", "aspectratio", lib_sr__ratio[lv_p]);
lib_sr__gettingResolution[lv_p] = false;
return false;
}
void lib_sr_calibrate ( int whichPlayer ) {
trigger lv_tempTrig;
libNtve_gf_HideGameUI(false, PlayerGroupSingle(whichPlayer));
lv_tempTrig = TriggerCreate("getResolutions");
TriggerAddEventMouseClicked(lv_tempTrig, whichPlayer, c_mouseButtonLeft, true);
UIDisplayMessage(PlayerGroupSingle(whichPlayer), c_messageAreaDirective, StringToText("Please calibrate your resolution by clicking in the bottom right corner."));
lib_sr__gettingResolution[whichPlayer] = true;
while ( lib_sr__gettingResolution[whichPlayer] && PlayerGroupHasPlayer(PlayerGroupActive(), whichPlayer) ) {
Wait(0.0, c_timeGame);
}
TriggerDestroy(lv_tempTrig);
BankValueSetFromFlag(lib_sr__banks[whichPlayer], "screenData", "lib_sr__calibrated", true);
lib_sr__calibrated[whichPlayer] = true;
UIClearMessages(PlayerGroupSingle(whichPlayer), c_messageAreaDirective);
libNtve_gf_HideGameUI(true, PlayerGroupSingle(whichPlayer));
}
//--------------------------------------------------------------------------------------------------
// Library Initialization
//--------------------------------------------------------------------------------------------------
static void lib_sr__InitVariables() {
int lv_i = 15;
while ( lv_i >= 0 ) {
lib_sr__banks[lv_i] = BankLoad("lib_sr__screenData", lv_i);
lib_sr__calibrated[lv_i] = BankValueGetAsFlag(lib_sr__banks[lv_i], "screenData", "lib_sr__calibrated");
if ( lib_sr__calibrated[lv_i] ) {
lib_sr__resX[lv_i] = BankValueGetAsInt(lib_sr__banks[lv_i], "screenData", "resolutionX");
lib_sr__resX[lv_i] = BankValueGetAsInt(lib_sr__banks[lv_i], "screenData", "resolutionY");
lib_sr__resX[lv_i] = BankValueGetAsInt(lib_sr__banks[lv_i], "screenData", "aspectratio");
}
lib_sr__gettingResolution[lv_i] = false;
lv_i -= 1;
}
lib_sr__resolutions[0][0] = 1024;
lib_sr__resolutions[0][1] = 768;
lib_sr__resolutions[1][0] = 1280;
lib_sr__resolutions[1][1] = 800;
lib_sr__resolutions[2][0] = 1280;
lib_sr__resolutions[2][1] = 1024;
lib_sr__resolutions[3][0] = 1440;
lib_sr__resolutions[3][1] = 900;
lib_sr__resolutions[4][0] = 1680;
lib_sr__resolutions[4][1] = 1050;
lib_sr__resolutions[5][0] = 1366;
lib_sr__resolutions[5][1] = 768;
lib_sr__resolutions[6][0] = 800;
lib_sr__resolutions[6][1] = 600;
lib_sr__resolutions[7][0] = 1152;
lib_sr__resolutions[7][1] = 864;
lib_sr__resolutions[8][0] = 1920;
lib_sr__resolutions[8][1] = 1080;
lib_sr__resolutions[9][0] = 1280;
lib_sr__resolutions[9][1] = 768;
lib_sr__resolutions[10][0] = 1600;
lib_sr__resolutions[10][1] = 900;
lib_sr__resolutions[11][0] = 1024;
lib_sr__resolutions[11][1] = 600;
lib_sr__resolutions[12][0] = 1280;
lib_sr__resolutions[12][1] = 720;
lib_sr__resolutions[13][0] = 1280;
lib_sr__resolutions[13][1] = 960;
lib_sr__resolutions[14][0] = 320;
lib_sr__resolutions[14][1] = 396;
lib_sr__resolutions[15][0] = 320;
lib_sr__resolutions[15][1] = 480;
lib_sr__resolutions[16][0] = 1360;
lib_sr__resolutions[16][1] = 768;
lib_sr__resolutions[17][0] = 1600;
lib_sr__resolutions[17][1] = 1200;
lib_sr__resolutions[18][0] = 1400;
lib_sr__resolutions[18][1] = 1050;
lib_sr__resolutions[19][0] = 1024;
lib_sr__resolutions[19][1] = 640;
lib_sr__resolutions[20][0] = 1152;
lib_sr__resolutions[20][1] = 720;
lib_sr__resolutions[21][0] = 1093;
lib_sr__resolutions[21][1] = 614;
lib_sr__resolutions[22][0] = 768;
lib_sr__resolutions[22][1] = 1024;
lib_sr__resolutions[23][0] = 1024;
lib_sr__resolutions[23][1] = 819;
lib_sr__resolutions[24][0] = 1344;
lib_sr__resolutions[24][1] = 840;
lib_sr__resolutions[25][0] = 819;
lib_sr__resolutions[25][1] = 614;
lib_sr__resolutions[26][0] = 1024;
lib_sr__resolutions[26][1] = 576;
lib_sr__resolutions[27][0] = 2560;
lib_sr__resolutions[27][1] = 1440;
lib_sr__resolutions[28][0] = 1536;
lib_sr__resolutions[28][1] = 864;
lib_sr__resolutions[29][0] = 1311;
lib_sr__resolutions[29][1] = 737;
lib_sr__resolutions[30][0] = 240;
lib_sr__resolutions[30][1] = 320;
lib_sr__resolutions[31][0] = 1280;
lib_sr__resolutions[31][1] = 854;
lib_sr__resolutions[32][0] = 960;
lib_sr__resolutions[32][1] = 600;
lib_sr__resolutions[33][0] = 2560;
lib_sr__resolutions[33][1] = 1600;
lib_sr__resolutions[34][0] = 320;
lib_sr__resolutions[34][1] = 240;
lib_sr__resolutions[35][0] = 1536;
lib_sr__resolutions[35][1] = 960;
lib_sr__resolutions[36][0] = 480;
lib_sr__resolutions[36][1] = 360;
lib_sr__resolutions[37][0] = 1441;
lib_sr__resolutions[37][1] = 810;
lib_sr__resolutions[38][0] = 640;
lib_sr__resolutions[38][1] = 480;
lib_sr__resolutions[39][0] = 1080;
lib_sr__resolutions[39][1] = 810;
lib_sr__resolutions[40][0] = 480;
lib_sr__resolutions[40][1] = 320;
lib_sr__resolutions[41][0] = 1249;
lib_sr__resolutions[41][1] = 702;
lib_sr__resolutions[42][0] = 1120;
lib_sr__resolutions[42][1] = 700;
lib_sr__resolutions[43][0] = 234;
lib_sr__resolutions[43][1] = 282;
lib_sr__resolutions[44][0] = 983;
lib_sr__resolutions[44][1] = 737;
lib_sr__resolutions[45][0] = 1067;
lib_sr__resolutions[45][1] = 800;
lib_sr__resolutions[46][0] = 1024;
lib_sr__resolutions[46][1] = 614;
lib_sr__resolutions[47][0] = 1192;
lib_sr__resolutions[47][1] = 670;
lib_sr__resolutions[48][0] = 1067;
lib_sr__resolutions[48][1] = 600;
lib_sr__resolutions[49][0] = 1024;
lib_sr__resolutions[49][1] = 1024;
lib_sr__resolutions[50][0] = 480;
lib_sr__resolutions[50][1] = 800;
lib_sr__resolutions[51][0] = 853;
lib_sr__resolutions[51][1] = 533;
lib_sr__resolutions[52][0] = 1600;
lib_sr__resolutions[52][1] = 1000;
lib_sr__resolutions[53][0] = 1600;
lib_sr__resolutions[53][1] = 1024;
lib_sr__resolutions[54][0] = 911;
lib_sr__resolutions[54][1] = 512;
lib_sr__resolutions[55][0] = 1140;
lib_sr__resolutions[55][1] = 641;
lib_sr__resolutions[56][0] = 1229;
lib_sr__resolutions[56][1] = 983;
lib_sr__resolutions[57][0] = 1680;
lib_sr__resolutions[57][1] = 945;
lib_sr__resolutions[58][0] = 800;
lib_sr__resolutions[58][1] = 480;
lib_sr__resolutions[59][0] = 1229;
lib_sr__resolutions[59][1] = 768;
lib_sr__resolutions[60][0] = 480;
lib_sr__resolutions[60][1] = 854;
lib_sr__resolutions[61][0] = 1525;
lib_sr__resolutions[61][1] = 857;
lib_sr__resolutions[62][0] = 1382;
lib_sr__resolutions[62][1] = 864;
lib_sr__resolutions[63][0] = 1170;
lib_sr__resolutions[63][1] = 936;
lib_sr__resolutions[64][0] = 983;
lib_sr__resolutions[64][1] = 576;
lib_sr__resolutions[65][0] = 1143;
lib_sr__resolutions[65][1] = 857;
lib_sr__resolutions[66][0] = 1120;
lib_sr__resolutions[66][1] = 840;
lib_sr__resolutions[67][0] = 1058;
lib_sr__resolutions[67][1] = 595;
lib_sr__resolutions[68][0] = 2048;
lib_sr__resolutions[68][1] = 1152;
lib_sr__resolutions[69][0] = 853;
lib_sr__resolutions[69][1] = 683;
lib_sr__resolutions[70][0] = 922;
lib_sr__resolutions[70][1] = 691;
lib_sr__resolutions[71][0] = 240;
lib_sr__resolutions[71][1] = 160;
lib_sr__resolutions[72][0] = 2560;
lib_sr__resolutions[72][1] = 1024;
lib_sr__resolutions[73][0] = 1613;
lib_sr__resolutions[73][1] = 1008;
lib_sr__resolutions[74][0] = 360;
lib_sr__resolutions[74][1] = 640;
lib_sr__resolutions[75][0] = 936;
lib_sr__resolutions[75][1] = 702;
lib_sr__resolutions[76][0] = 1088;
lib_sr__resolutions[76][1] = 614;
lib_sr__resolutions[77][0] = 1117;
lib_sr__resolutions[77][1] = 894;
lib_sr__resolutions[78][0] = 360;
lib_sr__resolutions[78][1] = 480;
lib_sr__resolutions[79][0] = 1350;
lib_sr__resolutions[79][1] = 844;
lib_sr__resolutions[80][0] = 1152;
lib_sr__resolutions[80][1] = 870;
lib_sr__resolutions[81][0] = 1440;
lib_sr__resolutions[81][1] = 960;
lib_sr__resolutions[82][0] = 683;
lib_sr__resolutions[82][1] = 512;
lib_sr__resolutions[83][0] = 1080;
lib_sr__resolutions[83][1] = 633;
lib_sr__resolutions[84][0] = 1069;
lib_sr__resolutions[84][1] = 855;
lib_sr__resolutions[85][0] = 1317;
lib_sr__resolutions[85][1] = 823;
lib_sr__resolutions[86][0] = 1365;
lib_sr__resolutions[86][1] = 1024;
lib_sr__resolutions[87][0] = 1350;
lib_sr__resolutions[87][1] = 1080;
lib_sr__resolutions[88][0] = 819;
lib_sr__resolutions[88][1] = 480;
lib_sr__resolutions[89][0] = 1170;
lib_sr__resolutions[89][1] = 731;
lib_sr__resolutions[90][0] = 1017;
lib_sr__resolutions[90][1] = 572;
lib_sr__resolutions[91][0] = 1024;
lib_sr__resolutions[91][1] = 1280;
lib_sr__resolutions[92][0] = 1117;
lib_sr__resolutions[92][1] = 698;
lib_sr__resolutions[93][0] = 1519;
lib_sr__resolutions[93][1] = 949;
lib_sr__resolutions[94][0] = 854;
lib_sr__resolutions[94][1] = 480;
lib_sr__resolutions[95][0] = 1300;
lib_sr__resolutions[95][1] = 2300;
lib_sr__resolutions[96][0] = 1276;
lib_sr__resolutions[96][1] = 733;
}
static bool lib_sr__InitLib_completed = false;
void lib_sr_InitLib() {
if (lib_sr__InitLib_completed) {
return;
}
lib_sr__InitVariables();
lib_sr__InitLib_completed = true;
}
Change Log
1.0.0.0 said:Initial Release
1.0.0.1 said:Fixed a minor bug on calibration boolean not saving
1.0.0.2 said:Fixed a minor bug on array initialization.
1.1.0.0 said:Added the misclick algorithm.
1.2.0.0 said:Changed function names and added Dialog module.
1.2.0.1 said:Added a bunch of resolutions. Ninety-seven in total now. All from here and listed from most common to least common.
1.2.0.2 said:Added [ljass]lib_sr_getXAsPercent ( value, EventPlayer() )[/ljass] and [ljass]lib_sr_getYAsPercent( value, EventPlayer() )[/ljass].