Sign in to follow this  
AWilson

Menu function problems...

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[i].type!=ITEM_INT) { len += strlen(items[i].name); if(len>maxNameLen)maxNameLen=len; } else { for(int j=0; j<items[i].IntItems.size(); j++) { if(strlen(items[i].IntItems[j].name) > len) len = strlen(items[i].IntItems[j].name); } if(len>maxNameLen)maxNameLen=len; } len=0; if(items[i].type==ITEM_BOOL)len+=7; else if(items[i].type==ITEM_KEY)len+=3; else if(items[i].type==ITEM_KEY_CHANGE)len+=3; else if(items[i].type==ITEM_INT) { len+=3; if(items[i].p == NULL) len+=4; } else if(items[i].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[i].type==ITEM_TEXT) { f->Print( xdelta, i+ydelta, items[i].name, 0, color); } else if(items[i].type==ITEM_KEY || items[i].type==ITEM_KEY_CHANGE) { if(items[i].p!=NULL) { char text_keys[2]={0}; f->Print(xdelta, i+ydelta, items[i].name, 0, color); if(items[i].key==-1)text_keys[0]='-'; else text_keys[0]=items[i].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[i].type==ITEM_BOOL) { if(items[i].p!=NULL) { char text_keys[2]={0}; f->Print(xdelta, i+ydelta, items[i].name, 0, color); if(*(int*)items[i].p )f->Print( xdelta+maxNameLen, i+ydelta, ": ON", 0, color); else f->Print( xdelta+maxNameLen, i+ydelta, ": OFF", 0, color); if(items[i].key==-1)text_keys[0]='-'; else text_keys[0]=items[i].key; f->Print(xdelta+maxNameLen+6, i+ydelta, text_keys, 0, color); } else { f->Print( xdelta+maxNameLen, i+ydelta, ": !!! !", 0, color); } } else if(items[i].type==ITEM_INT) { char text_keys[2]={0}; if(items[i].IntItems.size()<=0)f->Print(xdelta, i+ydelta, items[i].name, 0, color); else f->Print( xdelta, i+ydelta, items[i].IntItems[items[i].IntIndex].name, 0, color); if(items[i].key==-1)text_keys[0]='-'; else text_keys[0]=items[i].key; f->Print(xdelta+maxNameLen, i+ydelta, ":", 0, color); f->Print(xdelta+maxNameLen+2, i+ydelta, text_keys, 0, color); if(items[i].p==NULL)f->Print(xdelta+maxNameLen+4, i+ydelta, "!!!", 0, color); } else if(items[i].type==ITEM_FLOAT) { char text_keys[2]={0}; char text_float[50]; f->Print(xdelta, i+ydelta, items[i].name, 0, color); if(items[i].key==-1)text_keys[0]='-'; else text_keys[0]=items[i].key; f->Print(xdelta+maxNameLen+10, i+ydelta, text_keys, 0, color); float a = items[i].float_item.min+items[i].float_item.aktual*(items[i].float_item.max-items[i].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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this