Tech Note 25e: Using Windows

May 01, 2008

© NSB Corporation. All rights reserved.

I posted my question about the CreateWindow command before. I don't use the command in my applications "Amisol" and "AmiKuji", but bitmaps are drawn on the screen by default. So I was wondering why we need the CreateWindow command.

Then, when I was thinking to create a next application, I got a question:
What happens if I try to display a bitmap which is larger than the graphic area specified by CreateWindow?

To test it, I prepared this large bitmap (98x151), and draw it in the defined area (60x60).

          Define: CreateWindow("Test",50,50,60,60)
Draw: SetCurrentWindow "Test" DrawBitmap 1005,0,0
GWH: need to fix these images.
    +         =    

As I expected, the graphic window area was drawn. From the result, the top left corner of the defined window seems to be coordinates (0,0) for the bitmap.

Next, I changed the coordinates like:

        DrawBitmap 1005,10,5



In this case, putting positive numbers is OK, but if you put a negative number such as:
        DrawBitmap 1005,-10,5

Then it causes a compile-time error. This was a disappointing fact if I can't specify a negative number.

However, moving a bitmap within a window was still attractive. So I prepared a global variables and made the following window.
Tapping [U], [D], [L] and [R] buttons moves the bitmap to the tapped direction.



I didn't write a check routine for the negative coordinates -- in the worst case, the device would hang but I didn't care because I was testing. However, it accepted the negative numbers.



With this fact I think I found a practical way to use the graphic window. Maybe we can apply this method to game applications. However, it is not clear why specifying with constants causes the compile error. I think that the compiler would accept only alphabets or numbers as the argument of DrawBitmap. It is just my guess, but if it were true, there might be more commands that behave the same.

Another thing I noticed was that the coordinates I got by GetPen was the coordinates of the current window. I found this after adding code to display the tapped coordinates. The program is sample03.prc.

It is easy to test. First, tap [U], [D], [L] and [R] to move the image. When the image is drawn, the current window is the small window in the center of the screen. At this point the label displays the coordinates of the tapped position (0,0)-(159,159). In this state, if you tap on the image in the center, its coordinates is displayed based on the small window (0,0)-(59,59).

Then, tap the screen where no window underneath. This makes the whole window current. If you tap the image in the middle, the displayed coordinates are based on the whole window. Therefore, when you read coordinates by GetPen, you have to know which one is the current window.

There is one more thing I noticed, which may be a bug. Changing the Text property when the image is current, the coordinates are displayed, instead of the top of the screen, at the relative position where the label is placed in the current window.


Can you see a part of coordinates in the circle?

In this program, the window is defined by CreateWindows("main",0,0,160,160,), and when the tapped coordinates are displayed, the program makes this windows current. It can be understandable that drawing happens in the current window, but it may not be acceptable to have an object placed at a different place.

So there is a little problem, but with CreateWindow you can easily scroll images in NS Basic.