I've run into a problem with graphic fonts in PB/CC 5.0 where for some reason, after creating and destroying fonts in a loop for a time, the FONT NEW no longer works properly.
I'm not sure if its a PowerBASIC issue or a Windows issue, but it seems like something is running out of memory, and the program is no longer able to create new fonts.
The reason for needing to create and destroy fonts so many times is to be able to print fonts at any rotation and at any size, so it has to be done on the fly by creating them at the right size and angle as needed. That's too many possible angles and sizes to pre-create.
Here is the start of a program that shows the problem. It doesn't matter if the FONT END is included or not, same problem. Also, it doesn't matter if the board is rotated or not, just calling the SUB that redraws the board as is, which requires rotating the fonts to complete the drawing, causes the problem after a while. The board needs to be able to be resized too, but until I get this figured out, there's no point in going further down this path.
Is there a better way to rotate and resize fonts on the fly with this many possible combinations of fonts using PB/CC 5.0?
I'm not sure if its a PowerBASIC issue or a Windows issue, but it seems like something is running out of memory, and the program is no longer able to create new fonts.
The reason for needing to create and destroy fonts so many times is to be able to print fonts at any rotation and at any size, so it has to be done on the fly by creating them at the right size and angle as needed. That's too many possible angles and sizes to pre-create.
Here is the start of a program that shows the problem. It doesn't matter if the FONT END is included or not, same problem. Also, it doesn't matter if the board is rotated or not, just calling the SUB that redraws the board as is, which requires rotating the fonts to complete the drawing, causes the problem after a while. The board needs to be able to be resized too, but until I get this figured out, there's no point in going further down this path.
Is there a better way to rotate and resize fonts on the fly with this many possible combinations of fonts using PB/CC 5.0?
Code:
#COMPILE EXE FUNCTION PBMAIN () AS LONG CONSOLE SET LOC -10000, -10000 DESKTOP GET CLIENT TO ScreenWidth&, ScreenHeight& GRAPHIC WINDOW "DartBoard", 0, 0, ScreenWidth&, ScreenHeight& TO MyWindow??? GRAPHIC ATTACH MyWindow???, 0, REDRAW DIM RingRadius#(7), BoardColor&(102), RingNumber&(102), WedgeValue&(102), FillPointx#(102), FillPointy#(102), Fontx#(20), Fonty#(20) Radian# = .017453293 MinBoardSize# = 100 MaxBoardSize# = ScreenHeight& * .9 FOR Wedge& = 1 TO 20 BoardColor&(Wedge&) = RGB(Wedge&, Wedge&, Wedge&) RingNumber&(Wedge&) = 1 WedgeValue&(Wedge&) = VAL(READ$(Wedge&)) NEXT Wedge& FOR Wedge& = 0 TO 9 BoardColor&(Wedge& * 2 + 21) = RGB(240 - Wedge&, 0, 0) BoardColor&(Wedge& * 2 + 22) = RGB(0, 140 - Wedge&, 0) RingNumber&(Wedge& * 2 + 21) = 2 RingNumber&(Wedge& * 2 + 22) = 2 WedgeValue&(Wedge& * 2 + 21) = VAL(READ$(Wedge& * 2 + 1)) WedgeValue&(Wedge& * 2 + 22) = VAL(READ$(Wedge& * 2 + 2)) BoardColor&(Wedge& * 2 + 41) = RGB(Wedge& + 21, Wedge& + 21, Wedge& + 21) BoardColor&(Wedge& * 2 + 42) = RGB(230 - Wedge&, 230 - Wedge&, 200 - Wedge&) RingNumber&(Wedge& * 2 + 41) = 3 RingNumber&(Wedge& * 2 + 42) = 3 WedgeValue&(Wedge& * 2 + 41) = VAL(READ$(Wedge& * 2 + 1)) WedgeValue&(Wedge& * 2 + 42) = VAL(READ$(Wedge& * 2 + 2)) BoardColor&(Wedge& * 2 + 61) = RGB(230 - Wedge&, 0, 0) BoardColor&(Wedge& * 2 + 62) = RGB(0, 130 - Wedge&, 0) RingNumber&(Wedge& * 2 + 61) = 4 RingNumber&(Wedge& * 2 + 62) = 4 WedgeValue&(Wedge& * 2 + 61) = VAL(READ$(Wedge& * 2 + 1)) WedgeValue&(Wedge& * 2 + 62) = VAL(READ$(Wedge& * 2 + 2)) BoardColor&(Wedge& * 2 + 81) = RGB(Wedge& + 31, Wedge& + 31, Wedge& + 31) BoardColor&(Wedge& * 2 + 82) = RGB(220 - Wedge&, 220 - Wedge&, 190 - Wedge&) RingNumber&(Wedge& * 2 + 81) = 5 RingNumber&(Wedge& * 2 + 82) = 5 WedgeValue&(Wedge& * 2 + 81) = VAL(READ$(Wedge& * 2 + 1)) WedgeValue&(Wedge& * 2 + 82) = VAL(READ$(Wedge& * 2 + 2)) NEXT BoardColor&(101) = RGB(0, 120, 0) BoardColor&(102) = RGB(220, 0, 0) RingNumber&(101) = 6 RingNumber&(102) = 7 WedgeValue&(101) = 100 WedgeValue&(102) = 200 ForeGroundColor& = RGB(255, 255, 255) BackGroundColor& = RGB(0, 0, 255) BoardFontColor& = RGB(255, 255, 255) BoardCenterx# = ScreenWidth& / 2 BoardCentery# = ScreenHeight& / 2 BoardSize# = ScreenHeight& / 2 * .8 BoardAngle# = 0 SpinRate# = 1 DO GRAPHIC COLOR ForeGroundColor&, BackGroundColor& GRAPHIC CLEAR CALL GetBoardLayout (BoardCenterx#, BoardCentery#, BoardSize#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), WedgeValue&(), Fontx#(), Fonty#(), FontSize#) CALL DrawBoard (BoardCenterx#, BoardCentery#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), BoardColor&(), BackGroundColor&) CALL DrawBoardNumbers (BoardAngle#, BoardFontColor&, FontSize#, Fontx#(), Fonty#(), WedgeValue&()) GRAPHIC REDRAW BoardAngle# = BoardAngle# + SpinRate# IF BoardAngle# = 360 THEN BoardAngle# = BoardAngle# - 360 GRAPHIC INKEY$ TO test$ LOOP UNTIL test$ <> "" DATA 20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5 END FUNCTION SUB GetBoardLayout (BoardCenterx#, BoardCentery#, BoardSize#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), WedgeValue&(), Fontx#(), Fonty#(), FontSize#) Radian# = .017453293 RingRadius#(1) = BoardSize# RingRadius#(2) = BoardSize# * .76 RingRadius#(3) = BoardSize# * .72 RingRadius#(4) = BoardSize# * .48 RingRadius#(5) = BoardSize# * .44 RingRadius#(6) = BoardSize# * .07 RingRadius#(7) = BoardSize# * .03 FOR Ring& = 0 TO 4 FOR Wedge& = 1 TO 20 FillPointx#(Ring& * 20 + Wedge&) = BoardCenterx# + (RingRadius#(Ring& + 1) - 2) * SIN(((Wedge& - 1) * 18 + BoardAngle#) * Radian#) FillPointy#(Ring& * 20 + Wedge&) = BoardCentery# - (RingRadius#(Ring& + 1) - 2) * COS(((Wedge& - 1) * 18 + BoardAngle#) * Radian#) NEXT NEXT FillPointx#(101) = BoardCenterx# FillPointy#(101) = BoardCentery# - (RingRadius#(6) - 2) * COS(0 * Radian#) FillPointx#(102) = BoardCenterx# FillPointy#(102) = BoardCentery# FontName$ = "" 'Use Current FontSize# = BoardSize# * .09 'Adjust font size according to board size FontStyle& = 0 'Normal FontSet& = 1 'Default FontFamily& = 16 'Roman FontAngle& = 0 FONT NEW FontName$, FontSize#, FontStyle&, FontSet&, FontFamily&, FontAngle& TO BoardFont& GRAPHIC SET FONT BoardFont& FOR Wedge& = 1 TO 20 GRAPHIC TEXT SIZE LTRIM$(STR$(WedgeValue&(Wedge&))) TO TextWidth#, TextHeight# TextRadius# = RingRadius#(1) * 1.015 'Move text up a bit to adjust for space above fonts CenterAngle# = (Wedge& - 1) * 18 * Radian# TextOffset# = ATN(TextWidth# * .75 / TextRadius#) 'Center text according to text width plus leading space Fontx#(Wedge&) = BoardCenterx# + TextRadius# * SIN(CenterAngle# - TextOffset# + BoardAngle# * Radian#) Fonty#(Wedge&) = BoardCentery# - TextRadius# * COS(CenterAngle# - TextOffset# + BoardAngle# * Radian#) NEXT FONT END BoardFont& END SUB SUB DrawBoard (BoardCenterx#, BoardCentery#, BoardAngle#, RingRadius#(), FillPointx#(), FillPointy#(), BoardColor&(), BackGroundColor&) Radian# = .017453293 FOR Angle# = 0 TO 360 STEP .1 FOR Radii# = 1 TO 7 x# = BoardCenterx# + RingRadius#(Radii#) * SIN(Angle# * Radian#) y# = BoardCentery# - RingRadius#(Radii#) * COS(Angle# * Radian#) IF Radii# = 1 THEN RingColor& = RGB(255, 255, 255) ELSE RingColor& = RGB(150, 150, 150) END IF GRAPHIC SET PIXEL (x#, y#), RingColor& NEXT Radii# NEXT FOR Angle# = BoardAngle# + 9 TO BoardAngle# + 351 STEP 18 x1# = BoardCenterx# + RingRadius#(6) * SIN(Angle# * Radian#) y1# = BoardCentery# - RingRadius#(6) * COS(Angle# * Radian#) x2# = BoardCenterx# + RingRadius#(1) * SIN(Angle# * Radian#) y2# = BoardCentery# - RingRadius#(1) * COS(Angle# * Radian#) GRAPHIC LINE (x1#, y1#) - (x2#, y2#), RGB(150, 150, 150) NEXT FOR Wedge& = 1 TO 102 GRAPHIC PAINT REPLACE (FillPointx#(Wedge&), FillPointy#(Wedge&)), BoardColor&(Wedge&), BackGroundColor& NEXT END SUB SUB DrawBoardNumbers (BoardAngle#, FontColor&, FontSize#, Fontx#(), Fonty#(), WedgeValue&()) FontName$ = "" 'Use Current FontStyle& = 0 'Normal FontSet& = 1 'Default FontFamily& = 16 'Roman GRAPHIC COLOR FontColor&, -2 FOR Wedge& = 1 TO 20 FontAngle& = (360 - BoardAngle# - (Wedge& - 1) * 18) * 10 FONT NEW FontName$, FontSize#, FontStyle&, FontSet&, FontFamily&, FontAngle& TO BoardFont& GRAPHIC SET FONT BoardFont& GRAPHIC SET POS (Fontx#(Wedge&), Fonty#(Wedge&)) GRAPHIC PRINT WedgeValue&(Wedge&); FONT END BoardFont& NEXT END SUB
Comment