Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Sizer, Images

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Sizer, Images
#3655
Posted by: 2004-03-30 18:16:18
Hi,

I have to have a frame with some text, images, buttons etc. First I used

wxLayoutConstraints *lc_bsc = new wxLayoutConstraints; //basisLayoutConstraints

lc_bsc->left.SameAs       (this, wxLeft);
lc_bsc->top.SameAs        (this, wxTop);
lc_bsc->right.PercentOf   (this, wxWidth, 100);
lc_bsc->height.PercentOf  (this, wxHeight, 100);
panel_bsc->SetConstraints(lc_bsc);

with only one panel. but to put images I had to use wxPaintDC. It needs OnPaint. my problem is now, that I have 2 posibilities: to have all functions but no pictures, or to have pictures, but no functions (becoase of using one panel it is all painted...).

Can I put another panel in the right top corner (pritty small, for pictures) or should I use wxBoxSizer? I tryed with the sizer but I can not manage it...do you have simple example?

please...it should be ready till tomorrow...
Message2. Re: Sizer, Images
#3658
Posted by: upCASE 2004-03-30 21:26:13
Hi!
Well, first of all I'm not really sure what you want to do. I guess that is has something to do with painting an image on a panel and displaying other controls. I'll comment on some things now, but for a proper answer I'd need more info, maybe a screenshot or code snippet.

1. Don't use wxLayoutContraint, but use wxSizer instead. Constrains are considered deprecated. In fact I never worked with them...
2. If sizers trouble you, maybe try a GUI editor like wxGlade (free). Sometimes that helps to get most of the stuff done.
3. To paint a image any DC (not only wxPAintDC) would do. If it is a static image that doesn't change or has to be repainted -> use a wxStaticBitmap instead.
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: Sizer, Images
#3660
Posted by: 2004-03-30 23:03:42
first - thanks a lot!

This is my first variant with Constraints (the cpp-file):

BEGIN_EVENT_TABLE(TARA_Setup_Frame, wxFrame)
         ...
	EVT_PAINT(TARA_Setup_Frame::OnPaint)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit(){	
	wxImage::AddHandler(new wxGIFHandler);
	MyFrame *frame = new MyFrame("GUI",wxPoint(250, 50), wxSize(500, 650));
	frame->Show(TRUE);
	SetTopWindow(frame);
	return TRUE;
}

MyFrame::MyFrame(const wxString& titel, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame*)NULL, -1, titel, pos, size){

  SetAutoLayout(TRUE);
  panel_bsc = new wxPanel(this);		// basisPanel

  wxLayoutConstraints *lc_bsc = new wxLayoutConstraints; //basisLayoutConstraints

  lc_bsc->left.SameAs       (this, wxLeft);  
  lc_bsc->top.SameAs        (this, wxTop);
  lc_bsc->right.PercentOf   (this, wxWidth, 100);
  lc_bsc->height.PercentOf  (this, wxHeight, 100);
  panel_bsc->SetConstraints(lc_bsc);

  // this elements I have in the frame	
  wxStaticText *label = new wxStaticText( panel_bsc,-1, "&Titel",wxPoint(20,35), wxSize(200, 80), wxST_NO_AUTORESIZE);
  label->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL, FALSE, ""));

  image = new wxImage("./picture.gif", wxBITMAP_TYPE_GIF);
	 
  if (!image->LoadFile("picture.gif"))
      wxLogError(wxT("Can't load GIF image"));
	
  // Text etc.
  (void)new wxStaticBox( panel_bsc, -1, "&ProgTitle", 
                           wxPoint(5, 100), wxSize(482, 220));

  (void)new wxCheckBox( panel_bsc, ID_1, "&choose 1", wxPoint(40,120), wxSize(170,30) );
  (void)new wxCheckBox( panel_bsc, ID_2, "&choose 2",	wxPoint(40,160), wxSize(170,30) );
  
 // one more SaticBox with 3 CheckBoxes

  // Buttons
  (void)new wxButton( panel_bsc, ID_iO, "&i.O.",wxPoint(100, 530), wxSize(100, 30));
  (void)new wxButton( panel_bsc, ID_Quit, "&Abbrechen", wxPoint(300, 530),
							wxSize(100, 30));
		
  CreateStatusBar();

  if (image->Ok()) SetStatusText("LOADED gif!");
  else SetStatusText("FAILED TO LOAD gif!");
}

void TARA_Setup_Frame::OnPaint(wxPaintEvent& WXUNUSED(event)){
	wxPaintDC dc(panel_bsc);
         PrepareDC(dc);
	image_bmp = new wxBitmap;
	*image_bmp = image->ConvertToBitmap();
	if (image && image->Ok())
        dc.DrawBitmap(*image_bmp, 220, 30, FALSE);
}

In this variant I had (I guess) a problemm, becoase I "paint" on one panel...exually I can do 3 panels: on the top: for titel and logo (picture) and the rest..but when I tryed to put picture panel (upper right corner) with

lc_1->right.SameAs(this, wxRight);  

it wouldn't be accept....

with wxSizer (or wxBoxSizer) I've got a error, that the function "add()" is not defined for wxSizer.... maybe I vergot to include some header?
Message4. Re: Sizer, Images
#3662
Posted by: upCASE 2004-03-31 00:19:28
Hi!
Just had a look at it and I think I know by now what you want...
I'm going to compile a small example, but this may take a while.
Drop me an email (upcase@gmx.net) and I'll send you a copy when I'm done.
BTW: I suppose you're german. Feel free to mail in german :)
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥289.00 ·
 
 
¥1,080.00 ·
 
 
¥1,380.00 ·
 
 
¥638.00 ·
 
 
¥1,290.00 ·
 
 
¥1,420.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0