Created
April 24, 2011 20:42
-
-
Save opatut/939864 to your computer and use it in GitHub Desktop.
MyGUI Skin Layout Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
''' | |
Description: | |
This script generates the different BasisSkin tags for a MyGUI skin | |
definintion file. Possible widget layouts are: | |
- Stretch | |
- 3 Tiles, vertical | |
- 3 Tiles, horizontal | |
- 9 Tiles (center piece and 8 around it) | |
Possible widget states are: normal, highlighted, pushed, disabled, | |
normal_checked | |
Version: | |
1.0 | |
MyGUI URL: | |
http://mygui.info | |
Author: | |
Paul <opatut> Bienkowski - [email protected] | |
License: | |
Copyright (C) 2011 Paul <opatut> Bienkowski | |
This program is free software; you can redistribute it and/or | |
modify it under the terms of the GNU General Public License | |
as published by the Free Software Foundation; either version 2 | |
of the License, or (at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
''' | |
import io | |
import getpass | |
yes=['y','yes','j','+'] | |
no=['n','no','-'] | |
def input_yes_no(msg, default = True): | |
while True: | |
if default: | |
inp = input("{0} [{1}/{2}] ".format(msg, yes[0].upper(), no[0])) | |
else: | |
inp = input("{0} [{1}/{2}] ".format(msg, yes[0], no[0].upper())) | |
if inp == '': | |
return default | |
inp = inp.lower() | |
if inp in yes: | |
return True | |
if inp in no: | |
return False | |
print("Please answer {0} or {1}.".format(yes[0], no[0])) | |
def hr(): | |
print("-" * 80) | |
def select_one(msg, choices, default): | |
while True: | |
hr() | |
print(msg) | |
for c in choices: | |
print(" " + c + ": " + choices[c]) | |
hr() | |
inp = input("> ") | |
if choices[inp]: | |
return inp | |
else: | |
print("Please choose one of the above.") | |
def generate_basis_skin(posx, posy, offset, size, states_offset): | |
align = "" | |
if posx == -1: align += "Left" | |
elif posx == 0: align += "HStretch" | |
else: align += "Right" | |
align += " " | |
if posy == -1: align += "Top" | |
elif posy == 0: align += "VStretch" | |
else: align += "Bottom" | |
out = '<BasisSkin type="SubSkin" offset="{0} {1} {2} {3}" align="{4}">\n' \ | |
.format(offset[0], offset[1], size[0], size[1], align) | |
for state in states_offset: | |
o = states_offset[state] | |
out += ' <State name="{0}" offset="{1} {2} {3} {4}" />\n' \ | |
.format(state, o[0] + offset[0], o[1] + offset[1], size[0], | |
size[1]) | |
out += '</BasisSkin>\n\n' | |
return out | |
if __name__ == "__main__": | |
layout = select_one("What layout type?", {"1" : "Simple stretch", | |
"2" : "3 Tiles, horizontal", | |
"3" : "3 Tiles, vertical", | |
"4" : "9 Tiles" }, "3") | |
hr() | |
w = int(input("Widget / Tile width: ")) | |
h = int(input("Widget / Tile height: ")) | |
state_list = ["normal", "highlighted", "pushed", "disabled", | |
"normal_checked"] | |
states = {} | |
for state in state_list: | |
states[state] = input_yes_no("Has \"" + state + "\" state?", | |
state == "normal") | |
hr() | |
state_offset = {} | |
for state in state_list: | |
if states[state]: | |
print("Offset of tile for state " + state + ":") | |
state_offset[state] = ( | |
int(input("X offset: ")), | |
int(input("Y offset: "))) | |
hr() | |
if layout == "1": | |
# Stretch it | |
out = generate_basis_skin(0, 0, (0, 0), (w, h), state_offset) | |
hr() | |
print(out) | |
elif layout == "2": | |
# 3 Tiles, horizontal | |
# we need left right bottom size | |
l = int(input("Left border: ")) | |
r = int(input("Right border: ")) | |
hr() | |
print("All data collected!") | |
print("Generating file!") | |
W = w - l - r # center piece width | |
out = "" | |
out += generate_basis_skin(-1, 0, (0, 0), (l, h), state_offset) | |
out += generate_basis_skin( 0, 0, (l, 0), (W, h), state_offset) | |
out += generate_basis_skin(+1, 0, (w - r, 0), (r, h), state_offset) | |
hr() | |
print(out) | |
elif layout == "3": | |
# 3 Tiles, vertical | |
# we need left right bottom size | |
t = int(input("Top border: ")) | |
b = int(input("Bottom border: ")) | |
hr() | |
print("All data collected!") | |
print("Generating file!") | |
H = h - t - b # center piece width | |
out = "" | |
out += generate_basis_skin(0, -1, (0, 0), (w, t), state_offset) | |
out += generate_basis_skin(0, 0, (0, t), (w, H), state_offset) | |
out += generate_basis_skin(0, +1, (0, h - b), (w, b), state_offset) | |
hr() | |
print(out) | |
elif layout == "4": | |
# 9 Tiles | |
# we need left right bottom top border size | |
# and offset positions of all states | |
l = int(input("Left border: ")) | |
r = int(input("Right border: ")) | |
t = int(input("Top border: ")) | |
b = int(input("Bottom border: ")) | |
hr() | |
print("All data collected!") | |
print("Generating file!") | |
W = w - l - r # center piece width | |
H = h - t - b # center piece height | |
out = "" | |
out += generate_basis_skin(-1, -1, (0, 0), (l, t), state_offset) | |
out += generate_basis_skin( 0, -1, (l, 0), (W, t), state_offset) | |
out += generate_basis_skin(+1, -1, (w - r, 0), (r, t), state_offset) | |
out += generate_basis_skin(-1, 0, (0, t), (l, H), state_offset) | |
out += generate_basis_skin( 0, 0, (l, t), (W, H), state_offset) | |
out += generate_basis_skin(+1, 0, (w - r, t), (r, H), state_offset) | |
out += generate_basis_skin(-1, +1, (0, h - b), (l, b), state_offset) | |
out += generate_basis_skin( 0, +1, (l, h - b), (W, b), state_offset) | |
out += generate_basis_skin(+1, +1, (w - r, h - b), (r, b), state_offset) | |
print("Done.") | |
hr() | |
print(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment