[comp.lang.pascal] TP type cast/conversion woes

oecheruo@silver.ucs.indiana.edu (Chima Echeruo) (03/13/91)

I am working on a small windowing system for use in some educational
applications. To handle the mouse I am using a freeware mouse TPU. My problem
is that all the mouse routines take words while most  of my own routine uses
integers. For simple things like comparing an integer variable (say a window
co-ord) with a word (say the mouse x-co-ord) the TP compiler produces
incorrect code.

I have looked throughout the manuals and online help and I cannot find a
convertion function or even a built in type conversion. Why can't I compare
a word and an integer to see which is greater or smaller.

If they have to be converted to some common type, why won't TP do the 
conversion at compile time - like any decent computer language.

Then, If I have to convert a word value to an integer how do I do that?
there is an Int function but it works only on real numbers.

===========================================================================

PS. On a different problem.

As I said earlier I am working on a graphics windowing unit. Well I have almost
NIL experience in graphics programming and  would like some tips about how
windows are implemented. I am most concerned about the sort of data structures
that one would use to allow  random access to any window. Right now, I use
a simple fixed array but I cannot tell the order in which the windows were
created since they new windows can be added anywhere in the array.

secondly, how can one implement overlapping windows given the fact that
the BGI graphics only understands one current window. I have avoided virtual
windows that allow updating even when they are partially hidden.

How do window systems like WIN 3 , GEM, Mac and TGL handle the huge amount
of background bitmaps that have to be stored whenever a dialog box pops over
the screen?

In general does one have to start from scratch to write one's on graphics
primitives such as lines and circles so as  to be able to control clipping 
and the rest?

I would be very happy to get information on these problems.

thanks a lot.

Chima Echeruo


PPS.

I use a 286, EGA and some extended RAM (384 KB).















--
-------------------------------------------------------------------------------
	        	----- Chima Oke Echeruo -----
   oecheruo@silver.ucs.indiana.edu   ++++++   oecheruo@amber.ucs.indiana.edu
-------------------------------------------------------------------------------

CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) (03/14/91)

In article <oecheruo.668797789@silver>, oecheruo@silver.ucs.indiana.edu
  (Chima Echeruo) wrote:

>I am working on a small windowing system for use in some educational
>applications. To handle the mouse I am using a freeware mouse TPU.
>My problem is that all the mouse routines take words while most  of
>my own routine uses integers. For simple things like comparing an
>integer variable (say a window co-ord) with a word (say the mouse
>x-co-ord) the TP compiler produces incorrect code.

Can you demonstrate this "incorrect code", please? I've just
examined the code for a sample program (shown below), and it appears
to me to be correct in all cases (using TPC.EXE 5.5 and 6.0).

Why do your routines use integers?

>I have looked throughout the manuals and online help and I cannot
>find a convertion function or even a built in type conversion. Why
>can't I compare a word and an integer to see which is greater or
>smaller.

Pending your demonstration, I'm inclined to say, "But you can."

>If they have to be converted to some common type, why won't TP do
>the conversion at compile time - like any decent computer language.

The examples I examined converted (at compile time) both words and
integers to double words (long integers) before comparing.

>Then, If I have to convert a word value to an integer how do I do
>that? there is an Int function but it works only on real numbers.

Type cast it--but beware of wrap around of words > MaxInt. Or just
assign it (same caveat).

        some_int := some_word;
        some_int := integer(some_word);

>PS. On a different problem.
>
>As I said earlier I am working on a graphics windowing unit. Well I
>have almost NIL experience in graphics programming and  would like

Hmmm...reading/writing to NIL is not always a good idea... (bad
joke, sorry... ;) )

>some tips about how windows are implemented. I am most concerned
>about the sort of data structures that one would use to allow
>random access to any window. Right now, I use a simple fixed array
>but I cannot tell the order in which the windows were created since
>they new windows can be added anywhere in the array.

Hopefully your "simple fixed array" is an array of pointers, not of
the window structures themselves. That being the case, the cost of
swapping items in the array is trivial, and you can keep the array
ordered as you please--possibly with the topmost window having the
highest current index value.

Windows are often implemented using stacks which are implemented
with arrays or linked lists.

>secondly, how can one implement overlapping windows given the fact
>that the BGI graphics only understands one current window. I have
>avoided virtual windows that allow updating even when they are
>partially hidden.

I'm not very knowledgable about BGI, and haven't tried a graphics
window implementation myself. Can't you just use SetViewPort to
change from one window to another? (Obviously you'd be responsible
for saving and restoring overwritten window contents. I'd think
GetImage and PutImage would do well for that.)

What version of TPas are you using? Do you have the documentation
for it?

Sample program for checking integer<->word comparisons:

{$R-,S-,V-,I-}

var
  w1, w2 : word;
  i1, i2 : integer;

begin
  if w1 < w2 then
    if i1 < i2 then
      if w1 < i1 then
        if i1 < w1 then;
end.

+--------------------------------------------------------------------+
| Karl Brendel                           Centers for Disease Control |
| Internet: CDCKAB@EMUVM1.BITNET         Epidemiology Program Office |
| Bitnet: CDCKAB@EMUVM1                  Atlanta, GA, USA            |
|                        Home of Epi Info 5.0                        |
+--------------------------------------------------------------------+

oecheruo@silver.ucs.indiana.edu (Chima Echeruo) (03/14/91)

CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) writes:
...[help about typecasts in pascal ]...

>In article <oecheruo.668797789@silver>, oecheruo@silver.ucs.indiana.edu
>  (Chima Echeruo) wrote:

>>I am working on a small windowing system for use in some educational
>>applications. To handle the mouse I am using a freeware mouse TPU.
>>My problem is that all the mouse routines take words while most  of
>>my own routine uses integers. For simple things like comparing an
>>integer variable (say a window co-ord) with a word (say the mouse
>>x-co-ord) the TP compiler produces incorrect code.

>Type cast it--but beware of wrap around of words > MaxInt. Or just
>assign it (same caveat).

>        some_int := some_word;
>        some_int := integer(some_word);



Now there was the problem.
I have recieved advice from a lot of kind people who point out that I can 
typecast integer type values by using word,integer etc..

>>some tips about how windows are implemented. I am most concerned
>>about the sort of data structures that one would use to allow
>>random access to any window. Right now, I use a simple fixed array
>>but I cannot tell the order in which the windows were created since
>>they new windows can be added anywhere in the array.

>Hopefully your "simple fixed array" is an array of pointers, not of
>the window structures themselves. That being the case, the cost of
>swapping items in the array is trivial, and you can keep the array
>ordered as you please--possibly with the topmost window having the
>highest current index value.

I used a fixed array but  will now modify it to use an array of pointers to
window strucs. then perhaps I will be able to sort on the fly without much 
swaping of data.

>>secondly, how can one implement overlapping windows given the fact
>>that the BGI graphics only understands one current window. I have
>>avoided virtual windows that allow updating even when they are
>>partially hidden.

>I'm not very knowledgable about BGI, and haven't tried a graphics
>window implementation myself. Can't you just use SetViewPort to
>change from one window to another? (Obviously you'd be responsible
>for saving and restoring overwritten window contents. I'd think
>GetImage and PutImage would do well for that.)

I have done that and it works great for small windows with a first-in-last out
sequence. Clicking on an obscured window now brings it to the front and restore
the client drawing space. However, ther are some problems with BGI viewport
routines.

1) You cannot draw to an overlapped window without destroying the topmost
one. That is , all viewports have to be rectangular and all drawing most
take place in the foreground.

2) Most of the BitMap routines do not work properly. BitMaps that have parts
of themselves exceeding the window boundry are not displayed and sometimes
crash the system. 

3) there is a no support of multiple windows or viewpoints in the BGI
   interface. 

4) No virtual windows or buffers that store windows.

>What version of TPas are you using? Do you have the documentation
>for it?

Oh yes, I'm legit.
I've got the TP 5.0 package with manuals.
I have resisted from buying thrid party books because I did not think that
there was much I needed to get started.

>+--------------------------------------------------------------------+
>| Karl Brendel                           Centers for Disease Control |
>| Internet: CDCKAB@EMUVM1.BITNET         Epidemiology Program Office |
>| Bitnet: CDCKAB@EMUVM1                  Atlanta, GA, USA            |
>|                        Home of Epi Info 5.0                        |
>+--------------------------------------------------------------------+

Thanks a lot for those who have helped out.
--
-------------------------------------------------------------------------------
	        	----- Chima Oke Echeruo -----
   oecheruo@silver.ucs.indiana.edu   ++++++   oecheruo@amber.ucs.indiana.edu
-------------------------------------------------------------------------------

bobb@vice.ICO.TEK.COM (Bob Beauchaine) (03/14/91)

In article <oecheruo.668901555@silver> oecheruo@silver.ucs.indiana.edu (Chima Echeruo) writes:
>
>2) Most of the BitMap routines do not work properly. BitMaps that have parts
>of themselves exceeding the window boundry are not displayed and sometimes
>crash the system. 
>

  Are you using the clipping variable in the setviewport call?  I have
  seen some rather disturbing behavior if this variable is not set
  to "clipon".    

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ 

Bob Beauchaine bobb@vice.ICO.TEK.COM 

C: The language that combines the power of assembly language with the 
   flexibility of assembly language.