Jump to content
  • Advertisement
Sign in to follow this  
AWilson

Menu function problems...

This topic is 4056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Below is some code for a menu system I am currently working on. It draws the menu nicely but whenever I click on something in the menu nothing happens. Have a look at the source and tell me what you think is wrong, thanks. ////// void Menu::Render(float timeframe) { diKeyboard->GetDeviceState(256, (LPVOID)keystate); ZeroMemory(&mousestate, sizeof(mousestate)); diMouse->GetDeviceState(sizeof(DIMOUSESTATE), &mousestate); if(FAILED(D3DXCreateTextureFromFile(d3dDevice, "textures/model/test.bmp", &TEXmenumain))) { sprintf(txt,"Cannot load menu."); error(); return; } POINT MousePoint; RECT WindowRect,ClientRect; GetCursorPos(&MousePoint); GetWindowRect(hWnd, &WindowRect); GetClientRect(hWnd, &ClientRect); int vy = ClientRect.bottom; int vx = ClientRect.right; int mouse_move=0; if(last_mouse_pos.x != MousePoint.x || last_mouse_pos.y != MousePoint.y) mouse_move=1; float xf = (screen_x_font/(float)vx)*(MousePoint.x-WindowRect.left+ClientRect.left)/(float)11; float yf = (screen_y_font/(float)vy)*(MousePoint.y-WindowRect.top+ClientRect.top)/16; int ydelta=1; int xdelta=1; int zn=0; int ri=0; int maxNameLen=0; int maxExtLen=0; for(int i=0; i<items.size(); i++) { int len=0; if(items.type!=ITEM_INT) { len += strlen(items.name); if(len>maxNameLen)maxNameLen=len; } else { for(int j=0; j<items.IntItems.size(); j++) { if(strlen(items.IntItems[j].name) > len) len = strlen(items.IntItems[j].name); } if(len>maxNameLen)maxNameLen=len; } len=0; if(items.type==ITEM_BOOL)len+=7; else if(items.type==ITEM_KEY)len+=3; else if(items.type==ITEM_KEY_CHANGE)len+=3; else if(items.type==ITEM_INT) { len+=3; if(items.p == NULL) len+=4; } else if(items.type==ITEM_FLOAT)len+=11; else len+=7; if(len>maxExtLen)maxExtLen = len; ri++; zn = maxNameLen+maxExtLen; if(zn>70)zn=70; xdelta = (85-zn)/2+1; ydelta = (45-ri)/2+1; int x = (int)xf-xdelta; int y = (int)yf-ydelta; int akt_item_old = akt_item; if(mouse_move) { if(y>=0 && y<items.size() && x>=0 && x<zn) akt_item=y; } if( akt_item != akt_item_old ) { mousestate.rgbButtons[0]=0; } if(items[akt_item].type==ITEM_BOOL) { if(mousestate.rgbButtons[0]) { if(items[akt_item].p!=NULL)*(int*)items[akt_item].p=!*(int*)items[akt_item].p; mousestate.rgbButtons[0]=0; } } else if(items[akt_item].type==ITEM_INT) { if(items[akt_item].IntItems.size()>0) { if(mousestate.rgbButtons[0]) { items[akt_item].IntIndex = (items[akt_item].IntIndex+1)%items[akt_item].IntItems.size(); } if(items[akt_item].p!=NULL) { *(int*)items[akt_item].p = items[akt_item].IntItems[items[akt_item].IntIndex].value; } } mousestate.rgbButtons[0]=0; } else if(items[akt_item].type==ITEM_FLOAT) { float step=0.1f; if(mousestate.rgbButtons[0] && mouse_move) { items[akt_item].float_item.aktual+= (float)(MousePoint.x - last_mouse_pos.x)*step*0.03f; if(items[akt_item].float_item.aktual>1.0f)items[akt_item].float_item.aktual=1.f; if(items[akt_item].float_item.aktual<0.0f)items[akt_item].float_item.aktual=0.f; if(items[akt_item].p!=NULL) { *(float*)items[akt_item].p = items[akt_item].float_item.min + items[akt_item].float_item.aktual*(items[akt_item].float_item.max-items[akt_item].float_item.min); } } else if(items[akt_item].type==ITEM_KEY_CHANGE) { if(mousestate.rgbButtons[0]) { if(items[akt_item].p!=NULL) *(int*)items[akt_item].p=1; mousestate.rgbButtons[0]=0; } } } //draw here...> f->Begin(); int i; for(i=0; i<items.size(); i++) { if(i==akt_item)color = D3DCOLOR_ARGB(255,255,0,0); if(items.type==ITEM_TEXT) { f->Print( xdelta, i+ydelta, items.name, 0, color); } else if(items.type==ITEM_KEY || items.type==ITEM_KEY_CHANGE) { if(items.p!=NULL) { char text_keys[2]={0}; f->Print(xdelta, i+ydelta, items.name, 0, color); if(items.key==-1)text_keys[0]='-'; else text_keys[0]=items.key; f->Print(xdelta+maxNameLen, i+ydelta, ":", 0, color); f->Print(xdelta+maxNameLen+2, i+ydelta, text_keys, 0, color); } else { f->Print( xdelta+maxNameLen, i+ydelta, ": !!! !", 0, color); } } else if(items.type==ITEM_BOOL) { if(items.p!=NULL) { char text_keys[2]={0}; f->Print(xdelta, i+ydelta, items.name, 0, color); if(*(int*)items.p )f->Print( xdelta+maxNameLen, i+ydelta, ": ON", 0, color); else f->Print( xdelta+maxNameLen, i+ydelta, ": OFF", 0, color); if(items.key==-1)text_keys[0]='-'; else text_keys[0]=items.key; f->Print(xdelta+maxNameLen+6, i+ydelta, text_keys, 0, color); } else { f->Print( xdelta+maxNameLen, i+ydelta, ": !!! !", 0, color); } } else if(items.type==ITEM_INT) { char text_keys[2]={0}; if(items.IntItems.size()<=0)f->Print(xdelta, i+ydelta, items.name, 0, color); else f->Print( xdelta, i+ydelta, items.IntItems[items.IntIndex].name, 0, color); if(items.key==-1)text_keys[0]='-'; else text_keys[0]=items.key; f->Print(xdelta+maxNameLen, i+ydelta, ":", 0, color); f->Print(xdelta+maxNameLen+2, i+ydelta, text_keys, 0, color); if(items.p==NULL)f->Print(xdelta+maxNameLen+4, i+ydelta, "!!!", 0, color); } else if(items.type==ITEM_FLOAT) { char text_keys[2]={0}; char text_float[50]; f->Print(xdelta, i+ydelta, items.name, 0, color); if(items.key==-1)text_keys[0]='-'; else text_keys[0]=items.key; f->Print(xdelta+maxNameLen+10, i+ydelta, text_keys, 0, color); float a = items.float_item.min+items.float_item.aktual*(items.float_item.max-items.float_item.min); _gcvt((double)a, 4, text_float); f->Print(xdelta+maxNameLen, i+ydelta, ":", 0, color); f->Print(xdelta+maxNameLen+2, i+ydelta, text_float, 0, color); } color = D3DCOLOR_ARGB(255,255,255,255); } f->End(); last_mouse_pos = MousePoint; } void Menu::AddKeyChange(char *name, int key, void *p) { MENUITEM i; strncpy(i.name, name, 50); i.name[50]=NULL; i.key = key; if(i.key!=-1)keystate[i.key]=0; i.p = p; if(i.p!=NULL)*(int*)i.p = 0; i.type = ITEM_KEY_CHANGE; items.push_back(i); }

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!