Corona SDK: Align Text To Center...by Setreferencepoint? - xcode

Using Corona SDK for building iOS app, I want to align text to center, I read some discussion this can be done by 'setReferencePoint', I tried to make it, but failed, anybody can show me an example??
Here is my code:
message = display.newText("TEXT HERE!! TEXT HERE!! TEXT HERE!! TEXT HERE!! TEXT HERE!!", 140, 120, 240, 400, native.systemFontBold, 18 )
message:setReferencePoint(display.CenterReferencePoint)
message.x = 200
message:setTextColor(0, 126, 255)
g:insert(message)
Thanks!!

In Corona SDK, by default the reference point is display.CenterReferencePoint unless you are providing the X, Y values as parameters.
In your case - I think you should use -
message.x = X ---- X = center of object
message.y = Y ---- Y = center of object

you must use like this
skorX = cx - 10
nilaiSkorr = nilaiSkor + 0
if nilaiSkorr >= 10 then
skorX = cx - 20
elseif nilaiSkorr >= 100 then
skorX = cx - 30
end
local t = display.newText(nilaiSkor, skorX, cy + 3, native.systemFontBold, 30 )
t:setReferencePoint(display.CenterReferencePoint)

Related

Rainmeter skin not updating like it should

After I click the button, and the text file updates in the same directory, the skin doesnt refresh after a second... I'm at a loss. Any ideas?
Ive tried changing the value of the update, ive added dynamicvariables to the measures im honestly at a loss for why the skin is not automatically updating, i know its probably something really stupid, any help at all is appreciated. Thanks
Update = 1000
AccurateText = 1
[UFCTitle]
Meter = String
Text = UFC - Upcoming Events
StringAlign = Right
X = 480
Y = R
AntiAlias = 1
FontWeight = 100
Padding = 5,5,5,5
FontColor = 255,255,255
FontFace = Segoe UI
FontSize = 12
[MeterAdd1]
Meter=BUTTON
ButtonImage=button_small.png
X=480
Y=12
ButtonCommand=["#CURRENTPATH#\run.bat"]
[Seperator]
Meter = String
Text = _______________________________________________
StringAlign = Right
X = 500
Y = 18
AntiAlias = 1
Padding = 5,5,5,5
FontColor = 255,255,255
FontFace = Segoe UI
FontSize = 12
[LoadUFCFile]
Measure = Plugin
Plugin = QuotePlugin
PathName = #CURRENTPATH#upcoming_ufc_events.txt
Separator = |EOF|
DynamicVariables=1
[DisplayUFCEvents]
Meter = String
MeasureName = LoadUFCFile
StringAlign = Right
X = 500
Y = 40
FontWeight = 100
FontFace = Segoe UI
FontSize = 12
FontColor = 255,255,255,255
Padding = 5,5,5,5
ClipString = 2
AntiAlias = 1
DynamicVariables=1```

How do I get buttons to do things for gui hangman

I am new to python and have decided to create a hangman game as a GUI with tkinter. I have stumbled across this problem where I can't get my buttons to do what I want. Specifically, I want them to check if the letter is in the mystery word and print it in the position of the letter in the word if it is. Any tips or suggestions will be helpful.
from tkinter import *
import random
from tkinter import Label, Canvas
root = Tk()
root.title("Hangman Project")
c: Canvas = Canvas(root, height=500, width=500, bg="white")
c.pack()
height = 400
width = 400
head = c.create_oval(70, 70, 130, 130)
neck = c.create_line(100, 130, 100, 150)
body = c.create_rectangle(70, 150, 130, 220, fill="orange")
arm1 = c.create_line(130, 170, 150, 120)
arm2 = c.create_line(70, 170, 50, 120)
leg1 = c.create_line(110, 220, 145, 275)
leg2 = c.create_line(90, 220, 55, 275)
def gallows():
c.create_line(width / 40, height / 8, width / 4, height / 8)
c.create_line(width / 40, height / 8, width / 40, height / 1.6)
c.create_line(0, height / 1.6, width / 20, height / 1.6)
c.create_line(width / 40, height / 5, width / 4, height / 8)
c.create_line(width / 4, height / 8, width / 4, height / 5.7)
line = """Antiquated outdated fashioned Choleric easily angered Diorama
model scene Fecund fertile Inebriation drunkenness intoxication Marshal gather
together Parity equality Profound meaning Servile overly submissive groveling Usurp
"""
line.lower()
word_list = list(line.split(" "))
correct_ans = word_list
prize_word = random.choice(word_list)
spaces = " ".join(prize_word)
mystery_word = " ".join("_" * len(prize_word))
y = Label(root, text=mystery_word, font="Times, 30")
y.place(x=190, y=300)
def makebuttons():
count = 0
lst = []
if count <= 27:
for letter in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
lst.append(letter)
for letter in lst:
Buttons = Button(master=root, text=letter, font="Times, 20")
Buttons.pack()
Buttons.place(x=20 * count, y=460)
count += 1
makebuttons()
gallows()
root.mainloop()
There are several issues in your code:
line.lower() will not modify line, so use line = """...""".lower() instead
line.split() will contain "" and "\n" which need to be filtered out
redundant code in makebuttons(): if statement is not necessary and the two for loops can be merged into one
Below is a modified version of part of your code with a new function check_letter() which will be executed when a letter button is clicked:
line = """Antiquated outdated fashioned Choleric easily angered Diorama
model scene Fecund fertile Inebriation drunkenness intoxication Marshal gather
together Parity equality Profound meaning Servile overly submissive groveling Usurp
""".lower()
word_list = [x for x in line.split(" ") if x != "" and x != "\n"] # filter out all "" and "\n"
prize_word = list(random.choice(word_list)) # use list instead of string for easy modification
print(prize_word)
mystery_word = ["_"] * len(prize_word) # use list instead of string for easy modification
y = Label(root, text=mystery_word, font=("Times", 30))
y.place(x=190, y=300)
def check_letter(c):
found = False
for i, letter in enumerate(prize_word):
if c == letter:
prize_word[i] = "-"
mystery_word[i] = c # update the guess result
found = True
if found:
y['text'] = mystery_word
else:
# do whatever you want if letter is not found
pass
def makebuttons():
for i,letter in enumerate("abcdefghijklmnopqrstuvwxyz"):
Button(root, text=letter, font=("Times", 14), width=2, command=lambda c=letter: check_letter(c)).place(x=30*i+10, y=460)
You need to modify check_letter() function to cater two situations:
when all letters in the mystery word are found
when the letter is not found in the mystery word
Hope this help.

How to convert feet and inches into inches using classic .asp

I have thousands of different sizes that I need to convert from feet and inches into inches using classic .asp.
The sizes are listed in the following format:
[width] x [height]
The width and height are shown with ' marks, which stand for feet and " marks which stand for inches.
For example, take the following and convert it into inches:
2'6" x 8' = width = 30; height = 96
9'6" x 13'6" = width = 120; height = 162
Sometimes there is no X in the size, indicating that it is round or square in shape. For example:
2'6"
That would have to make both the width and height the same, so:
2'6" = width = 30; height = 30
Sometimes, there is a trailing " at the end, where there should be inches, but there are none listed. For example:
5'0" x 8'" = width = 60; height = 96
I am guessing that I would need to create some sort of custom function with expressions, but just having a hard time figuring it out.
I tried creating the following function, but it only outputs the test size I created, 5' x 4'
'example source sizes
'5'2" X 4'3"
'4' X 3'
'3'4"
'5'
'23" X 21"
'21"
'then run the function
'idsize = GetInches(rs("size"))
dim idsize
idsize = "5' x 4'"
GetInches(idsize)
Response.Write (idsize)
Function GetInches(feet_inches)
dim sizehold
feet_inches = split(feet_inches,"X")
sizehold = split(feet_inches(0),"'")
feet_inches = sizehold(0)
feet_inches = replace(feet_inches,chr(34),"")
feet_inches = replace(feet_inches,"'","")
feet_inches = trim(feet_inches)
feet_inches = feet_inches * 12
End Function
Any pointers would be appreciated.
You'll need to search the string for an X and then use string split functions.
You can split on the X if it exists to start to split things out into the width and height. You should then be able to split on the single quote, convert the feet using *12 and add to the inches.
Remember that classic ASP is basically VB script so there's probably some code for this floating around on google.

beginner swift sprite kit - arc4random and getting screen size

I want to get a random number to be in between my background width and to be 37 pixels away from the margins but it doesn't work
var width = UInt32(self.frame.width - 74)
var newX = Int(arc4random)%width)
var newY = Int(self.frame.height+10)
var pos = CGPoint(x: newX + 37, y: newY)
arc4random is a function, you need to call it. And you should be using arc4random_uniform anyway.
var newX = Int(arc4random_uniform(width))
Also, because Swift is still terrible about implicit conversions, you need to convert the arguments to the CGPoint:
var pos = CGPoint(x: CGFloat(newX + 37), y: CGFloat(newY))
And if you don't intend to change these later in the method, you should use let instead of var.

how to get width - height of a controls within dialogbox

I had created a dialog with some controls -
IDD_DIALOG_EFFECTS DIALOGEX 0, 0, 168, 49
STYLE DS_SETFONT | WS_CHILD
FONT 8, "MS Sans Serif", 400, 0, 0x1
BEGIN
--- ---
--- ---
CTEXT "",3,200,120,60,60, WS_VISIBLE
END
In Header - file:
const int16 kItem = 3;
Now when I am trying to get the position and dimension of the control, it's not accurate.
// Retrieving the location and dimension of the control
RECT wRect_proxy;
GetWindowRect(GetDlgItem(hDlg, kItem), &wRect_proxy);
ScreenToClient (hDlg, (LPPOINT)&wRect_proxy);
ScreenToClient (hDlg, (LPPOINT)&(wRect_proxy.right));
// Output of the control as location and position that I am getting is:
wRect_proxy.left: 300 (Expected: 200)
wRect_proxy.top: 195 (Expected: 120)
wRect_proxy.right: 390 (Expected: 60)
wRect_proxy.bottom: 293 (Expected: 60)
I need to calculate width - height of the control. Seeking help ...
What you receive IS the height of the contro!
The RC file uses Dialog Base Units.
When the Dialog is created the specific font is used to find howmany Pixels are 1 DLU.
Internally MapDalogRect is used to convert the values from the RC file to the final number of Pixels.
Using MapDialogrect on CRect(0,0,4,8) gives you the base values of 1 DLU.
Now take the x-width multiply with 4 and divide by the "width" base units you just calculated. For the y-height multiply with 8 and divide by the
"height".
This can be easily done with MulDiv.
Thanks a Ton ... :)
As per your guidance and suggestion the snippet will be:
// Summarizing the code-snippet.
RECT wRect;
GetWindowRect(GetDlgItem(hDlg, kDProxyItem), &wRect);
ScreenToClient (hDlg, (LPPOINT)&wRect);
ScreenToClient (hDlg, (LPPOINT)&(wRect.right));
RECT pixel_rect;
pixel_rect.left = 0;
pixel_rect.top = 0;
pixel_rect.right = 4;
pixel_rect.bottom = 8;
bool b_check = MapDialogRect(hDlg, &pixel_rect);
LONG base_pix_width = pixel_rect.right;
LONG base_pix_height = pixel_rect.bottom;
// Calculating acctual X,Y coordinates with Width - Height of the Proxy Rectangle
RECT proxy_acc_dim;
proxy_acc_dim.left = (wRect.left * 4 / base_pix_width);
//or we can do the same by: MulDiv(wRect.left, 4, base_pix_width);
proxy_acc_dim.right = (wRect.right * 4 / base_pix_width) - proxy_acc_dim.left;
//or we can do the same by: MulDiv(wRect.right, 4, base_pix_width);
proxy_acc_dim.top = (wRect.top * 8 / base_pix_height);
//or we can do the same by: MulDiv(wRect.top, 8, base_pix_height);
proxy_acc_dim.bottom = (wRect.bottom * 8 / base_pix_height) - proxy_acc_dim.top;
//or we can do the same by: MulDiv(wRect.bottom, 8, base_pix_height);
proxy_acc_dim.left = proxy_rect.left;
proxy_acc_dim.top = proxy_rect.top;
proxy_acc_dim.right = proxy_rect.right - proxy_rect.left;
proxy_acc_dim.bottom = proxy_rect.bottom - proxy_rect.top;
It works fine. Hope it would be help full to others ...

Resources