Turing Help (Font Commands

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
KukuriChan
Posts: 13
Joined: Tue Dec 30, 2003 1:41 pm

Turing Help (Font Commands

Post by KukuriChan »

I have a question about the font.Draw command. Here's the basic code for my text procedure. It's suppose to get the font, what size they want, and the style of the font. After getting the information, it's suppose to use the same information to write text on the canvas. But everytime I run it, there's always an error. Somewhere around the fontID := Font.Draw line. ^^ If anybody can help me fix it or make my code grateful I'll be really happy. And just in case you're wondering, I'm still doing my paint program. It's due this Friday so the faster I get help the happier I'll be. ^^ Thanks.

import GUI
var x, y, butNum, butupdown, button, buttonnum, buttonupdown, col2 : int
var px, py, absX, absY : int
var words : string
var temppic : int
col2 := 0
var canvas : int := GUI.CreateCanvas (90, 85, 510, 245)
var fontID : int

proc myMouse (var x, y, b : int)
var absX, absY : int
Mouse.Where (absX, absY, B)
x := absX - 90
y := absY - 85
end myMouse


proc text
var fontName, font, size, style : string
var boxID : int := GUI.CreateTextBox (20, 390, 150, 65)
var winID, font11 : int
font11 := Font.New ("serif:12")
Font.Draw ("Font Names ", 20, 464, font11, 11)
Font.StartName
loop
fontName := Font.GetName
exit when fontName = ""
GUI.AddLine (boxID, fontName)
end loop
winID := Window.Open ("position:center;center,graphics:200;200")
put fontName
put "Type in name of font you wish to use: " ..
get font
put "Size:" ..
get size
put "Style (bold or italic) : " ..
get style
Window.Close (winID)

Mouse.ButtonWait ("down", x, y, butNum, butupdown)
temppic := Pic.New (90, 85, 600, 330)
myMouse (px, py, button)
loop
setscreen ("nocursor")
var ch : string (1)
if hasch then
getch (ch)
exit when ch = "q"
end if
var textbtn : int := GUI.CreateButtonFull (20, 130, 0, "Text", text, 0, '^T', true)
GUI.Disable (textbtn)
fontID := Font.New ("font : size")
GUI.PicDraw (canvas, temppic, 0, 0, picCopy)
loop
Mouse.Where (x, y, button)
setscreen ("cursor")
get words : *
GUI.FontDraw (canvas, words, x - 90, y - 85, fontID, 7)
end loop
end loop
end text

text


Archived topic from Iceteks, old topic ID:1908, old post ID:15611
syb
Posts: 222
Joined: Wed Jun 18, 2003 10:12 pm

Turing Help (Font Commands

Post by syb »

this maybe what your looking for.
Font.Draw Part of Font module

Syntax Font.Draw (txtStr : string, x, y, fontID, Color : int)

Description Font.Draw is used to actually draw text in a specified font. The textStr parameter contains the string to be drawn. The x and y parameters are the location of the lower left hand corner of the text to be displayed. The fontID parameter is the number of the font in which the text is to be drawn. The Color parameter is used to specify the color in which the text is to appear.
Note that the text that appears is completely unrelated to the text that appears using put. Font.Draw is a graphics command and thus does not use or affect the cursor location.

The text drawn by the Font.Draw procedure does not erase the background.


Details If Font.Draw is passed an invalid font ID, a fatal error occurs. If the Font.Draw call fails for other (non-fatal) reasons, then Error.Last will return a non-zero value indicating the reason for the failure. Error.LastMsg will return a string which contains the textual version of the error.

Example The program prints out several phrases in a variety of fonts.

var font1, font2, font3, font4 : int
font1 := Font.New ("serif:12")
assert font1 > 0
font2 := Font.New ("sans serif:18:bold")
assert font2 > 0
font3 := Font.New ("mono:9")
assert font3 > 0
font4 := Font.New ("Palatino:24:bold,italic")
assert font4 > 0
Font.Draw ("This is in a serif font", 50, 30, font1, red)
Font.Draw ("This is in a sans serif font", 50, 80, font2, brightblue)
Font.Draw ("This is in a mono font", 50, 130, font3, colorfg)
Font.Draw ("This is in Palatino (if available)", 50, 180, font4, green)
Font.Free (font1)
Font.Free (font2)
Font.Free (font3)
Font.Free (font4)

Status Exported qualified.
This means that you can only call the function by calling Font.Draw, not by calling Draw.





Archived topic from Iceteks, old topic ID:1908, old post ID:15622
The wisdom of sight comes from the father of lights
KukuriChan
Posts: 13
Joined: Tue Dec 30, 2003 1:41 pm

Turing Help (Font Commands

Post by KukuriChan »

I know understand what you put as an example but how do you put the text where you want it when you click in the canvas. Um.. like how normal paint programs are like. I hope you understand what I mean. ^^;;

Archived topic from Iceteks, old topic ID:1908, old post ID:15623
syb
Posts: 222
Joined: Wed Jun 18, 2003 10:12 pm

Turing Help (Font Commands

Post by syb »

ooohhh.. you want to be able to seleted it when the in the window.
do something like this but when the person pick one put it as that font.

% The "Dialog" program.
setscreen ("graphics:640;480,nocursor")
var x, y, btn, updown, match : int
drawfillbox (50, 50, maxx - 50, maxy - 100, red)
drawbox (50, 50, maxx - 50, maxy - 100, maxcolour)
for i : 1 .. 6
drawfillbox (80, 45 + i * 48, 110, 65 + i * 48, colorbg)
locatexy (120, 50 + i * 48)
put 7 - i ..
end for
colour (13)
locatexy (300, 250)
put " Choose one " ..
match := - 1
loop
buttonwait ("down", x, y, btn, updown)
for i : 1 .. 6
if (80 <= x) and (x <= 110) and
(45 + i * 48 <= y) and (y <= 65 + i * 48) then
drawfillbox (80, 45 + i * 48, 110, 65 + i * 48, colorfg)
match := 7 - i
end if
end for
exit when match not= - 1
sound (440, 200)
end loop
locate (1, 20)
put "You chose ", match


Archived topic from Iceteks, old topic ID:1908, old post ID:15642
The wisdom of sight comes from the father of lights
Locked