FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Resizeable Form

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
chpl



Joined: 30 Nov 2007
Posts: 2

PostPosted: Sun Dec 02, 2007 5:14 pm    Post subject: Resizeable Form Reply with quote

Hi

Its me again.
I am just playing with the api. Now I try to make an little Window (Form) I want it to draw a grid and plots some math-functions like sinus etc. So i tried it do it like it is the "normal" way. I derived from Form an tried to override the "onPaint" methode and do all "paintings" there. It seems to work fine but when i resize the window it doesent work in the correct way. It doenst resize the drawing.

First i noticed that the onpaint event is comes before the resize event. Is this ok ? Schouldn't the resize event be thrown before the paint event ? I am not sure at this moment but isn't this the normal way ? Because in this way in some cases the area is drawn twice ... isn't it ?

The next thing i saw is that clientSize calls the onpaint methode when i make the window bigger. But when i make the window smaller it doesnt call it. It makes sense ... because the window has to draw the new area when the window gets bigger. And has just to hide the area which disappear while making the window smaller. I think this is the reason.
(But usually(in other frameworks) the paint event comes every time i think.)

Ok lets go back!. I want to redraw it always because i want to rearrange my drawing. So i override onResize too and i just call invalidate() there. This invalidates the entire window area and the area will be drawn in the way i want.

First i thought update() is what i need but it seems not to work ??? I dont know what is the differnt between Update and invalidate?? In Source ("Control.d") it just calles UpdateWindow(hwnd);

But invalidate works fine Smile
So here is my little Window. I dont know if its the best way cause i am realy new in D. Maybe its better to derive from Control for an extra Plotarea. So you can add other controls Textbox, Buttens ... in the Form. I will try this in a few days.
Code:

/*
 * chpl@chello.at
 */

import dfl.all;
import std.stdio;

int main()
{
   MyForm myForm = new MyForm();
 
   Application.run(myForm);
 
   return 0;
}
 
 
class MyForm: dfl.form.Form
{
   Pen p1 = null;
   
   this()
   {
      initializeMyForm();
   }
   
   private void initializeMyForm()
   {
      text = "My Form";
      p1 = new Pen(Color(0, 0, 0xF0));
      clientSize = dfl.all.Size(292, 266);
      
   }
 
    protected override void onResize(EventArgs ea)
    {
       writefln("onResize");
       super.onResize(ea);
       
       invalidate();
       //update();
    }
 
    protected override void onPaint(PaintEventArgs ea)
   {
       writefln("onPaint");
       super.onPaint(ea);
      
   DrawGrid(ea.graphics, p1);
   
   }
   
     private void DrawGrid(Graphics graphics,Pen p1)
     {
        writefln("DrawGrid");
        int width = clientSize.width;
        int height = clientSize.height;
       
        static int border = 5;
       
        graphics.drawRectangle(p1,border,border,width-2*border,height-2*border);
       
        // Axis
        graphics.drawLine(p1,0,height/2,width,height/2);
        graphics.drawLine(p1,width/2,0,width/2,height);
     }
}

Cu chpl
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Tue Dec 04, 2007 2:03 pm    Post subject: Re: Resizeable Form Reply with quote

The invalidate function tells the control or form it needs to repaint part of the display. The update function only tells it to make sure the invalidated parts are painted at that moment, instead of being delayed and coalescing many paints into one. Controls and forms have property resizeRedraw to ensure every resize causes the whole display to repaint.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group