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

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

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

Post by Theophage » Mon Jun 12, 2006 2:44 pm

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?
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."

MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows » Mon Jun 12, 2006 2:58 pm

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. :-).
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com

User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage » Mon Jun 12, 2006 9:48 pm

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?
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."

User avatar
The Walrus
Veteran
Posts: 85
Joined: Fri Apr 01, 2005 7:19 am
Location: Denmark
Contact:

Post by The Walrus » Tue Jun 13, 2006 7:40 pm

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.
If swimming is so good for your figure, how do you explain walruses?

User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage » Tue Jun 13, 2006 10:46 pm

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)
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."

User avatar
The Walrus
Veteran
Posts: 85
Joined: Fri Apr 01, 2005 7:19 am
Location: Denmark
Contact:

Post by The Walrus » Wed Jun 14, 2006 5:06 am

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.
If swimming is so good for your figure, how do you explain walruses?

User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage » Wed Jun 14, 2006 2:50 pm

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?
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."

User avatar
The Walrus
Veteran
Posts: 85
Joined: Fri Apr 01, 2005 7:19 am
Location: Denmark
Contact:

Post by The Walrus » Thu Jun 15, 2006 3:22 pm

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.
If swimming is so good for your figure, how do you explain walruses?

User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage » Thu Jun 15, 2006 5:22 pm

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...
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."

User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage » Thu Jun 15, 2006 5:52 pm

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...
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."

User avatar
The Walrus
Veteran
Posts: 85
Joined: Fri Apr 01, 2005 7:19 am
Location: Denmark
Contact:

Post by The Walrus » Fri Jun 16, 2006 8:21 am

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.
If swimming is so good for your figure, how do you explain walruses?

RyanKelly
Coder
Posts: 48
Joined: Sun Jan 22, 2006 6:40 pm
Contact:

Post by RyanKelly » Sat Jun 17, 2006 8:05 pm

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

Post Reply