FPGA - DIY Dialogs
Hi, Trying to draw a selection rectangle, aka `marching ants'. I do this, it makes selection east-rightwards only. I am surprised I need to call `DrawBox' in three places, otherwise it trails visual marks. I wish to keep the code minimal. How to make it in all directions? PROCEDURE DrawBox(x, y, w, h: INTEGER); (*selection rectangle*) BEGIN Display.ReplPattern(8, Display1.grey2, x, y, w, 1, Display.invert); Display.ReplPattern(8, Display1.grey2, x, y+h-1, w, 1, Display.invert); Display.ReplPattern(8, Display1.grey2, x, y, 1, h, Display.invert); Display.ReplPattern(8, Display1.grey2, x+w-1, y, 1, h, Display.invert) END DrawBox; PROCEDURE TrackSelection(M: Oberon.InputMsg); (*eastwards*) VAR x, y: INTEGER; keys: SET; BEGIN x := M.X; y := M.Y; REPEAT DrawBox(M.X, M.Y, ABS(M.X-x), ABS(M.Y-y)); Input.Mouse(keys, x, y); Oberon.DrawMouse(Crosshair, x, y); DrawBox(M.X, M.Y, ABS(M.X-x), ABS(M.Y-y)) UNTIL keys = {}; DrawBox(M.X, M.Y, ABS(M.X-x), ABS(M.Y-y)) END TrackSelection; -- Tomas Kral <thomas.kral@email.cz>
Try to make DrawBox(x0, y0, x1, y1). Jörg
Am 26.12.2018 um 23:20 schrieb Tomas Kral <thomas.kral@email.cz>:
Hi,
Trying to draw a selection rectangle, aka `marching ants'. I do this, it makes selection east-rightwards only. I am surprised I need to call `DrawBox' in three places, otherwise it trails visual marks. I wish to keep the code minimal. How to make it in all directions?
PROCEDURE DrawBox(x, y, w, h: INTEGER); (*selection rectangle*) BEGIN Display.ReplPattern(8, Display1.grey2, x, y, w, 1, Display.invert); Display.ReplPattern(8, Display1.grey2, x, y+h-1, w, 1, Display.invert); Display.ReplPattern(8, Display1.grey2, x, y, 1, h, Display.invert); Display.ReplPattern(8, Display1.grey2, x+w-1, y, 1, h, Display.invert) END DrawBox;
PROCEDURE TrackSelection(M: Oberon.InputMsg); (*eastwards*) VAR x, y: INTEGER; keys: SET; BEGIN x := M.X; y := M.Y; REPEAT DrawBox(M.X, M.Y, ABS(M.X-x), ABS(M.Y-y)); Input.Mouse(keys, x, y); Oberon.DrawMouse(Crosshair, x, y); DrawBox(M.X, M.Y, ABS(M.X-x), ABS(M.Y-y)) UNTIL keys = {}; DrawBox(M.X, M.Y, ABS(M.X-x), ABS(M.Y-y)) END TrackSelection;
-- Tomas Kral <thomas.kral@email.cz> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On Thu, 27 Dec 2018 10:44:30 +0100 Jörg Straube <joerg.straube@iaeth.ch> wrote:
Try to make DrawBox(x0, y0, x1, y1).
Done, does things using a dotted pattern. Now, I try to move objects (rectangles) on the screen. Not perfect so far, as it trails cursor Oberon.DrawMouse(); I use the same dotted rectangle to mark move position until middle key release. When moving only one object, then updating background, is just redrawing one/two rectangles, depending if it overlaps itself or not. PLS see pict. My approach so far is, to distribute Frames.Handle(F, M) to objects as found at x,y coord. I need o.Draw(), o.Handle() two dynamic methods and an Update message (todo) for that, as it seems. Perhaps I set on a difficult task for me, but is quite catchy. I wish to put it in as simple coding as possible, but appears complicated. -- Tomas Kral <thomas.kral@email.cz>
Hi, DIY Dialogs, do so far only simple things. But, how can I tie it to some main computing module? I provide each dialog object with a unique id, as my idea initially was to somehow broadcast a message, {object-id, {changed, clicked, moved, ...}, value {value}}. But I really do not know. I prefer it simple, with not much coding, so other alternative is to use dialogs only as a skeleton to be tailored for each GUI application. What do you think? -- Tomas Kral <thomas.kral@email.cz>
Hi, In support of `System.Grow', `System.Copy', it seems basically only this statement is needed in response to `CopyMsg'. PROCEDURE Handle*(F: Display.Frame; VAR M: Display.FrameMsg); ... CASE F OF Frame: CASE M OF | Oberon.CopyMsg: M.F := F ... It does not seem so obvious from Chapters 3-4. -- Tomas Kral <thomas.kral@email.cz>
Hi, When storing dialog objects, I somehow wish to compress the object name strings. One idea coming to my mind, store a unique name list first, and then store only object ids with reference to the list. So there are no names duplicated in files, this may reduce file storage size? Any better idea? ObjName = ARRAY 32 OF CHAR; ObjDesc* = RECORD do*: Methods; x*, y*, w*, h*: INTEGER; next: Object; id*: INTEGER; mod*: ObjName (*take out to its own module list*) END; PROCEDURE Store*(VAR r: Files.Rider); VAR o: Object; BEGIN o := first; (*TODO store unique names list first*) WHILE o # NIL DO Files.WriteString(r, o.mod); (* TODO write ids only*) Files.WriteInt(r, o.x); Files.WriteInt(r, o.y); Files.WriteInt(r, o.w); Files.WriteInt(r, o.h); o.do.store(o, r); o := o.next END END Store; PROCEDURE LinkObj*(o: Object); (*link at runtime*) BEGIN o.next := first; first := o; INC(cnt); o.id := cnt END LinkObj; -- Tomas Kral <thomas.kral@email.cz>
On Sun, 13 Jan 2019 10:32:52 +0100 Tomas Kral <thomas.kral@email.cz> wrote:
When storing dialog objects,
I need to maintain a sort of object visual hierarchy. Some objects are topmost, some are at the back. As the order of drawing objects is opposite to order in which there are stored. Not sure if good idea at all, but I coded double linked list at the expense of one VAR and one IF. PROCEDURE Insert*(o: Object); BEGIN INC(cnt); o.id := cnt; IF first # NIL THEN first.prev := o ELSE last := o END ; o.next := first; first := o; o.prev := NIL END Insert; (*LinkObj*) PROCEDURE Draw*(y: INTEGER); VAR o: Object; BEGIN o := first; WHILE o # NIL DO o.do.draw(o, y); o := o.next END END Draw; PROCEDURE Store*(VAR r: Files.Rider); VAR o: Object; BEGIN o := last; WHILE o # NIL DO Files.WriteString(r, o.mod); (*TODO use id*) Files.WriteInt(r, o.x); Files.WriteInt(r, o.y); Files.WriteInt(r, o.w); Files.WriteInt(r, o.h); o.do.store(o, r); o := o.prev END END Store; -- Tomas Kral <thomas.kral@email.cz>
I try to answer both your questions in one mail. Basically, you have TWO kind of „objects“, you want to store: 1) the object itself (and all its possible extensions) and 2) the list of those objects. First, try to determine a) what elements of an object change from instance to instance and b) what elements are constant. The elements b) should be part of the object, the elements a) are part of the list. Eg I could imagine that the id will not change but also the width and the height will not change. if so, the width and the height should only be stored once to have a small compressed file. But it depends on your case. So while storing the list, first store the constant object elements if the object is not stored already (so you have to remember whether you stored an object’s instance already) and then store the list elements. br Jörg
Am 14.01.2019 um 09:40 schrieb Tomas Kral <thomas.kral@email.cz>:
On Sun, 13 Jan 2019 10:32:52 +0100 Tomas Kral <thomas.kral@email.cz> wrote:
When storing dialog objects,
I need to maintain a sort of object visual hierarchy. Some objects are topmost, some are at the back. As the order of drawing objects is opposite to order in which there are stored. Not sure if good idea at all, but I coded double linked list at the expense of one VAR and one IF.
PROCEDURE Insert*(o: Object); BEGIN INC(cnt); o.id := cnt; IF first # NIL THEN first.prev := o ELSE last := o END ; o.next := first; first := o; o.prev := NIL END Insert; (*LinkObj*)
PROCEDURE Draw*(y: INTEGER); VAR o: Object; BEGIN o := first; WHILE o # NIL DO o.do.draw(o, y); o := o.next END END Draw;
PROCEDURE Store*(VAR r: Files.Rider); VAR o: Object; BEGIN o := last; WHILE o # NIL DO Files.WriteString(r, o.mod); (*TODO use id*) Files.WriteInt(r, o.x); Files.WriteInt(r, o.y); Files.WriteInt(r, o.w); Files.WriteInt(r, o.h); o.do.store(o, r); o := o.prev END END Store;
-- Tomas Kral <thomas.kral@email.cz> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On Mon, 14 Jan 2019 11:26:27 +0100 Jörg Straube <joerg.straube@iaeth.ch> wrote:
So while storing the list, first store the constant object elements if the object is not stored already (so you have to remember whether you stored an object’s instance already) and then store the list elements.
Hi, Thanks. I keep unique names in an array, referring to them by an index, or if first instance by index+name. Testing it. This sets a fixed limit on numer of object types (frames, buttons, text boxes, ...) e.g. max 16. While INTEGER number of instances. I would like to keep unique name list instead, reading from the root and adding at an end. But not sure what is better. The file has this format { id [name] x y w h [obj properties] } PROCEDURE ReadObjName(VAR r: Files.Rider; VAR mod: ObjName); VAR id: BYTE; mods: ARRAY 16 OF ObjName; BEGIN Files.ReadByte(r, id); IF id = end THEN Files.ReadString(r, mod); mods[id] := mod; INC(end) ELSE mod := mods[id] END END ReadObjName; PROCEDURE WriteObjName(VAR r: Files.Rider; mod: ObjName); VAR id: BYTE; found: BOOLEAN; mods: ARRAY 16 OF ObjName; BEGIN found := FALSE; id := 1; WHILE ~ found & (id < end) DO IF mod = mods[id] THEN found := TRUE END ; INC(id) END ; Files.WriteByte(r, id); IF ~ found THEN Files.WriteString(r, mod); mods[id] := mod; INC(end) END END WriteObjName; -- Tomas Kral <thomas.kral@email.cz>
Hi, Loading/Storing done, sort of. Struggling with object hierarchy, I maintain double linked list, as storing order is reverse to drawing, is reverse to pointing->clicking. I tried to implement send-to-back, but is fairly complex with double links. I wonder if I could somehow recode using only single linked list. -- Tomas Kral <thomas.kral@email.cz>
Whether doubly linked or single linked: send to back is moving the object to the end of the list. Slightly easier with double linked: root.prev Jörg
Am 17.01.2019 um 21:03 schrieb Tomas Kral <thomas.kral@email.cz>:
Hi,
Loading/Storing done, sort of. Struggling with object hierarchy, I maintain double linked list, as storing order is reverse to drawing, is reverse to pointing->clicking.
I tried to implement send-to-back, but is fairly complex with double links. I wonder if I could somehow recode using only single linked list.
-- Tomas Kral <thomas.kral@email.cz> <rgb.png> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On Thu, 17 Jan 2019 22:32:27 +0100 Jörg Straube <joerg.straube@iaeth.ch> wrote:
Whether doubly linked or single linked: send to back is moving the object to the end of the list.
Yes, I realise now. I was looking at ways to shuffle nodes (swap), is not easy as requires updating neighbouring node pointers. I have an idea, marking objects as hidden with id=0 (as valid ids > 0), and cloning them at back or front of the list. One assignment for cloning NEW(p); p^:=o^, plus Insert(), or Append(), all in there already, and are easy, simple assignments, too, for first/last prev/next. I think regular object copies may be required anyway. Hidden objects will be compressed out during store, one IF o.id # 0; This may support object removal at runtime, too, sort of. There is some memory overhead though, but only during design phase. I just see node pointer shuffling a bit complicated and wish to avoid if possible. -- Tomas Kral <thomas.kral@email.cz>
On Fri, 18 Jan 2019 08:19:25 +0100 Tomas Kral <thomas.kral@email.cz> wrote:
I just see node pointer shuffling a bit complicated and wish to avoid if possible.
If it were homogeneous objects, I could just swap their values. Other idea to keep an external list of object pointers, and just swap object pointers, keeping nodes as they are. Changed the order now, adding after last, drawing from first, storing from first, pointing from last. Before was the reverse, but I need frame added, drawn, and stored as very first! -- Tomas Kral <thomas.kral@email.cz>
Tomas I doubt you can escape "pointer shuffling" for the procedures "bring to front" / "send to back" ( When shuffling pointers a quick drawing of the list, the objects involved and their pointers next and prev helps a lot.. It's not sooo complicated after all. Jörg Am 18.01.19, 08:20 schrieb "Oberon im Auftrag von Tomas Kral" <oberon-bounces@lists.inf.ethz.ch im Auftrag von thomas.kral@email.cz>: On Thu, 17 Jan 2019 22:32:27 +0100 Jörg Straube <joerg.straube@iaeth.ch> wrote: > Whether doubly linked or single linked: send to back is moving the > object to the end of the list. Yes, I realise now. I was looking at ways to shuffle nodes (swap), is not easy as requires updating neighbouring node pointers. I have an idea, marking objects as hidden with id=0 (as valid ids > 0), and cloning them at back or front of the list. One assignment for cloning NEW(p); p^:=o^, plus Insert(), or Append(), all in there already, and are easy, simple assignments, too, for first/last prev/next. I think regular object copies may be required anyway. Hidden objects will be compressed out during store, one IF o.id # 0; This may support object removal at runtime, too, sort of. There is some memory overhead though, but only during design phase. I just see node pointer shuffling a bit complicated and wish to avoid if possible. -- Tomas Kral <thomas.kral@email.cz> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On Fri, 18 Jan 2019 09:34:40 +0100 Jörg <joerg.straube@iaeth.ch> wrote:
When shuffling pointers a quick drawing of the list, the objects involved and their pointers next and prev helps a lot
I am now considering this, PROCEDURE Remove*(id: INTEGER); VAR o: Object; BEGIN o := ThisId(id); IF o # NIL THEN o.id := 0 END END Remove; versus that PROCEDURE Remove*(id: INTEGER); VAR o: Object; BEGIN o := ThisId(id); IF o # NIL THEN IF first = last THEN first := NIL; last := NIL ELSIF o = last THEN o.prev.next := NIL; last := o.prev ELSIF o = first THEN o.next.prev := NIL; first := o.next ELSE o.prev.next := o.next; o.next.prev := o.prev END ; Out.String("Removing "); Out.Int(id, 3); Out.Ln END END Remove; -- Tomas Kral <thomas.kral@email.cz>
Hi, I can move a single (so far not overlapping) dialog, when they are two or more, moving one, also moves the others. When moving, I just copy display block to a new location, broadcast empty rectangle to redraw background fill, and dY + dX to all objects. I realise I need a context switch to move from one to the other dialog. This implies keeping another info in a list e.g. with `first',`last' object pointers. Object* = POINTER TO ObjDesc; ObjName = ARRAY 32 OF CHAR; ObjDesc* = RECORD do*: Methods; x*, y*, w*, h*: INTEGER; next, prev: Object; id*: INTEGER; mod*: ObjName END ; Context = RECORD name: ObjName; (*picked from file*) first, last: Object; id: INTEGER; END ; Not sure if good idea at all, but need a way, to effectively switch context and determine current one for a given object? -- Tomas Kral <thomas.kral@email.cz>
On Mon, 21 Jan 2019 19:55:34 +0100 Tomas Kral <thomas.kral@email.cz> wrote:
I realise I need a context switch to move from one to the other dialog.
I can now move dialogs, overlapping ones as well. I have introduced `frame' field to object type, that does object binding to a particular frame. So far avoiding another list of frame pointers. Moving now, does not seem complicated. PROCEDURE Move*(o: Object; dx, dy: INTEGER); VAR f: Object; BEGIN f := o.frame; WHILE (o # NIL) & (o.frame = f) DO INC(o.x, dx); INC(o.y, dy); o := o.next END END Move; Bring to top takes slightly more coding, also need a global `top' pointer. PROCEDURE BringToTop*(o: Object); VAR f, p: Object; BEGIN IF o # top THEN Top(o); f := o.frame; p := o; cnt := o.id-1; WHILE (o # NIL) & (o.frame = f) DO p := p.next; Unlink(o); Insert(o); o := p END END END BringToTop; With additional list, the above would take only swapping two node pointers in a list, but all other procedures, would need double list traversal. Not sure what is better. The graphics is not completely flicker-free, but on the other hand, does not need offscreen bitmaps. I could try evaluate rectangle intersections in a list, and redraw only overlapping frames, the others would just need display copy block, or leave in position as is. Not sure just testing. -- Tomas Kral <thomas.kral@email.cz>
On Wed, 23 Jan 2019 20:37:42 +0100 Tomas Kral <thomas.kral@email.cz> wrote:
I could try evaluate rectangle intersections in a list, and redraw only overlapping frames
I do intersection check below, almost flicker free graphics, except when some frames overlap. (p.frame # o.frame) is a guard against itself. PROCEDURE Overlap*(o: Object): BOOLEAN; VAR p: Object; overlap: BOOLEAN; BEGIN p := first; overlap := FALSE; WHILE ~ overlap & (p # NIL) DO IF (p.frame # o.frame) & (o.x < p.x+p.w) & (o.x+o.w > p.x) & (o.y-o.h < p.y) & (o.y > p.y-p.h) THEN overlap := TRUE END ; p := p.next END ; RETURN overlap END Overlap; -- Tomas Kral <thomas.kral@email.cz>
Hi, My first attempt with a simple calc, reverse polish only, it is a gimmick so far, as it needs adding RPN logic, and some testing. -- Tomas Kral <thomas.kral@email.cz>
Hi, Testing `Calc', shows something I need yet to improve about (y-x). While (y+x) seems alright. So are y*x, y/x. Sanity check 123.123 Enter 123.123 Enter - 0.0 <= good This has a problem 123 Enter .123 Enter + 1.231230+E02 <= top of stack 123.123 Enter - 7.629395-E06 <= ??? But this works 123 Enter .123 Enter + 1.231230+E02 <= top of stack 123.123 Enter + 2.462460+E02 <= good 246.246 Enter - 0.0 <= good -- Tomas Kral <thomas.kral@email.cz>
Floating-point numbers are not exact. No matter how closely they may round, no matter how close they look, they may not be exactly equal. You formed a number that is "close" to 123.123. You formed another number that is "close" to 123.123. When you subtracted the two, you saw the difference between "close" and "exact". Your two numbers were close, but they were not exactly equal. They differed by 0.0000076395, or thereabouts. This is probably very close to the lower error limit of your processor's floating-point representation. When you multiplied the problem by two, you got "close enough" that the error rounded off. I remember losing it one night, trying to explain that an error of a mile or so, on a problem that involved LITERALLY astronomical distances (with a system that was probably not too well-conditioned to begin with), was not bad. I also remember a lecture in the introductory numerical methods class, something over forty years ago, that asked the question "What is a good answer?". The example was solving two simultaneous linear equations. One solution gave an error that was exactly on one of the lines, but not at the exact intersection. Another gave a point that was a little way off both lines. However, if you calculated the distance from the calculated solution to the exact solution, you found that the second method gave a "closer" answer. Thirty years later, I'd say something about L-infinity norm vs. L-2 norm. -----Original Message----- From: Tomas Kral Sent: Tuesday, February 5, 2019 3:14 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - DIY Dialogs Hi, Testing `Calc', shows something I need yet to improve about (y-x). While (y+x) seems alright. So are y*x, y/x. Sanity check 123.123 Enter 123.123 Enter - 0.0 <= good This has a problem 123 Enter .123 Enter + 1.231230+E02 <= top of stack 123.123 Enter - 7.629395-E06 <= ??? But this works 123 Enter .123 Enter + 1.231230+E02 <= top of stack 123.123 Enter + 2.462460+E02 <= good 246.246 Enter - 0.0 <= good -- Tomas Kral <thomas.kral@email.cz> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus
On 05/02/2019, John R. Strohm <strohm@airmail.net> wrote:
Floating-point numbers are not exact.
No matter how closely they may round, no matter how close they look, they may not be exactly equal.
So true. Goldberg is considered the definitive essay: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html N.
On Tue, 5 Feb 2019 20:03:20 -0600 "John R. Strohm" <strohm@airmail.net> wrote:
When you multiplied the problem by two, you got "close enough" that the error rounded off.
I see, proves by the test 123 Enter .123 Enter + 1.231230+E02 <= top of stack Enter + <== double 2.462460+E02 Enter - 0.0 <== good -- Tomas Kral <thomas.kral@email.cz>
Tomas Welcome to the world of rounding errors ( Jörg Am 06.02.19, 18:32 schrieb "Oberon im Auftrag von Tomas Kral" <oberon-bounces@lists.inf.ethz.ch im Auftrag von thomas.kral@email.cz>: On Tue, 5 Feb 2019 20:03:20 -0600 "John R. Strohm" <strohm@airmail.net> wrote: > When you multiplied the problem by two, you got "close enough" that > the error rounded off. I see, proves by the test 123 Enter .123 Enter + 1.231230+E02 <= top of stack Enter + <== double 2.462460+E02 Enter - 0.0 <== good -- Tomas Kral <thomas.kral@email.cz> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
participants (5)
-
John R. Strohm -
Jörg -
Jörg Straube -
Nemo -
Tomas Kral