MEGAMAX MODULA-2 - examples

C and PASCAL (or any other high-level languages) in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

tcat
Atari freak
Atari freak
Posts: 73
Joined: Fri May 03, 2013 6:00 am

MEGAMAX MODULA-2 - examples

Postby tcat » Fri Sep 06, 2013 6:53 pm

Hi,

I am making my first steps with MM2 programming environment. I learnt to work with keyboard. menus, resources, events, dialogs and windows, making use of the core MM2 modules. These are really the steps of a beginner.

One sample I wish to share here, is a two window demo application, showing what happens when one window overlaps the other and then is moved, or the other comes to the top, GEM sends events for just certain parts of a window to be redrawn.

Please see picture.
mm2-clip.png

It seems to work as it should except when the top window overlaps with the bottom one, and the bottom comes to the top, the whole window area is redrawn, not just the part that was hidden.

MM2 expects that each module or a symbol has to be imported before use.
I have two floppy MM2 system, the boot disk with MM2 shell and a user disk. Applications are compiled as modules MOD, that can be executed right from the MM2 shell. Can also be later linked to PRG, TOS or ACC, to run from the GEM.

TCAT
You do not have the required permissions to view the files attached to this post.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: MEGAMAX MODULA-2 - examples

Postby Mikefulton » Thu Jan 07, 2016 7:34 am

tcat wrote:It seems to work as it should except when the top window overlaps with the bottom one, and the bottom comes to the top, the whole window area is redrawn, not just the part that was hidden.
TCAT


This is just the way your redraw code is doing things. It's walking the rectangle list of the window, but it's not looking at the RECT of the "dirty" area in the redraw message.

When you walk the window's rectangle list, you're getting the VISIBLE portions of the window, not the "dirty" parts. A topped window will only have one rectangle for the entire window.

If you only want to redraw the "dirty" area, then as you walk the rectangle list you need to calculate the intersection of each rectangle with the one from the redraw message, set the clipping, and draw.

-----
I know it's an old post but it seemed like it could still be relevant.

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 687
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: MEGAMAX MODULA-2 - examples

Postby mfro » Thu Jan 07, 2016 7:42 am

Mikefulton wrote:... It's walking the rectangle list of the window, but it's not looking at the RECT of the "dirty" area in the redraw message....


which can be a perfectly valid design decision (no objection) at times, considering the complexity of the drawing code.

Depending on the drawing logic, drawing only a part of the scene might require clipping, which can dramatically slow down redraw performance. It's a case by case decision what's better.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: MEGAMAX MODULA-2 - examples

Postby Mikefulton » Thu Jan 07, 2016 12:25 pm

mfro wrote:
Mikefulton wrote:... It's walking the rectangle list of the window, but it's not looking at the RECT of the "dirty" area in the redraw message....


which can be a perfectly valid design decision (no objection) at times, considering the complexity of the drawing code.

Depending on the drawing logic, drawing only a part of the scene might require clipping, which can dramatically slow down redraw performance. It's a case by case decision what's better.


Your argument leads me to wonder if you understood. Getting the intersection of the "dirty" area will typically result in a smaller area that needs to be redrawn. The best way to save time on a redraw is to avoid drawing objects you know are completely outside the current clip rectangle, and a smaller (intersected) rectangle means (potentially) that you have fewer things to draw.

BTW, there's really no such thing as "no clipping". When you "turn clipping off" all that really happens is that the clipping rectangle is set to match the screen boundaries. Setting the clip area to a smaller rectangle means that it avoids pushing pixels to the screen, so it should usually be faster. (Most likely the difference would not be perceptible to the viewer, however.)

Can you provide an example of a program where drawing the window was noticeably faster with clipping turned off? That seems unlikely and my guess would be that there was something else going on.

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 687
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: MEGAMAX MODULA-2 - examples

Postby mfro » Thu Jan 07, 2016 2:18 pm

Mikefulton wrote:BTW, there's really no such thing as "no clipping". When you "turn clipping off" all that really happens is that the clipping rectangle is set to match the screen boundaries. Setting the clip area to a smaller rectangle means that it avoids pushing pixels to the screen, so it should usually be faster. (Most likely the difference would not be perceptible to the viewer, however.)

