www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.dwt - HelloWorld in Harmonia

reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
Just in case someone would like to compare with others.
Here are 3 "hello world"s



hello1. d --------------------------------------------

module samples.hello1;

// HTML Hello World.

import harmonia.ui.application;
import harmonia.ui.window;
import harmonia.html.view;

// HTML behavior can be attached to any container
// This time to the window.
alias HtmlPanelT!(Window) HtmlWindow;

void HelloWorldStart()
{
  HtmlWindow w = new HtmlWindow;
  w.html =
     "<HTML back-color='edit info'
            text-align=center
            vertical-align=middle>Hello World!</HTML>";
  w.state = Window.STATE.SHOWN;
}

static this()
{
  Application.onStart = &HelloWorldStart;
}

EOF: --------------------------------



hello2.d --------------------------------------------

module samples.hello1;

// Hello World with custom draw.

import harmonia.ui.application;
import harmonia.ui.window;
import harmonia.gx.graphics;

class MyWindow:Window
{
  this() { windowCaption = "Hello2"; }

  const wchar[] message = "Hello World!";

  override void draw(Graphics g)
  {
    // client rect is a rect with origin (0,0)
    rect clientRc = rect(this.place.dim);
    // fill background by gradient colors
    g.fillRect(clientRc, 0x8ce8ff, 0x8ce8ff, 0x0066cc, 0x0066cc);

    // create font or get it from font cache
    // and select it into the Graphics
    g.font = Font.create("Century Gothic", 36);
    // textColor
    g.textColor = 0x003399;
    // draw chars
    g.drawChars(message, clientRc, Graphics.DRAW.CENTER | 
Graphics.DRAW.MIDDLE);
  }
}

static this()
{
  Application.onStart =
    function void()
    {
      // create MyWindow and show it
      (new MyWindow()).state = Window.STATE.SHOWN;
    };
}

EOF: ------------------------------------------------




module samples.browser;

import harmonia.ui.application;
import harmonia.ui.frame;
import harmonia.html.view;

import harmonia.io.mmfile;

//|
//| static module ctor
//|
//| Harmonia way to setup GUI application
//|

static this()
{
  Application.onStart =
    // Runtime started. Statics were intitalized.
    // Voulez-vous dancer?
    function void()
    {
      // create MainWindow here
      (new MyFrame()).state = Window.STATE.SHOWN;
    };
}

// Frame is a template parametrized by class name of it central View widget

class MyFrame: Frame!(HtmlView)
{
  this()
  {
    // menu initialization
      menu ~=
        new Menu("File")
          ~ FileCommand.Open
              ~ Menu.Separator
          ~ FileCommand.Exit;

      view.html = initialHtml; //a.k.a. about:blank
  }

  void openFile()
  {
    static FileDialog dlg;
    if(!dlg)
    {
      dlg = new FileDialog();
      dlg.addFilter("HTML Files", "*.htm;*.html");
      dlg.dialogCaption = "Select HTML file to open:";
    }
    if(!dlg.selectFileToOpen(this))
      return;

    MMFile data = MMFile.open(dlg.filePathNameExt);
    this.view.html = cast(char[])data[];

  }

  bool on(EventCommand evt)
 {
  if(evt.cmd is FileCommand.Open)
    {
      if( evt.type == EventCommand.DO ) openFile();
      return true;
    }
  else if(evt.cmd is FileCommand.Exit)
    {
      if( evt.type == EventCommand.DO ) this.state = STATE.CLOSED;
      return true;
    }
    return false;
 }
 static char[] initialHtml = "<HTML>&nbsp;</HTML>";
}

