Welcome, Guest |
You have to register before you can post on our site.
|
Forum Statistics |
» Members: 483
» Latest member: aplus
» Forum threads: 2,796
» Forum posts: 26,382
Full Statistics
|
|
|
String color in IDE |
Posted by: Dimster - 03-12-2024, 08:22 PM - Forum: Help Me!
- Replies (31)
|
|
I love the control I have with color setting in the IDE but is there an option or a command this will help me with seeing the color of a string in the IDE?
An example would be:
Screen _NewImage(800, 400, 32)
$Color:32
Color Blue
Print "The sky is blue"
It prints the phrase in a lovely blue to the Screen, but often you can't tell if the blue being printed to the screen is the one you actually want until you run the code. Is there a way or command that I can use to actually have "The sky is blue" appear in the blue in the IDE code itself? It would save me from running the code just to see if it's the color is what I want.
|
|
|
Recursion limit? |
Posted by: TerryRitchie - 03-12-2024, 02:55 AM - Forum: General Discussion
- Replies (5)
|
|
Is there a limit to the number of recursions that QB64PE can handle? The code below works well with a circle the radius of 50, but increase the radius to 100 and the program will crash part way through.
Also, I figured out why the IDE was using so much RAM (256MB as I reported in another thread). Every crash of this program increases the IDE RAM usage.
Keep in mind the code below is just me playing around. It's not optimized at all or debugged in any way. Just me experimenting.
Code: (Select All) OPTION _EXPLICIT
DIM Image AS LONG
DIM x AS INTEGER
DIM y AS INTEGER
Image = _NEWIMAGE(800, 600, 32)
SCREEN Image
MemCLS Image, _RGB32(255, 255, 255)
CIRCLE (399, 299), 50, _RGB32(0, 0, 0) ' recursion works at radius 50, fails at radius 100
FloodPaint 399, 299, _RGB32(255, 0, 255), _RGB32(0, 0, 0) ' recursive paint
SUB FloodPaint (x AS INTEGER, y AS INTEGER, c AS _UNSIGNED LONG, b AS _UNSIGNED LONG)
' x,y - paint location
' c - paint color
' b - border color
DIM p AS _UNSIGNED LONG ' pixel color
STATIC Iterations AS LONG ' the number of iterations
IF x = -1 OR y = -1 OR x = _WIDTH(_DEST) OR y = _HEIGHT(_DEST) THEN EXIT SUB
p = POINT(x, y)
IF p = b OR p = c THEN EXIT SUB
PSET (x, y), c
Iterations = Iterations + 1
' Just some code to show what's going on and slow things down a bit
LOCATE 1, 1
PRINT x, y, Iterations
_DELAY .001
' Check neighboring pixels
FloodPaint x - 1, y, c, b
FloodPaint x + 1, y, c, b
FloodPaint x, y - 1, c, b
FloodPaint x, y + 1, c, b
Iterations = Iterations - 1
END SUB
FUNCTION xyOFFSET%& (i AS LONG, x AS INTEGER, y AS INTEGER)
' Calculates the pixel memory address offset location within an image given the x,y coordinate pair
'
' i - image handle
' x,y - pixel coordinate
$CHECKING:OFF
IF (i = 0 OR i < -1) AND _PIXELSIZE(i) = 4 THEN ' valid 32bit image?
xyOFFSET%& = y * _WIDTH(i) * 4 + x * 4 ' yes, calculate pixel offset location
END IF
$CHECKING:ON
END FUNCTION
SUB MemCLS (i AS LONG, c AS _UNSIGNED LONG)
' Clears an image with provided color
'
' i - image handle
' c - 32bit color
DIM m AS _MEM
$CHECKING:OFF
IF (i = 0 OR i < -1) AND _PIXELSIZE(i) = 4 THEN ' valid 32bit image?
m = _MEMIMAGE(i)
_MEMFILL m, m.OFFSET, m.SIZE, c
_MEMFREE m
$CHECKING:ON
END IF
END SUB
|
|
|
QB64 PE and Inform PE numeric input box |
Posted by: Willi Grundmann - 03-11-2024, 08:32 AM - Forum: General Discussion
- Replies (3)
|
|
Hi,
I am learning QB64 Phoenix Edition and Inform PE with the intention to do a hobby project.
In my test GUI I have a numeric input box.
How can I pass in QB64 PE the value of the numeric input box to a variable? I could not find it in the Inform PE examples.
Is there a way to get a manual for QB64 and Inform?
|
|
|
Shifting versus Mutliplying |
Posted by: TerryRitchie - 03-11-2024, 03:36 AM - Forum: General Discussion
- Replies (7)
|
|
In my quest learning the _MEM related commands I'm also looking for the fastest possible ways to do things.
When working with image memory blocks many times you need to multiply by 4 to calculate offsets to pixel locations. Instead of multiplying by 4 I thought perhaps shifting left by 2 would be faster and still achieve the same result. So I wrote a little speed test program (below) to prove this out.
When the program is first run the very first loop will sometimes show multiplying is faster than shifting, but then subsequent loops show shifting is faster.
Now here is the really weird part, REM the SLEEP 3 line in the code below and multiplying is always faster ???
Any idea what is causing this? I'm using QB64PE version 3.12.0. (Update: I just ran the code in version 3.11.0 with the same results)
Also, has anyone else noticed that the 3.12.0 IDE flickers occasionally when not using it (not the active window)? As I am writing this text into the forum it's flickering now and then. This also happens when I run code and press keys while the code is running, the IDE flickers in the background.
Code: (Select All) DIM x AS INTEGER
DIM y AS INTEGER
DIM i AS LONG
DIM t AS DOUBLE
DIM f1 AS LONG
DIM f2 AS LONG
DIM h AS DOUBLE
DIM l AS DOUBLE
DIM p AS DOUBLE
x = 4
DO
i = 0
t = TIMER(.001)
DO
y = x * 4
i = i + 1
LOOP UNTIL TIMER(.001) - t >= 1
f1 = i
i = 0
t = TIMER(.001)
DO
y = _SHL(x, 2)
i = i + 1
LOOP UNTIL TIMER(.001) - t >= 1
f2 = i
p = (f2 - f1) / f1 * 100 ' calculate percentage
IF p > h THEN h = p
IF l = 0 THEN l = p
IF p < l THEN l = p
CLS
PRINT
PRINT f1; "--> Multiplying"
PRINT f2; "--> Shifing left"
PRINT
PRINT f2 - f1; "--> Additional calculations using shifting"
PRINT USING " ##.##% --> Increase"; p
PRINT
PRINT USING " ##.##% --> Lowest seen"; l
PRINT USING " ##.##% --> Highest seen"; h
' Rem the following line for negative results ???
SLEEP 3
LOOP
|
|
|
Is _NEWIMAGE just a nicer way of saying, "Special needs?" |
Posted by: Pete - 03-10-2024, 07:51 PM - Forum: General Discussion
- Replies (12)
|
|
Just poking some fun at the obvious extra work and thinking required to expand font use in a graphics environment, instead of taking advantage of the ease of spacing and wrapping with a text display.
I'm wondering if I could cheat it a bit, and get something that looks reasonably okay using mono-spaced fonts. The challenge here would be finding bold and italics in the same as regular font.
It's possible to make a wrap routine based upon non-mono-spaced fonts, by concatenating the font widths. When there is enough physical space, then wrap. I guess another alternative would be to measure any font width and simply print it to the screen at center point, 16 pixels away from the previous center point.
I really wonder how Word works in this regard. Regular fonts, bold, italicized, underlined. Well, you don't actually need an underlined font set, just position a LINE statement.
I wish all fonts came with the above aforementioned glyphs, but they don't. If anyone has found some better choices, methods, or font selections for this type of project, I'm all ears... You just can't see them unders me big ASCII hat.
Pete
- Steve to reply... Look, Pete just called himself a, " big ASCII hat. "
|
|
|
HELP, I've fallen out of SCREEN 0 and I can't Esc back! |
Posted by: Pete - 03-10-2024, 01:37 AM - Forum: Works in Progress
- No Replies
|
|
Code: (Select All)
$Color:32
Screen _NewImage(1100, 600, 32)
f& = _LoadFont("c:\windows\fonts\lucon.ttf", 16)
_Font f&
Color Black, _RGB32(255, 255, 255, 255)
Cls
_Delay .1
_ScreenMove 0, 0
x = 100
y = 100
maxchars = 90
a$ = "If I had a nickle for every good idea, I couldn't afford to give anyone my 2-cents."
sentence$ = Space$(maxchars): Mid$(sentence$, 1, Len(a$)) = a$
strng$ = GetField(sentence$, x, y, maxchars)
End
Function GetField$ (t$, x, y, maxchars)
t$ = Left$(t$ + Space$(maxchars), maxchars)
ccol = 1: cnew = ccol
Do:
_Limit 30
Line (x, y)-(x + _PrintWidth(t$) + 20, y + 16), _RGB32(255, 255, 255, 255), BF
Color _RGB32(0, 0, 0, 255), _RGB32(255, 255, 255, 255)
_PrintString (x, y), t$
If Timer > cc! Or cnew <> ccol Or ins_update Then
If ins_update = 1 And Timer < cc! Then
_KeyClear
_Continue ' Wait for one cursor cycle before next operation.
Else
bit = bit Xor 1
cc! = Timer + .25
c$ = Mid$(t$, ccol, 1)
chr_wdth = _PrintWidth(c$)
tx_row = _PrintWidth(Mid$(t$, 1, ccol)) - _PrintWidth(c$)
If overwritemode Then
Line (x + tx_row - 0, y)-(x + tx_row - 0 + chr_wdth, y + 16), _RGB32(bit * 200), BF ' insert cursor
If bit Then
Color _RGB32(255, 255, 255, 255), _RGB32(0, 0, 0, 255) ' Overwrite cursor.
_PrintString (x + tx_row, y), c$
End If
Else
Line (x + tx_row, y + 16)-Step(chr_wdth, 0), _RGB32(bit * 255) ' Underline cursor.
End If
_Display ' text and cursor
If ins_update = -1 Then ins_update = 1: _Continue Else ins_update = 0
End If
End If
cnew = ccol
b$ = InKey$
Select Case Len(b$)
Case Is = 1
ins_update = 0 ' Shut off cycle delay since ins key was not pressed.
If b$ = Chr$(27) Then ' Remove cursor and restore text before quitting.
Color _RGB32(0, 0, 0, 255), _RGB32(255, 255, 255, 255)
_PrintString (x, y), t$
_Display
End ' Esc
End If
If b$ = Chr$(13) Then ' Enter
GetField$ = LTrim$(RTrim$(t$))
_AutoDisplay
Exit Function
End If
If b$ = Chr$(8) Then ' backspace
If ccol > 1 Then
ccol = ccol - 1 - (ccol = 1)
t$ = Left$(t$, ccol - 1) + Right$(t$, maxchars - ccol) + " "
End If
_Continue
End If
If overwritemode Then
Mid$(t$, ccol, 1) = b$
If ccol < maxchars Then ccol = ccol + 1 Else cnew = -ccol ' Disables printing delay due to cursor non-movement.
Else
If Len(RTrim$(t$)) < maxchars Then
t$ = Left$(Left$(t$, ccol - 1) + b$ + Right$(t$, Len(t$) - ccol + 1) + Space$(10), maxchars)
If ccol < maxchars Then ccol = ccol + 1
End If
End If
Case Is = 2
a = Asc(Right$(b$, 1))
If ins_update And a <> 82 Then ins_update = 0 ' Shut off cycle delay since ins key was not pressed.
Select Case a
Case 71 ' Home
If ccol <> 1 Then ccol = 1
Case 79 ' End
If ccol < Len(RTrim$(t$)) + 1 And ccol < maxchars Then
If Len(RTrim$(t$)) = maxchars Then ccol = maxchars Else ccol = Len(RTrim$(t$)) + 1
End If
Case 82 ' Ins
If Not ins_update Then overwritemode = overwritemode Xor 1: ins_update = -1
Case 83 ' Del
If Len(RTrim$(t$)) And ccol <= Len(RTrim$(t$)) Then t$ = Left$(t$, ccol - 1) + Right$(t$, maxchars - ccol) + " ": cnew = -ccol
End Select
cur_arrows = ccol + (a = 75) - (a = 77) ' left or right arrow
If cur_arrows > ccol Then
If cur_arrows > Len(RTrim$(t$)) + 1 Or cur_arrows > maxchars Then
If cur_arrows > maxchars Then ccol = maxchars
Else
ccol = cur_arrows
End If
Else
If cur_arrows < ccol And cur_arrows > 0 Then ccol = cur_arrows
End If
End Select
Loop
End Function
This was a project I continued today from a few years back. My thanks the Richard Frost, who came up with a nice cursor routine for graphics screens. I modified that routine a bit, to cut down on some processing loops. I do a lot of WP stuff in screen 0, but I'm either going to have to take this new approach, or continue using some hardware image hybrids if I want to add so extra bells and whistles, like underlined and italic text.
The above example is bare bones, but missing mouse translation to graphics for now, as well as highlighting and scrolling input past the max characters point, it certainly is usable, as is , for smaller input tasks.
I'm also looking into some very cool text printing with hardware imaging, posted by MasterGY: https://qb64phoenix.com/forum/showthread...4#pid23644
QB64 has certainly opened up a world of possibilities. From Rob to Fell, and the developer crew still working on it today. Wow, you guys rock!
Pete
|
|
|
Some unicode symbols not supported. |
Posted by: Pete - 03-09-2024, 02:52 AM - Forum: Help Me!
- Replies (2)
|
|
Code: (Select All)
Option _Explicit
Screen _NewImage(800, 600, 32)
Dim fh As Long: fh = _LoadFont("cyberbit.ttf", 21)
If fh <= 0 Then
Print "Failed to load font file!"
End
End If
_Font fh
Restore text_data
Dim myString As String: myString = LoadUData$
_UPrintString (_Width \ 2 - _UPrintWidth(myString, 8, fh) \ 2, _Height \ 2 - _UFontHeight \ 2), myString, _Width, 8
End
text_data:
Data 6F
Data E2,96,95,E2,96,94,E2,96,94,E2,96,94,E2,96,94,E2,96,94,E2,96,94,E2,96,94,E2,96,94,E2,96,94,E2,96,94
Data E2,96,81 'Lower one eighth block won't display.
Data E2,96,8F 'Left one eighth block won't display.
Data E2,89,A1
Function LoadUData$
Dim As _Unsigned Long i, s
Dim d As String
Dim buffer As String
Read d
s = Val("&h" + d)
s = 42
buffer = Space$(s)
For i = 1 To s
Read d
Asc(buffer, i) = Val("&h" + d)
Next
LoadUData = buffer
End Function
What's funny is this routine will print that hamburger menu symbol ≡ I wasn't able to display to a screen a couple of years ago, but it misses on two of the outer one eighth blocks. When a symbol fails to display correctly, we get a hollow rectangle symbol in the display.
So is this a QB64 glitch?
Pete
|
|
|
|