I can't tell for all VDI implementations, but I seriously doubt that for at least the "standard" LineA-based one we all know. Most (if not all) of the VDI output functions just wrap around to the next scanline if you draw off the right screen border with clipping off.

Clipped VDI (v_gtext()) output, for example, gets dramatically slower with clipping enabled. It does clip-checks for every single character if clipping is enabled.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: MEGAMAX MODULA-2 - examples

Postby Mikefulton » Fri Jan 08, 2016 12:16 am

On reflection, you might be right. I may have been thinking about the printer driver stuff, not the screen driver.

tcat
Atari freak
Atari freak
Posts: 73
Joined: Fri May 03, 2013 6:00 am

Re: MEGAMAX MODULA-2 - examples

Postby tcat » Wed Feb 03, 2016 8:06 pm

Hi Folks,

I have been away from ATARI for some time, doing mainly QL stuff. Now I see my old posts raised some interest. I am looking into the code, trying to understand what I meant more than 2 years ago. I share, it is my learning example, possibly far from excellent.

Cheers
Tom

WINDOWS.M module listing ...

Code: Select all

MODULE Windows;


FROM GEMEnv IMPORT RC, InitGem, ExitGem, CurrGemHandle, DeviceHandle, GemHandle,
                   GemError;

FROM GEMGlobals IMPORT GemChar, MouseButton, MButtonSet, SpecialKey,
                       SpecialKeySet, solidFill, hollowFill;
                     
FROM GrafBase   IMPORT Rect, Pnt, Point, Rectangle, ClipRect, TransRect,
                       black, white, red;
FROM AESEvents  IMPORT KeyboardEvent, MessageBuffer, MultiEvent, Event,
                       EventSet, RectEnterMode,
                       windMoved, windSized, windTopped, windRedraw;
                       
FROM AESWindows  IMPORT CreateWindow, OpenWindow, SetWindowSize, DeleteWindow,
                        SetWindowString, SetTopWindow,
                        UpdateWindow, WindowRectList, WindowSize,
                        WindowElement, RListMode, WElementSet, NoWindow,
                        WStringMode, WSizeMode;
                       
FROM AESGraphics IMPORT GrafMouse, MouseForm;
                       
FROM VDIOutputs    IMPORT Bar, Line, GrafText;
FROM VDIControls   IMPORT SetClipping, DisableClipping;
FROM VDIAttributes IMPORT SetFillColor, SetFillType, SetLineColor;
                       
FROM PrgCtrl    IMPORT TermProcess;
FROM Strings    IMPORT String;
FROM SYSTEM     IMPORT ADR, CADR;


VAR     dev     : DeviceHandle;
        gemHdl  : GemHandle;
        success : BOOLEAN;
       
        msg     : MessageBuffer;
        mouse   : Point;
        buttons : MButtonSet;
        keys    : SpecialKeySet;
        clicks  : CARDINAL;
        key     : GemChar;
        events  : EventSet;
       
        windHdl, wind2Hdl : CARDINAL;
        windRect: Rectangle;


PROCEDURE msgBox (msg : String; gemHdl : GemHandle; exitGem : BOOLEAN);
VAR
      gemCh : GemChar;
BEGIN
      KeyboardEvent (gemCh);
      IF exitGem THEN
        ExitGem (gemHdl);
        TermProcess (0);
      END;
     
END msgBox;


PROCEDURE RedrawWindow (handle : CARDINAL ; frame : Rectangle);
VAR
        work : Rectangle;
BEGIN
        work := WindowSize (handle, workSize);
       
        SetLineColor (dev, red);
        SetFillColor (dev, red);
        SetFillType (dev, hollowFill);
       
        Bar (dev, frame);
        WITH frame DO
          Line (dev, Pnt(x,y), Pnt(x+w-1,y+h-1) );
          Line (dev, Pnt(x+w-1,y), Pnt(x,y+h-1) );
        END;
       
        IF handle = windHdl THEN
          GrafText (dev, Pnt(work.x+5, work.y+15), 'Clip1')
        ELSIF handle = wind2Hdl THEN
          GrafText (dev, Pnt(work.x+5, work.y+15), 'Clip2') END;
       