EOF: ------------------------------------------
Feb 07 2006
parent reply Dannerbeck Dieter <no.spam.dd gmx.de> writes:
Andrew Fedoniouk schrieb:
 Just in case someone would like to compare with others.
 Here are 3 "hello world"s
 

 
 hello1. d --------------------------------------------
 
 module samples.hello1;
 
 // HTML Hello World.
 
 import harmonia.ui.application;
 import harmonia.ui.window;
 import harmonia.html.view;
 
 // HTML behavior can be attached to any container
 // This time to the window.
 alias HtmlPanelT!(Window) HtmlWindow;
 
 void HelloWorldStart()
 {
   HtmlWindow w = new HtmlWindow;
   w.html =
      "<HTML back-color='edit info'
             text-align=center
             vertical-align=middle>Hello World!</HTML>";
   w.state = Window.STATE.SHOWN;
 }
 
 static this()
 {
   Application.onStart = &HelloWorldStart;
 }
 
 EOF: --------------------------------
 

 
 hello2.d --------------------------------------------
 
 module samples.hello1;
 
 // Hello World with custom draw.
 
 import harmonia.ui.application;
 import harmonia.ui.window;
 import harmonia.gx.graphics;
 
 class MyWindow:Window
 {
   this() { windowCaption = "Hello2"; }
 
   const wchar[] message = "Hello World!";
 
   override void draw(Graphics g)
   {
     // client rect is a rect with origin (0,0)
     rect clientRc = rect(this.place.dim);
     // fill background by gradient colors
     g.fillRect(clientRc, 0x8ce8ff, 0x8ce8ff, 0x0066cc, 0x0066cc);
 
     // create font or get it from font cache
     // and select it into the Graphics
     g.font = Font.create("Century Gothic", 36);
     // textColor
     g.textColor = 0x003399;
     // draw chars
     g.drawChars(message, clientRc, Graphics.DRAW.CENTER | 
 Graphics.DRAW.MIDDLE);
   }
 }
 
 static this()
 {
   Application.onStart =
     function void()
     {
       // create MyWindow and show it
       (new MyWindow()).state = Window.STATE.SHOWN;
     };
 }
 
 EOF: ------------------------------------------------
 
 

 
 module samples.browser;
 
 import harmonia.ui.application;
 import harmonia.ui.frame;
 import harmonia.html.view;
 
 import harmonia.io.mmfile;
 
 //|
 //| static module ctor
 //|
 //| Harmonia way to setup GUI application
 //|
 
 static this()
 {
   Application.onStart =
     // Runtime started. Statics were intitalized.
     // Voulez-vous dancer?
     function void()
     {
       // create MainWindow here
       (new MyFrame()).state = Window.STATE.SHOWN;
     };
 }
 
 // Frame is a template parametrized by class name of it central View widget
 
 class MyFrame: Frame!(HtmlView)
 {
   this()
   {
     // menu initialization
       menu ~=
         new Menu("File")
           ~ FileCommand.Open
               ~ Menu.Separator
           ~ FileCommand.Exit;
 
       view.html = initialHtml; //a.k.a. about:blank
   }
 
   void openFile()
   {
     static FileDialog dlg;
     if(!dlg)
     {
       dlg = new FileDialog();
       dlg.addFilter("HTML Files", "*.htm;*.html");
       dlg.dialogCaption = "Select HTML file to open:";
     }
     if(!dlg.selectFileToOpen(this))
       return;
 
     MMFile data = MMFile.open(dlg.filePathNameExt);
     this.view.html = cast(char[])data[];
 
   }
 
   bool on(EventCommand evt)
  {
   if(evt.cmd is FileCommand.Open)
     {
       if( evt.type == EventCommand.DO ) openFile();
       return true;
     }
   else if(evt.cmd is FileCommand.Exit)
     {
       if( evt.type == EventCommand.DO ) this.state = STATE.CLOSED;
       return true;
     }
     return false;
  }
  static char[] initialHtml = "<HTML>&nbsp;</HTML>";
 }
 
 EOF: ------------------------------------------
I like harmonia( can't really use it because there's no docs ) but i'm sure it's the most portable toolkit there.
Feb 17 2006
parent "Andrew Fedoniouk" <news terrainformatica.com> writes:
 I like harmonia( can't really use it because there's no docs ) but i'm 
 sure it's the most portable toolkit there.
Well let's start together then. I've added following page into HarmoniaWiki: http://www.terrainformatica.com/wiki/pmwiki.php/Harmonia/Documentation Feel free to add there names of chapters you would like to see there. Andrew.
Feb 17 2006