project_files/Android-build/SDL-android-project/assets/Data/Scripts/Utils.lua
author Wuzzy <Wuzzy2@mail.ru>
Sun, 05 Jul 2020 02:03:08 +0200
branchui-scaling
changeset 15672 b3c9f5463cee
parent 7568 75ba91f14ed5
permissions -rw-r--r--
[backport] Chat: Use Ctrl-A for 'select all' again (instead of Ctrl-B) Backport of 783959a6810b to branch ui-scaling by sheepluva
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7568
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
-- Library for miscellaneous utilitiy functions
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
-- Check if a gear is inside a box
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
function gearIsInBox(gear, x, y, w, h)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
    gx, gy = GetGearPosition(gear)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
    if gx >= x and gy >= y and gx <= x + w and gy <= y + h then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
        return true
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
    return false
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
-- Check if a gear is inside a circle
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
function gearIsInCircle(gear, x, y, r, useRadius)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
    gx, gy = GetGearPosition(gear)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
    if useRadius then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
        r = r + GetGearRadius(gear)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
    if r ^ 2 >= (x - gx) ^ 2 + (y - gy) ^ 2 then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
        return true
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
    return false
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
end