Page 1 of 1

View Ports (no, not that question down at the bottom)

Posted: Mon Jun 12, 2006 2:44 pm
by Theophage
Okay, my question is what is the point of using the Viewport commands in QBASIC like "VIEW" and "WINDOW"? Why would I want to use those? Is there a good example?

Posted: Mon Jun 12, 2006 2:58 pm
by MystikShadows
Hi Theopage,

One of the more spreadout reasons to use a viewport or window and such is in GUI Development among other things.

but in a game, nothing's stoping you from having, for example, the main game area, and other sub windows to display player and game status for example. :-).

Posted: Mon Jun 12, 2006 9:48 pm
by Theophage
And that is exactly what I mean. If I'm making a program with QB, and I want a message area here, a creature graphic area there, a map graphic area there, and a comman area there, I'm going to do all those things separately myself.

In fact, (if I understand correctly) I would have to do those things myself because the viewport commands only let me mark off one text area and one graphics area.

So if I'm going to have to delineate these areas myself and treat them separately anyway (use LOCATE to print things here, input things there, put graphics here and here) then why would I ever want to use the veiwport commands? It's like somebody just stuck these commands in there without even really thinking about it.

Imagine if there was a DRAWPACMAN command. That might be mighty useful if I were making a pacman game, but if I wasn't, and I had to make my character sprites separately 99% of the time anyway, then that would be really useless and a waste of a command.

Am I missing something? Are these commands really as useless as that?

Posted: Tue Jun 13, 2006 7:40 pm
by The Walrus
One example is in a GUI, where you can set a viewport when drawing a window. That way controls won't go outside the window, but will get clipped instead. I find that pretty useful.

Posted: Tue Jun 13, 2006 10:46 pm
by Theophage
But isn't it good for only one window, or am I reading it wrong? Can you give me a little more of a detailed example? (I'm still just not picturing it)

Posted: Wed Jun 14, 2006 5:06 am
by The Walrus
What I'm doing is this: I draw the window, and set a viewport where the controls on it should be. Then they won't go outside the window. Then I do the same with the next window, and so on. So I call VIEW each time I draw a window.

Posted: Wed Jun 14, 2006 2:50 pm
by Theophage
See now that makes sense, though I didn't know you could set more than one at once. Would you happen to have some example code I could look at?

Posted: Thu Jun 15, 2006 3:22 pm
by The Walrus
You can't, you can only have one viewport. But you can change the coordinates of the viewport each time you draw a window. That's the method I use in my GUI.

Posted: Thu Jun 15, 2006 5:22 pm
by Theophage
Only one, that's what I thought. It still sounds pretty much like a one-trick pony. I'm going to check out your gui, though, and see how it looks.

EDITED TO ADD:

Well I tried to check it out, I created the cpath.ini file just like it said to do, and I still get an error when trying to run it (Path not found in module RUNNER at address 056D:0125)

My cpath.ini file contains this:
C:\Documents and Settings\Owner\Desktop\Costa080\

which is the correct path to the COSTA.EXE file.

I would just like to see an example of the viewport commands in use that at least attempts to justify their existance. (The example given in the QB help file certainly doesn't) I still just don't see the point for a couple of dedicated commands for this which would seem to be more likley a user-written routine.

QB has this but won't spare two more commands to use the mouse! I know, that's a whole 'nother kettle of fish...

Posted: Thu Jun 15, 2006 5:52 pm
by Theophage
BUGGER!

Ok, I figured out the problem with the path files, I should have realized that a QB based program would not like paths with folders like "Documents and Settings" in them, so I changed that part to "docume~1" and the program started up fine.

Until I tried to read the text. I have one of those machines that apparently doesn't like it when QB programmers read the font bitmaps from the bios and try to display them cleverly; all I get is garbage. So now I can see your nifty login screen, but can't figure out what to do since I can't read it, and I still haven't seen any useful example of the VIEW or WINDOW commands.

I sense a conspiracy...

Posted: Fri Jun 16, 2006 8:21 am
by The Walrus
The version of my GUI you tried out is outdated, it was released about half a year ago and doesn't have a windowing engine (it just draws windows so it looks like it does). It doesn't use VIEW and WINDOW, and it doesn't do much.

The reason nothing has been released for such a long time is that I've been working on a complete rewrite with moveable windows, plus I've been extremely busy. I don't have anything to show you at the moment, but I'm planning on releasing the next beta in a month or so.

Posted: Sat Jun 17, 2006 8:05 pm
by RyanKelly
Theophage, the Window and View facilitates QB's custom coordinate system, which is in effect whether you use it not, which means that QB's graphics routine perform the same calculations to effect coordinate translation all the time. You could implement such translation on your own, and the end result is that your final program will contain redundant code.

Also, by your line of reasoning, LINE and CIRCLE are useless because you could always implement lines and circle using pset.

Consider this:

Code: Select all

SCREEN 13

'a sine wave with WINDOW
WINDOW (0, -1)-(6.28318, 1)
FOR x = 0 TO 6.28318 STEP 6.28318 / 320
    PSET (x, SIN(x)) 'no calculations inside the loop
NEXT x

DO
    k$ = INKEY$
LOOP WHILE k$ = ""

WINDOW
CLS

'a sine wave without WINDOW
FOR x = 0 TO 319 
   'four calculations inside the loop 
   theta = x * 6.28318 / 320
    PSET (x, 100 - 100 * (SIN(theta))) 
NEXT x