Skip to content

Instantly share code, notes, and snippets.

@kumy
Created September 20, 2015 21:42
Show Gist options
  • Save kumy/3289cb775c5de6457a71 to your computer and use it in GitHub Desktop.
Save kumy/3289cb775c5de6457a71 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Compute INSET positions.
All dimentions are relative to mdpi resolution.
Ratio are fixed, and defined at
http://developer.android.com/guide/practices/screens_support.html#DesigningResources
"""
"""
Define here the expected marker size.
"""
# Background larker
marker_width = 34
marker_height = 38
# cache icon logo
cache_icon = 30
# overlays expected width/height
over_tl = 12
over_tr = 12
over_br = 12
over_bl = 12
"""
Static values
"""
marker_queue = marker_height - marker_width
marker = marker_width
ratio_ldpi = 0.75
ratio_mdpi = 1
ratio_hdpi = 1.5
ratio_xhdpi = 2
ratio_xxhdpi = 3
ratios = [ ratio_ldpi, ratio_mdpi, ratio_hdpi, ratio_xhdpi, ratio_xxhdpi ]
def print_values(title, left, top, right, bottom):
values = []
for ratio in ratios:
values.append("{ %d, %d, %d, %d }" % ((left * ratio), (top * ratio), (right * ratio), (bottom * ratio)))
print " private static final int[][] %s = { %s };" % (title, ', '.join(values))
# center
center_cache = (marker - cache_icon) / 2
print_values("INSET_TYPE", center_cache, center_cache, center_cache, center_cache + marker_queue)
# Top left (FOUND)
tl_overlay = marker - over_tl
print_values("INSET_FOUND", 0, 0, tl_overlay, tl_overlay + marker_queue)
# Top right (OWN)
tr_overlay = marker - over_tr
print_values("INSET_OWN", tr_overlay, 0, 0, tr_overlay + marker_queue)
# Bottom right (USER MODIFIED COORD)
br_overlay = marker - over_br
print_values("INSET_USERMODIFIEDCOORDS", br_overlay, br_overlay + marker_queue, 0, 0)
# Bottom left (PERSONALNOTE)
bl_overlay = marker - over_bl
print_values("INSET_PERSONALNOTE", 0, bl_overlay + marker_queue, bl_overlay, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment