View command in DOS

DOS specific questions.
Post Reply
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

View command in DOS

Post by dasyar »

In the program below, I was trying to figure out why the use of the 'view' command is not working as I expected. The program opens up showing the two buttons, but when I press the 'OK' inside of the view window, sometimes it responds immediately, but most of the time it does not seem to be responding. On the occasion that it does respond, when I press the 'view' button again, I do not get the window outline, just 'OK' button appears, and again sometimes that has an immediate response, but most of the time it does not respond.

Is this a problem with the way the 'view' command works in the DOS version? Or is this a major flaw in my program code.

Code: Select all

' test5.bas

#include "widgets.bi"

Screen 20
color 7,1:cls 'Paints BG blue-1, FG white-7
line (0,0)-(1023,767),45,b  '4 Outline the screen red border.

Dim Shared As Long mx,my,mb
Dim As String Key

Sub drawTitle()
  Line (2,2)-(1022,24),8,bf
  Draw String (450,5),"Test View Program",3
End Sub

Dim Shared As BUTTON btnQuit
Dim Shared As BUTTON btnApp
Dim Shared As BUTTON btnOK

' Quit button
btnQuit.x = 4  '0
btnQuit.y = 26  '0
btnQuit.w = 8 * 5
btnQuit.h = 16 * 8  '8
btnQuit.title = "Quit"
btnQuit.c2 = 0  ' ??Grey-8
btnQuit.c1 = 0  ' White

' Test application
btnApp.x = 44
btnApp.y = 26
btnApp.w = 8 * 8
btnApp.h = 16 * 8
btnApp.title = "View"
btnApp.c2 = 0
btnApp.c1 = 0

' OK button
btnOK.x = 190
btnOK.y = 95
btnOK.w = 8 * 8
btnOK.h = 16 * 8
btnOK.title = "OK"
btnOK.c2 = 0
btnOK.c1 = 0

drawTitle()
drawButton(btnQuit)
drawButton(btnApp)

Do
getmouse mx,my,,mb

  If mb = 1 Then
' This is the quit button.
    If mx>btnQuit.x And mx<btnQuit.x+btnQuit.w And my>btnQuit.y And my<btnQuit.y+16 Then
      End
    End If
' This is the view button.
    If mx>btnApp.x And mx<btnApp.x+btnApp.w And my>btnApp.y And my<btnApp.y+16 Then
      ' Create the view area.
      Line (210,125)-(600,240),44,bf ' 8 dark grey
      view (210,125)-(600,240)

      drawButton(btnOK)
      
      Do
        
        ScreenSync
'        ScreenLock
        getmouse mx,my,,mb
        If mx>btnOK.x And mx<btnOK.x+btnOK.w And my>btnOK.y And my<btnOK.y+16 Then
          Cls
          Exit Do
        End If
           
        While mb = 1
          getmouse mx,my,,mb
        Wend
        sleep 100
'        ScreenUnlock
      Loop
    End If

' mouse event
  While mb = 1
    getmouse mx,my,,mb
  Wend
  End If
sleep 1,0
Loop until multikey(&H01)

End

counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: FreeDOS 21st century?

Post by counting_pine »

Does the problem occur in DOS only? If so, this is probably worth splitting to a new thread.
If not, it's probably worth moving this to the General subforum.
I'm don't think I'm familiar with widgets.bi..
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: FreeDOS 21st century?

Post by dasyar »

widgets.bi, that is just my lib that I created to hold the button code. I also just tried the chain() command, it seems to work differently when you have a 'screen 20' in the code. I am strictly testing in the DOS environment, it seems like some of these commands are working differently when used in a graphic mode. And, why is 1024x748 video mode the highest that is available for the DOS version. Most of todays monitors are 1280x1020. Yea, I know, nobody uses DOS anymore.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: View command in DOS

Post by counting_pine »

We can't run your code without widgets.bi. Even if we do, testing/verifying the behaviour will be a whole other hurdle.
Maybe you can reduce the problem down to a small, reproducible test case?
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: View command in DOS

Post by dasyar »

The program below has the complete code, all you have to do is compile and run. The initial screen shows two buttons, quit and view. When you click the view button, that opens up a window which has the OK button. When you press the OK button it is supposed to close the window and make the quit and view buttons active again.

The problem is that when you click the OK button, that action is not closing the window, but sometimes it does close the window. It is very inconsistent, it probably does not work more than it does work. So, that is what I cannot figure out, is it a problem with my code, or is it a problem with the way the 'view' command works in the DOS version. The program below is about the smallest I can make in order to show the problem.

Code: Select all

' test5.bas
'
' Feb 26,2019
' Problem with clicking the 'OK' button
' while in the 'view' selection.


Screen 20
color 7,1:cls 'Paints BG blue-1, FG white-7
line (0,0)-(1023,767),45,b  '4 Outline the screen red border.

Dim Shared As Long mx,my,mb
Dim As String Key

Type BUTTON
  As String title
  As Integer x
  As Integer y
  As Integer w
  As Integer h
  As ulong c1
  As ulong c2
  As Integer a
End Type

Sub drawButton(btn as BUTTON)
  Line (btn.x,btn.y)-(btn.x+btn.w,btn.y + 24),3,bf  'Box 
  Line (btn.x,btn.y)-(btn.x+btn.w,btn.y + 24),0,b   'Box outline 16
  Draw String (btn.x+4,btn.y+4),btn.title,btn.c1 
End Sub

Sub drawTitle()
  Line (2,2)-(1022,24),8,bf
  Draw String (450,5),"Test View Program",3
End Sub

Dim Shared As BUTTON btnQuit
Dim Shared As BUTTON btnApp
Dim Shared As BUTTON btnOK

' Quit button
btnQuit.x = 4  '0
btnQuit.y = 26  '0
btnQuit.w = 8 * 5
btnQuit.h = 16 * 8  '8
btnQuit.title = "Quit"
btnQuit.c2 = 0  ' ??Grey-8
btnQuit.c1 = 0  ' White

' Test application
btnApp.x = 44
btnApp.y = 26
btnApp.w = 8 * 8
btnApp.h = 16 * 8
btnApp.title = "View"
btnApp.c2 = 0
btnApp.c1 = 0

' OK button
btnOK.x = 190
btnOK.y = 95
btnOK.w = 8 * 8
btnOK.h = 16 * 8
btnOK.title = "OK"
btnOK.c2 = 0
btnOK.c1 = 0

drawTitle()
drawButton(btnQuit)
drawButton(btnApp)

Do
getmouse mx,my,,mb

  If mb = 1 Then
' This is the quit button.
    If mx>btnQuit.x And mx<btnQuit.x+btnQuit.w And my>btnQuit.y And my<btnQuit.y+16 Then
      End
    End If
' This is the view button.
    If mx>btnApp.x And mx<btnApp.x+btnApp.w And my>btnApp.y And my<btnApp.y+16 Then
      ' Create the view area.
      Line (210,125)-(600,240),44,bf ' 8 dark grey
      view (210,125)-(600,240)

      drawButton(btnOK)

      Do
        
        ScreenSync
'        ScreenLock
        getmouse mx,my,,mb
        If mx>btnOK.x And mx<btnOK.x+btnOK.w And my>btnOK.y And my<btnOK.y+16 Then
          Cls
          Exit Do
        End If
           
        While mb = 1
          getmouse mx,my,,mb
        Wend
        sleep 100
'        ScreenUnlock
      Loop
    End If

' mouse event
  While mb = 1
    getmouse mx,my,,mb
  Wend
  End If
sleep 1,0
Loop until multikey(&H01)

End

fxm
Moderator
Posts: 12083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: View command in DOS

Post by fxm »

GETMOUSE statement always follows the physical pixel (not the view mapping).

GETMOUSE documentation page:
.....
If in graphics mode, x and y will always be returned in pixel coordinates still relative to the upper left corner of the screen, which is at 0,0 in this case; custom coordinates system set via View or Window do not affect the coordinates returned by Getmouse.
.....
For example (minimum change, but to be improved):

Code: Select all

' test5.bas
'
' Feb 26,2019
' Problem with clicking the 'OK' button
' while in the 'view' selection.


Screen 20
color 7,1:cls 'Paints BG blue-1, FG white-7
line (0,0)-(1023,767),45,b  '4 Outline the screen red border.

Dim Shared As Long mx,my,mb
Dim As String Key

Type BUTTON
  As String title
  As Integer x
  As Integer y
  As Integer w
  As Integer h
  As ulong c1
  As ulong c2
  As Integer a
End Type

Sub drawButton(btn as BUTTON)
  Line (btn.x,btn.y)-(btn.x+btn.w,btn.y + 24),3,bf  'Box
  Line (btn.x,btn.y)-(btn.x+btn.w,btn.y + 24),0,b   'Box outline 16
  Draw String (btn.x+4,btn.y+4),btn.title,btn.c1
End Sub

Sub drawTitle()
  Line (2,2)-(1022,24),8,bf
  Draw String (450,5),"Test View Program",3
End Sub

Dim Shared As BUTTON btnQuit
Dim Shared As BUTTON btnApp
Dim Shared As BUTTON btnOK

' Quit button
btnQuit.x = 4  '0
btnQuit.y = 26  '0
btnQuit.w = 8 * 5
btnQuit.h = 16 * 8  '8
btnQuit.title = "Quit"
btnQuit.c2 = 0  ' ??Grey-8
btnQuit.c1 = 0  ' White

' Test application
btnApp.x = 44
btnApp.y = 26
btnApp.w = 8 * 8
btnApp.h = 16 * 8
btnApp.title = "View"
btnApp.c2 = 0
btnApp.c1 = 0

' OK button
btnOK.x = 190
btnOK.y = 95
btnOK.w = 8 * 8
btnOK.h = 16 * 8
btnOK.title = "OK"
btnOK.c2 = 0
btnOK.c1 = 0

drawTitle()
drawButton(btnQuit)
drawButton(btnApp)

Do
getmouse mx,my,,mb

  If mb = 1 Then
' This is the quit button.
    If mx>btnQuit.x And mx<btnQuit.x+btnQuit.w And my>btnQuit.y And my<btnQuit.y+16 Then
      End
    End If
' This is the view button.
    If mx>btnApp.x And mx<btnApp.x+btnApp.w And my>btnApp.y And my<btnApp.y+16 Then
      ' Create the view area.
      Line (210,125)-(600,240),44,bf ' 8 dark grey
      view (210,125)-(600,240)

      drawButton(btnOK)

      Do
       
        ScreenSync
'        ScreenLock
        getmouse mx,my,,mb
        mx = mx - 210  '' <==========
        my = my - 125  '' <==========
        If mx>btnOK.x And mx<btnOK.x+btnOK.w And my>btnOK.y And my<btnOK.y+16 And mb=1 Then  '' <==========
          Cls
          Exit Do
        End If
           
        While mb = 1
          getmouse mx,my,,mb
        Wend
        sleep 100
'        ScreenUnlock
      Loop
    End If

' mouse event
  While mb = 1
    getmouse mx,my,,mb
  Wend
  End If
  view  '' <==========
sleep 1,0
Loop until multikey(&H01)

End

dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: View command in DOS

Post by dasyar »

I made the changes that fxm had suggested, and it sort of works. I had to remove the 'view' command, because that did not work as expected.

So, when you click on the view button it opens the window, which is to be expected. But, when you move the mouse cursor over the OK button the window closes, not what I expected. I thought you would have to move the mouse cursor to the OK button and then click the OK button to close the view window.

The next problem, that still persists, is that when you close the view window via the OK button and then click the view button again, only the OK button shows up on the screen. I was expecting that the complete view window would be redrawn.

At least now the program does not lock up, and you have a sort of functioning OK button. So, two things, not sure why the window is not redrawn, and why the OK button activates when you do a pass over the button.
fxm
Moderator
Posts: 12083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: View command in DOS

Post by fxm »

My proposed code changes above solve all these last points.
(each of my 4 modified lines is highlighted by "<==========")
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: View command in DOS

Post by dasyar »

Thanks for the suggestions fxm, I guess it was the fault of my coding. The next thing that I would like to try is to have a program start up when I click a button on the main window. Maybe add a line of code within the view code that would start up an external program, then when the external program ends the main window reappears. I tried a quick shell "newterm.exe" command, with some very bad results. I think it did not like the idea of being started with the confines of the view window.
Post Reply