'
' Created by piratesmack from the Puppy Linux forum
'
SETENVIRON "LANG", "C"
INCLUDE "hug.bac"
CONST url$ = "http://somuchdamage.com/stuff/dancingletters/"
' Sets text type to small
SUB SETSMALL
text_type$ = "small"
END SUB
' Sets text type to 'large'
SUB SETLARGE
text_type$ = "large"
END SUB
' Sets text type to 'rainbow'
SUB SETRAINBOW
text_type$ = "rainbow"
END SUB
' Generates BBCode for dancing letters:
SUB GENERATE
LOCAL text$, text_new$, char$, dletter$, dancing_text$
LOCAL len, i
' Grab text from edit box 1
text$ = GRAB$(edit1)
' Chop, make uppercase, and replace "?" with "q"
text_new$ = REPLACE$(CHOP$(UCASE$(text$)), "?", "q")
len = LEN(text_new$)
' Translate each character to dancing letter
FOR i=1 TO len
char$ = MID$(text_new$, i, 1)
IF REGEX(char$, "[A-Z]") THEN
dletter$ = CONCAT$("[img]", url$, text_type$, "/", char$, ".gif[/img]")
ELIF REGEX(char$, "[0-9!$&@q]") THEN
IF EQUAL(text_type$, "rainbow") THEN
dletter$ = CONCAT$("[img]", url$, text_type$, "/", char$, ".gif[/img]")
ELSE
dletter$ = CONCAT$("[img]", url$, "punctuation/", char$, ".gif[/img]")
END IF
ELSE
dletter$ = char$
END IF
dancing_text$ = CONCAT$(dancing_text$, dletter$)
NEXT
' Clear edit box 2
TEXT(edit2, "")
' Put Dancing letter BBCode in edit box 2
TEXT(edit2, dancing_text$)
END SUB
' Clear edit boxes
SUB CLEAR
TEXT(edit1, "")
TEXT(edit2, "")
END SUB
' Create main window
window = WINDOW("Dancing letter generator", 400, 335)
' Create "Enter some text" part
frame1 = FRAME(400, 150)
TEXT(frame1, " Enter some text ")
ATTACH(window, frame1, 0, 0)
edit1 = EDIT(390, 130)
ATTACH(window, edit1, 5, 15)
' Create "Dancing letter BBCode" part
frame2 = FRAME(400, 150)
TEXT(frame2, " Dancing letter BBCode ")
ATTACH(window, frame2, 0, 150)
edit2 = EDIT(390, 130)
ATTACH(window, edit2, 5, 165)
' Create 'generate!' button
button1 = BUTTON("generate!", 75, 25)
ATTACH(window, button1, 240, 305)
' Create 'clear' button
button2 = BUTTON("clear", 75, 25)
ATTACH(window, button2, 320, 305)
' Create radio button 'small'
radio1 = RADIO("small", 70, 25, radio1)
ATTACH(window, radio1, 5, 305)
ENABLE(radio1)
SETSMALL
' Create radio button 'large'
radio2 = RADIO("large", 70, 25, radio1)
ATTACH(window, radio2, 75, 305)
' Create radio button 'rainbow'
radio3 = RADIO("rainbow", 72, 25, radio1)
ATTACH(window, radio3, 145, 305)
' Define callbacks
CALLBACK(button1, GENERATE)
CALLBACK(button2, CLEAR)
CALLBACK(radio1, SETSMALL)
CALLBACK(radio2, SETLARGE)
CALLBACK(radio3, SETRAINBOW)
' Endless GTK loop
DISPLAY