April 16, 2024, 05:49:28 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Controls with 3d window

Started by kryton9, August 21, 2006, 10:02:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kryton9

August 21, 2006, 10:02:29 PM Last Edit: August 21, 2006, 10:09:01 PM by kryton9
While waiting for help with 3d vectors, I am doing test for what will be an ambitious project for a cool 3d toolbox. So started playing around with controls to see if I can get them to work.

Ran into a strange problem, if you click on the scrollbars thumb thingy and drag it to the left, it jumps to the right and gives an nPos of 65000+
This seems to only happen when you set the range for the scroll bar with a negative number. Not sure if it is a bug or not.

Also a strange thing, in MyWindow::OnHScroll(int nCommand,int nPos,int nID),int

It loses the value of nPos, but retains nID, so in the second select set, I had to assign nPos to nPos2 to not lose the value, seemed strange that it loses that info.


The ok button is just there, does nothing. Escape to exit.
/*
3d toolbox v1
kryton9 - 8.16.2006

*/

// *****************************************************************************
// *ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  DECLARATIONSÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, *
// *****************************************************************************

DECLARE IMPORT,GetSysColor(index as int),int;

class My3DWindow : C3DScreen
{
declare My3DWindow();
declare _My3DWindow();
declare init();
declare k9Create(int width, int height);
declare render();
declare virtual OnClose(),int;
C3DScreen s;
C3DObject sc;
C3DCamera c;
C3DLight l;

CDirectInput di;
int ColorHigh, ColorMain,ColorLow;
int fps,lx,ly,ls;
}

class MyWindow : CWindow
{
declare MyWindow();
declare _MyWindow();
declare virtual OnClose(),int;
declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare virtual OnCreate(),int;
declareÂÃ,  OnHScroll(int nCommand,int nPos,int nID),int;
}
// *****************************************************************************
// *ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  GLOBALSÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  *
// *****************************************************************************
int nPos2;
float m1FB,m1UD,m1LR,m1Pitch,m1Yaw,m1Roll;
m1FB=.0f;
m1UD=.0f;
m1LR=.0f;
m1Pitch=.0f;
m1Yaw=.0f;
m1Roll=.0f;
C3DMesh m1,m2;
// *****************************************************************************
// *ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  MAIN ROUTINEÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, *
// *****************************************************************************

global sub main()
{
width = 600;height = 600;
My3DWindow w;
w.k9Create(width,height);
MyWindow cw;
do
{
w.Render();
}until w.di.KeyDown(dik_escape);
cw.onclose();w.onclose();
return true;
}

// *****************************************************************************
// *ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, CLASS DEFINITIONSÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, *
// *****************************************************************************

My3DWindow::My3DWindow()
{

}
My3DWindow::_My3DWindow()
{

}
My3DWindow::init()
{
ColorHigh = rgba(255,200,0,255);
ColorMain = rgba(205,150,0,255);
ColorLow = rgba(155,100,0,255);
fps=0;lx=10;ly=10;ls=10;
}
My3DWindow::k9Create(int width, int height)
{
Init();
s.CreateWindowed(0,0,width,height,AWS_VISIBLE | AWS_POPUP ,0,"",NULL,0);


di.Init(s);
c.Create(s);
c.Position(0,0,-8);
c.Orient(0,0,1,0,1,0);
l.Create(s,LIGHT_POINT,1);
l.Position(0,20,-150);
m1.CreateSphere(s,25,1,false);
m1.Position(0,0,0);
sc.CreateScene(s);
sc.AddChild(m1);
sc.AddChild(l);
c.SetBackPlane(10000);

s.Clear(rgba(0,0,0,255));
s.BeginScene(c);
s.RenderText(0,10,"Loading...",ColorLow);
s.RenderScene();
}
My3DWindow::Render()
{
s.Clear(rgba(0,0,0,255));
s.BeginScene(c);
m1.position(m1LR,m1UD,m1FB);
m1.rotate(m1Pitch,m1Yaw,m1Roll);
sc.Draw();
s.RenderText(lx,ly,"FPS: "+NumToStr(fps)+"ÂÃ,  ÂÃ,  nPos2: "+NumToStr(nPos2),ColorHigh);ly+=ls;
fps = s.RenderScene();
ly=10;
}
My3DWindow::OnClose()
{
s.CloseScreen();
}
//******************************************************* END MY3DWINDOW CLASS
MyWindow::MyWindow()
{
onCreate();
}

MyWindow::_MyWindow()
{
}

MyWindow::OnClose(),int
{
Destroy();
return 0;
}

MyWindow::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case 100:
if(nNotifyCode = 0)
MessageBox(this,"OK Pressed","Info");
case 11:
if(nNotifyCode = 0)
MessageBox(this,"Number 11","Info");
case 13:
if(nNotifyCode = 0)
MessageBox(this,"Number 13","Info");
case 15:
if(nNotifyCode = 0)
MessageBox(this,"Number 15","Info");
}
return true;
}

MyWindow::OnCreate(),int
{
Create(600,0,200,600,AWS_VISIBLE | AWS_POPUP ,0,"",NULL);
SetWindowColor(GetSysColor(15));
AddControl(CTGROUPBOX,"Object Movement",2,2,196,72,0x50000007,0x0,10);setfont("Arial",8,100,0,10);
AddControl(CTSCROLLBAR,"",4,20,125,12,0x50000000,0x0,11);
AddControl(CTSTATIC,"In/Out",132,20,60,20,0x5000010B,0x0,12);setfont("Arial",8,100,0,12);
AddControl(CTSCROLLBAR,"",4,35,125,12,0x50000000,0x0,13);
AddControl(CTSTATIC,"Up/Down",132,35,60,20,0x5000010B,0x0,14);setfont("Arial",8,100,0,14);
AddControl(CTSCROLLBAR,"",4,50,125,12,0x50000000,0x0,15);
AddControl(CTSTATIC,"Left/Right",132,50,60,20,0x5000010B,0x0,16);setfont("Arial",8,100,0,16);
AddControl(CTBUTTON,"OK",120,174,50,20,0x5000000B,0x0,100);

AddControl(CTGROUPBOX,"Object Rotation",2,75,196,72,0x50000007,0x0,20);setfont("Arial",8,100,0,20);
AddControl(CTSCROLLBAR,"",4,95,125,12,0x50000000,0x0,21);
AddControl(CTSTATIC,"Pitch",132,95,60,20,0x5000010B,0x0,22);setfont("Arial",8,100,0,22);
AddControl(CTSCROLLBAR,"",4,110,125,12,0x50000000,0x0,23);
AddControl(CTSTATIC,"Yaw",132,110,60,20,0x5000010B,0x0,24);setfont("Arial",8,100,0,24);
AddControl(CTSCROLLBAR,"",4,125,125,12,0x50000000,0x0,25);
AddControl(CTSTATIC,"Roll",132,125,60,20,0x5000010B,0x0,26);setfont("Arial",8,100,0,26);

CScrollBar *pScroll;
pScroll = GetControl(11); pScroll->SetScrollRange(-10,200);
pScroll->SetScrollPos(0);
pScroll = GetControl(13); pScroll->SetScrollRange(-50,50);
pScroll->SetScrollPos(0);
pScroll = GetControl(15); pScroll->SetScrollRange(-50,50);
pScroll->SetScrollPos(0);

pScroll = GetControl(21); pScroll->SetScrollRange(0,100);
pScroll->SetScrollPos(0);
pScroll = GetControl(23); pScroll->SetScrollRange(0,100);
pScroll->SetScrollPos(0);
pScroll = GetControl(25); pScroll->SetScrollRange(0,100);
pScroll->SetScrollPos(0);
return 0;
}
MyWindow::OnHScroll(int nCommand,int nPos,int nID),int
{
CScrollBar *pScroll = GetControl(nID);
SELECT nCommand
{
CASE SBTHUMBTRACK:
pScroll->SetScrollPos(nPos);nPos2=nPos;

CASE SBLINEUP:
temp = pScroll->GetScrollPos()-1;
if temp >-101 {pScroll->SetScrollPos(temp);nPos=temp;nPos2=nPos;}

CASE SBLINEDOWN:
temp = pScroll->GetScrollPos()+1;
if temp <101 {pScroll->SetScrollPos(temp);nPos=temp;nPos2=nPos;}

CASE SBPAGEUP:
temp = pScroll->GetScrollPos()-10;
pScroll->SetScrollPos(temp);nPos=temp;nPos2=nPos;

CASE SBPAGEDOWN:
temp = pScroll->GetScrollPos()+10;
pScroll->SetScrollPos(temp);nPos=temp;nPos2=nPos;
}

SELECT nID
{
CASE 11:
m1FB =nPos2;
CASE 13:
m1UD =nPos2;
CASE 15:
m1LR =nPos2;
CASE 21:
m1Pitch =nPos2;
CASE 23:
m1Yaw =nPos2;
CASE 25:
m1Roll =nPos2;
}
//MessageBox(this,NumToStr(nID),"nID");
return true;
}
//********************************************************* END MYWINDOW CLASS

Ionic Wind Support Team

I wrote a tutorial once on using scrollbars.  Have to search for it and repost it.

Don't depend on nPos from the hander, use GetThumbPos instead.  nPos is not updated by windows before the SBTHUMBTRACK command is sent.  It also only has WORD resolution which is a holdover from windows 3.1 that Microsoft has left in there.

Ionic Wind Support Team

kryton9

Ok thanks will check that out.

kryton9

Ok got it working. Works both ways
First way:
CASE SBTHUMBTRACK:
         nPos2=pScroll->GetThumbPos();
         pScroll->SetScrollPos(nPos2);

Second way:
CASE SBTHUMBTRACK:
         pScroll->SetScrollPos(pScroll->GetThumbPos());

Ionic Wind Support Team

Ionic Wind Support Team

kryton9

Got another question. When you click on the button that is in the control window, I want it to close both windows. This would be like pressing Escape from the 3d screen.
w is a pointer for my 3dwindow

So I put these into my program:
import INT SendMessage alias SendMessageA(INT hWnd,UNSIGNED INT Msg,UNSIGNED INT wParam,INT lParam);
const WM_KEYDOWN = 0x100;
const VK_ESCAPE = 0x01B;

.
.
.
Where the button push is being processed, I am trying to send this message, from the control window to the 3d window.
SendMessage(w->m_hwnd, WM_KEYDOWN, VK_ESCAPE, 1);

What am I doing wrong? Nothing happens.

sapero

SendMessage or keybd_event doesn't work for DirectInput. This library reads data only from hardware, not from system queue.
You can create a extra pointer to other window(s):
class My3DWindow : C3DScreen
{
  CWindow *otherWindowToClose; // OnClose call ->Destroy();
}

If you prefer SendMessage - use WM_CLOSE,0,0 :)

kryton9

Thanks will tinker with it to learn.