END RedrawWindow;


PROCEDURE RedrawFrame (handle : CARDINAL; frame : Rectangle);
VAR
        clip : Rectangle;
BEGIN
        SetFillType (dev, solidFill);
        SetFillColor (dev, white);
        UpdateWindow (TRUE);
        GrafMouse (mouseOff, NIL);

        clip := WindowRectList (handle, firstElem);
        WHILE clip.w # 0 DO
         
          clip := ClipRect (frame, clip);
          IF clip.w # 0 THEN
            SetClipping (dev, clip);
            Bar (dev, clip);
            RedrawWindow (handle, clip);
          END;
         
          clip := WindowRectList (handle, nextElem);
        END;
       
        DisableClipping (dev);
        GrafMouse (mouseOn, NIL);
        UpdateWindow (FALSE);
       
END RedrawFrame;



BEGIN

  InitGem (RC, dev, success);
  IF success THEN
    gemHdl := CurrGemHandle ();
   
    GrafMouse (arrow, NIL);
    windRect := Rect(20,20,70,70);
   
    CreateWindow ( WElementSet {nameBar, mover}, windRect, windHdl);
    IF windHdl = NoWindow THEN
      msgBox ('Cannot create window!', gemHdl, TRUE) END;
     
    SetWindowString (windHdl, nameStr, CADR ('Sample') );
 
    CreateWindow ( WElementSet {nameBar, mover}, windRect, wind2Hdl);
    IF wind2Hdl = NoWindow THEN
      msgBox ('Cannot create window!', gemHdl, TRUE) END;
     
    SetWindowString (wind2Hdl, nameStr, CADR ('Sample') );
   
    OpenWindow (windHdl, windRect);
    OpenWindow (wind2Hdl, TransRect (windRect, Pnt (40,55)) );
 
    REPEAT
   
      MultiEvent (EventSet {keyboard, mouseButton, message}, 2,
                MButtonSet {msBut1,msBut2}, MButtonSet {msBut1},
                lookForEntry, Rect (0,0,0,0),
                lookForEntry, Rect (0,0,0,0),
                msg, 0, mouse, buttons, keys, key, clicks, events);
     
      IF message IN events THEN
        CASE msg.msgType OF
          windMoved : SetWindowSize (msg.moveHdl, msg.moveFrame) |
          windTopped : SetTopWindow (msg.topHdl) |
          windRedraw : RedrawFrame (msg.rdrwHdl, msg.rdrwFrame) |
           
          ELSE ;
        END;
      END;
     
    UNTIL key.ascii = 'q';
    DeleteWindow (windHdl);
    DeleteWindow (wind2Hdl);
    ExitGem (gemHdl);
     
  END;

END Windows.

MrWeb
Atarian
Atarian
Posts: 1
Joined: Sat Dec 10, 2016 11:58 pm

Re: MEGAMAX MODULA-2 - examples

Postby MrWeb » Sun Dec 11, 2016 1:07 pm

Hey tcat,

I've send you an e-mail via the forums! Unfortunately, I'm not able to send private messages yet. :(
I'm trying to use Megamax Modula-2 as well at the moment, would be glad to get a reply!

best regards
MrWeb

tcat
Atari freak
Atari freak
Posts: 73
Joined: Fri May 03, 2013 6:00 am

Re: MEGAMAX MODULA-2 - examples

Postby tcat » Mon Dec 12, 2016 6:53 pm

Hi MrWeb,

I took some interest in MM-2 as I learnt `Oxyd' was coded using this development tool.
I still consider myself a good starter, not professional coder in MM-2.

You may send your emails to thomas.kral(at)email.cz, while you cannot PM.

You may also follow some old discussion here:
viewtopic.php?f=70&t=25242


Ciao,
Tomas


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 2 guests