Jump to content

All Activity

This stream auto-updates     

  1. Yesterday
  2. Last week
  3. lynkfs

    tree walking

    Modern browsers have an enormous number of built-in functions, sometimes very handy These ones, having to do with tree handling, came up the other day : domParsing, nodeIteration and treeWalking The built in domParser function takes a tree in html/dom or xml format : <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer''s Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> </catalog> which can be used as in var oDOM: variant := new JObject; asm var oParser = new DOMParser(); @oDOM = oParser.parseFromString(@theaboveXMLstring, "application/xml"); end; writeln(oDOM.documentElement.nodeName); // root (catalog) writeln(oDOM.children[0].children[0].attributes[0].name); // id writeln(oDOM.children[0].children[0].attributes[0].value); // bk101 writeln(oDOM.children.item(0).innerHTML); To traverse these types of trees, there are also the following functions available : nodeIterator and treeWalker These functions are largely similar. The nodeIterator : var nodeIterator : variant := new JObject; nodeIterator := oDOM.createNodeIterator( oDOM.documentElement,-1); // NodeFilter.SHOW_ELEMENT : -1 or 0xFFFFFFFF var currentNode := nodeIterator.nextNode(); while currentNode <> null do begin // null = eof // get rid of whitespace text nodes if currentNode.nodeName <> '#text' then begin writeln(currentNode.nodeName); writeln(currentNode.innerHTML); end; currentNode := nodeIterator.nextNode(); end;
  4. DavidRM

    Node.JS Game Loop

    Here is my Smart Mobile Studio adaptation of the Node.JS "node-gameloop" module. My primary modification was some code to make the *next* interval line up with the desired number of ms per tick. I also tightened the window for choosing SetTimeout vs SetImmediate. I needed this to provide the beating heart of Paintball Net's simulation engine. Which, sure, only beats 10 times per second, but I wanted it to be as accurate as possible. 🙂 -David unit UPBNGameGameLoop; interface uses System.Types, System.Types.Convert, System.Time, System.Streams, System.Reader, System.Writer, System.Device.Storage, SmartNJ.System, SmartNJ.Streams, SmartNJ.Device.Storage, SmartNJ.Application, NodeJS.Core; var GameLoopActive: boolean; type TGameLoopCallback = procedure(delta: float); procedure StartGameLoop(update: TGameLoopCallback; msInterval: integer); procedure StopGameLoop; implementation procedure SetImmediate(const Entrypoint: TProcedureRef); external 'setImmediate'; const Seconds2Nano = 1e9; Nano2Seconds = 1 / Seconds2Nano; MS2Nano = 1e6; Nano2MS = 1 / MS2Nano; var _loopProc: TGameLoopCallback; _loopLengthHR: float; _loopPrevHR, _loopTargetHR: float; function GetHRTime: float; var hrTime: Variant; begin // I need a more up-to-date node to use the bigint() function. // asm // @Result = process.hrtime.bigint(); // end; asm @hrTime = process.hrtime(); end; Result := (hrTime[0] * Seconds2Nano) + hrtime[1]; end; procedure DoGameLoop; var now, delta: float; remaining: integer; begin if GameLoopActive then begin now := GetHRTime; if now >= _loopTargetHR then begin delta := now - _loopPrevHR; _loopPrevHR := now; _loopTargetHR := now + _loopLengthHR; if delta > _loopLengthHR then begin _loopTargetHR -= (delta - _loopLengthHR); end; _loopProc(delta * Nano2Seconds); end; if GameLoopActive then begin remaining := Trunc((_loopTargetHR - GetHRTime) * Nano2MS); if remaining >= 4 {16} then SetTimeout(DoGameLoop, remaining) else SetImmediate(DoGameLoop); end; end; end; procedure StartGameLoop(update: TGameLoopCallback; msInterval: integer); begin if not GameLoopActive then begin GameLoopActive := True; _loopLengthHR := msInterval * MS2Nano; _loopProc := update; _loopPrevHR := GetHRTime; _loopTargetHR := _loopPrevHR; SetImmediate(DoGameLoop); end; end; procedure StopGameLoop; begin GameLoopActive := False; _loopProc := nil; end; end.
  5. Henry

    My SMS Project: Paintball Net Revival

    I was eleven years old and had just mailed off a crinkly ten dollar bill folded inside a handwritten message explaining my love for this game. A few days would pass until there it was, my first level up. Huge fan, no game has ever come close to the caliber of paintball net. I’m — we — are much older now but the game hasn’t aged a day. Thank you David for resurrecting the legend !
  6. Earlier
  7. jarto

    Radiogroup - change items text

    With the current designer, having the items as a TStrArray is the only way we can define items at design time.
  8. IElite

    Radiogroup - change items text

    There are a number of controls that do this ..i.e. have a index (array property) and then a separate property for the list of controls (e.g. RadioButtons: TW3RadioGroupItems in Delphi there is not a string array it would be something like items: TW3RadioGroupItems instead and there would be no Items: TStrArray I am sure there is a reason for this and maybe @jarto can enlighten us
  9. Czar

    Radiogroup - change items text

    Ok, good work around - wasn't obvious for me
  10. IElite

    Radiogroup - change items text

    W3RadioGroup1.RadioButtons[0].Label.Caption:= 'it does not work';
  11. It is not possible to change the text of a radiogroup item e.g., W3RadioGroup1.Add('test'); W3RadioGroup1.items[0] := 'it does not work'; as a workaround - I am removing and then inserting
  12. lynkfs

    css grid

    2) using css grid to make a responsive 'form' The below component does some simple layouting of controls and also reacts to screen-sizing, both using the css grid : procedure TForm1.InitializeForm; begin inherited; // this is a good place to initialize components var ResponsiveForm : TResponsiveForm := TResponsiveForm.Create(self); ResponsiveForm.SetBounds(40,40,500,220); ResponsiveForm.AutoHeight := true; ResponsiveForm.Add('Name',TW3EditBox); ResponsiveForm.Add('Email',TW3EditBox); ResponsiveForm.Add('Township',TW3EditBox); ResponsiveForm.Add('Comments',TW3Memo); ResponsiveForm.Add('Submit',TW3Button,2); end; Demo here It is not really 100% responsive, as the labels should shift above the controls when screen size becomes small. It doesn't however look too bad and the tediousness of aligning labels and controls is taken care of by the css grid. (Adapted from this article). It's probably as easy though to use anchors creating the same result
  13. lynkfs

    php

    A web application ends up being encoded in html, js and css. php is a language which can be used to create these components, but more importantly can also be used within all 3 of these types of files. That gives some interesting possibilities. To make that happen, php needs to be activated serverside. Many server hosting environments come with php pre-installed. Activating php so that it can be used at the time of serving regular .html, .js or .css files by the browser depends on the type of server. Regular unix based servers make use of a .htaccess file which needs a line like AddHandler application/x-httpd-php5 .html .htm Windows servers have another mechanism 1 - Using php within Smart Php can be invoked like this, where the php statements are inclosed in a <?php block. asm var i = 0; i = <?php echo 35; ?>; alert(i); end; A practical use would be to include server side scripts normally accessed through a POST request (which eliminates a server round trip as well). The below code reads a MySqL database at form init procedure TForm1.InitializeForm; begin inherited; // this is a good place to initialize components var response : variant := new JObject; asm @response = <?php $link = mysql_pconnect("...domain...", "...user...", "...password...") or die("Could not connect"); mysql_select_db("...database...") or die("Could not select database"); $sql_statement = 'Select * from FishFacts'; $arr = array(); $rs = mysql_query($sql_statement); while($obj = mysql_fetch_object($rs)) { $arr[] = $obj; } echo '{"rows":'.json_encode($arr).'}'; mysql_close($link); ?>; end; writeln(response.rows[0].Common_Name); //Clown Triggerfish 2 - Using php within Html files A (possibly) usefull example scenario would be to separate web-pages into a header.html, a regular Smart index.html and a footer file. php has an include mechanism, which can be used like so <body> <?php include "header.html" ?> <script type="text/javascript"> /* This prevents the window being moved by touches, to give the impression of a native app */ document.ontouchmove = function(e) { e.preventDefault(); } </script> <script type="text/javascript" src="main.js.php"></script> </body> 3 - Using php within css files Similarly stylesheets can be scripted, something like this snippet where, within the stylesheet, the current date is checked which sets an image url <?php $month = date('m'); $day = date('d'); if($month=='12' && $day=='25') { $logoSrc = 'images/holidayLogo.png'; } else { $logoSrc = 'images/logo.png'; } ?> h1 { background: url(<?=$logoSrc?>) no-repeat; } Demo (of 1 and 2)
  14. lynkfs

    window component

    found the problem : the js events give a window based coordinate (e.clientX), while the Smart events give a component based coordinate (x as in left relative to component). Solution : just ad water (just ad component.left) if Ctrl.Cursor=crMove then begin x := x + left; y := y + top; or something like that
  15. jarto

    window component

    Cool, you found the new events like OnAllMovement. That makes the code a lot easier. The jitteryness may come from MoveTo. Forgot one thing: You need to call Ctrl.SetCapture when MouseDown happens and Ctrl.ReleaseCapture during MouseUp.
  16. lynkfs

    window component

    mmm your amended code (when applied to this or any other visual component) makes for very jittery dragging substituting code with this (below) gives a very smooth movement header.OnAllMovement := procedure(Sender: TObject; dx,dy: Integer) begin left := left + dx; top := top + dy; end; but that wasn't the point. Any idea what causes the jitteryness ? Edit1 : the x,y values in OnMouseMove don't make much sense
  17. jarto

    window component

    @warleyalex Yeah, well, the problem you experience is because the current Object Inspector lacks features. We're in the process of replacing it with a better component, which should let you edit more properties. For example sets. The Object Inspector also needs a lot of work. The current design was based on the idea that we'd get the Chromium to render us a live preview that we could use to make the controls look realistic. However, there was some changes in Chromium that broke that feature. So we're currently thinking about what'd be the best way to proceed. Basically: Should we try to improve the current one or replace it with something better.
  18. jarto

    window component

    Something like this: var saveX, saveY: Integer; Header.OnMouseDown:=procedure(Sender: TObject; Button: TMouseButton; shiftState: TShiftState; x, y: integer) begin var Ctrl:=TW3CustomControl(Sender); Ctrl.Cursor:=crMove; saveX:=x; saveY:=y; end; Header.OnMouseMove:=procedure(Sender: TObject; ShiftState: TShiftState; x, y: integer) begin var Ctrl:=TW3CustomControl(Sender); if Ctrl.Cursor=crMove then begin Ctrl.MoveTo(Ctrl.Left-(saveX-x),Ctrl.Top-(saveY-y)); PrevSize:=Ctrl.BoundsRect; saveX:=x; saveY:=y; end; end; Header.OnMouseUp:=procedure(Sender: TObject; Button: TMouseButton; shiftState: TShiftState; x, y: integer) begin var Ctrl:=TW3CustomControl(Sender); Ctrl.Cursor:=crDefault; end;
  19. warleyalex

    window component

    OFF TOPIC - "SMS Component design" Just things that crosses my mind, and I want to discuss. Please don’t see that as an attack to someones's work. I really like SMS and the new possibilities. We all want the best possible development experience result. While the visual widgets/UI in SMS still is customizable (by user and developer). I often spend more time on UI parts to realize the look and feel i want to have. I have to say here, one think that is very frustating for me is the SMS form designer I've spent a few minutes reflecting on this RAD approach and its form designer to create web app. Just drop components onto a form and set up at the objector inspector, the events and the properties. All of the above is great and it will no doubt give us the same benefits as Delphi developers currently enjoy. The compiler will auto generate the components for you, such as: var btn1: TButton; btn1 := TButton.Create(Self); btn1.Width := 121; btn1.Top := 16; btn1.Left := 536; btn1.Height := 25; btn1.Name := 'btn1'; btn1.OnClick := Self.btn1Click; The UI part could be implemented on top of TCustomComponent, both visual or non-visual components could be used. "the window component" - it's great candidate hein! ...but what I really don't like this approach is when i.e. you drop "a visual component" onto form, you see "rectangule" drawing which represents the component itself you dropped. I can't seem to find anyway how to get the "live preview" on the SMS designer on those components I've created. other thing is the "objector inspector" support for some custom properties. For instance, if the user choose 'Material' from the list, the Material CSS style should be applied to the component. type TCustomStyle = array[1..3] of string; const CustomStyle : TCustomStyle = ('iOS','Android','Material'); type TMystyle = (cssIOS, cssAndroid, cssMaterial); TToggleComponent = class(TW3CustomControl) private fMyStyle: TMystyle; fCustomStyle : TCustomStyle; published property Mystyle: TMystyle Read fMyStyle Write fMyStyle default cssAndroid; property CustomStyle: TCustomStyle Read fCustomStyle Write fCustomStyle; ...when I see at Object Inspector the property MyStyle : 0 (set to zero?). For the boolean type it shows the dropdown list. How can I create a property of type String that will show a combo box in the object inspector with a predefined set of values the user could choose? This is very frustating for me It seems there's just a bit too much work involved to meet even baseline expectations.
  20. lynkfs

    window component

    demo works ok here The javascriptisch events used are //Move window Header.handle.onmousedown := procedure(e: variant) begin Header.handle.style.cursor := 'move'; var saveX := e.clientX; var saveY := e.clientY; Header.handle.onmousemove := procedure(e: variant) begin self.left := self.Left - (saveX - e.clientX); self.top := self.top - (saveY - e.clientY); PrevSize := TRect.CreateSized(left, top, width, height); saveX := e.clientX; saveY := e.clientY; end; end; // Header.handle.onmouseup := procedure(e: variant) begin Header.handle.onmousemove := null; //nullify mousemove Header.handle.style.cursor := 'default'; end; // Header.handle.onmouseleave := procedure(e: variant) begin self.Parent.handle.onmousemove := header.handle.onmousemove; self.Parent.handle.onmouseup := procedure(e: variant) begin self.parent.Handle.onmousemove := null; end; end; will be interesting to compare using eventmanager. I agree that will probably be a better solution
  21. jarto

    window component

    Did you change to use the normal events? Because the situation I mentioned above does still happen when you drag the window.
  22. lynkfs

    window component

    Thanks. Never had a good look at the event manager. Better do that (problem fixed by the way)
  23. I also tried to find out which DWS version we use but the source tree does not tell it. @gabr42 may know more as we've not updated DWScript since I joined the project.
  24. jarto

    window component

    @lynkfs SetCapture/ReleaseCapture takes care of those dragging problems that @Czar mentioned. Edit: However, to be able to use SetCapture and ReleaseCapture, you need to listen to MouseDown, MouseUp and MouseMove using the normal Delphi-like events instead of using the raw JS events. Edit2: When you use normal events, the EventManager takes care of a boatload of the complexity. For example, SetCapture locks on to the control meaning that all move events go that one. (See the Scrollbars code in the RTL as an example) The EventManager also notices situations where you click on control to drag it, move the mouse outside of the whole browser window and release the button there. If you try to listen to events through JS, these kinds of special situations are a pain to handle correctly.
  25. lynkfs

    window component

    no drag racing ... fixable (when time permits)
  26. Czar

    window component

    Looks nice, unsure what I would use it for at the moment but good to see if here. You are undoubtedly aware that if mouse comes off the window the dragging stops.
  27. lynkfs

    window component

    Just in case anyone has a need for a window component. (multiple windows, movable, resizable, bringtofront, minimise, close, maximise) project
  28. Dany

    What happened to VarIsValidRef?

    You should be able to do the same using functions Assigned and Defined.
  1. Load more activity
×