bool Button(int x, int y, bool highlight, const char* text, int id) { DWORD color1=0x000000; DWORD color2=0xA09088; DWORD color3=0x000000; bool hover=MouseInBox(x, y, 100, 17); if(hover && mouse_leftclick) vcurbutton=id; bool current=(vcurbutton==id); if(highlight) { color1=0x000000; color2=0x988070; color3=0xFFF0E0; } if(current && hover) { color1=0xA09088; color2=0xFFF0E0; color3=0xA09088; } DrawBar(x-1, y-1, 102, 19, color1); DrawBar(x, y, 100, 17, color2); DrawText(x+5, y+5, color3, text); if(current && hover && !mouse_left) return true; return false; }
void Slider(int x, int y, float& value, bool bipolar, const char* text) { if(MouseInBox(x, y, 100, 10)) { if(mouse_leftclick) vselected=&value; else if(mouse_rightclick) value=0.0f; else if(mouse_scrollup) value+=0.001f; else if(mouse_scrolldown) value-=0.001f; } float mv=(float)(mouse_x-mouse_px); if(vselected!=&value) mv=0.0f; if(bipolar) { value+=mv*0.005f; if(value<-1.0f) value=-1.0f; if(value>1.0f) value=1.0f; } else { value+=mv*0.0025f; if(value<0.0f) value=0.0f; if(value>1.0f) value=1.0f; } DrawBar(x-1, y, 102, 10, 0x000000); int ival=(int)(value*99); if(bipolar) ival=(int)(value*49.5f+49.5f); DrawBar(x, y+1, ival, 8, 0xF0C090); DrawBar(x+ival, y+1, 100-ival, 8, 0x807060); DrawBar(x+ival, y+1, 1, 8, 0xFFFFFF); if(bipolar) { DrawBar(x+50, y-1, 1, 3, 0x000000); DrawBar(x+50, y+8, 1, 3, 0x000000); } DWORD tcol=0x000000; if(channels[currentChannel].wave_type!=0 && (&value==&channels[currentChannel].p_duty || &value==&channels[currentChannel].p_duty_ramp)) tcol=0x808080; DrawText(x-4-strlen(text)*8, y+1, tcol, text); char* strValue = ftoa(value); DrawText(x+100-4-strlen(strValue)*8, y+1, 0xFFFFFF, strValue); }
/****************************************************************************** * long APIENTRY FontEditWndProc(hBox, message, wParam, lParam) * * purpose: Master controller for Fontedit's all-encompassing main window * * params : same as for all window functions * * side effects: countless * *****************************************************************************/ LONG APIENTRY FontEditWndProc( HWND hBox, WORD message, WPARAM wParam, LONG lParam ) { PAINTSTRUCT ps; HMENU hMenu; WORD mf; POINT pt; RECT BoxRect; switch (message) { case WM_CLOSE: if (!CheckSave()) /* See if any files need saving */ break; /* Window's being destroyed. */ if (fLoaded) /* 4/8/87 Linsh added */ DeleteBitmap(); /* Get rid of memory DC */ DestroyWindow(hFont); DestroyWindow(hBox); break; case WM_DESTROY: PostQuitMessage(0); /* Cause application to be terminated */ break; case WM_QUERYENDSESSION: if (CheckSave()) /* See if any files need saving */ return TRUE; break; case WM_ENDSESSION: if (fLoaded) DeleteBitmap(); /* Get rid of memory DC */ break; case WM_SIZE: /* Window's size is changing. lParam contains the width ** and height, in the low and high words, respectively. ** wParam contains SIZENORMAL for "normal" size changes, ** SIZEICONIC when the window is being made iconic, and ** SIZEFULLSCREEN when the window is being made full screen. */ switch (wParam) { case SIZEFULLSCREEN: case SIZENORMAL: ResizeShow(); if (kStuff != GetkStuff()) /* Did it change ? */ ResizeShow(); /* Yes resize again */ break; } break; case WM_MOVE: /* Tell popup to move with us. */ if (!IsIconic(hBox)) ResizeShow(); break; case WM_PAINT: /* Time for the window to draw itself. */ BeginPaint(hBox, (LPPAINTSTRUCT)&ps); FontEditPaint(hBox, ps.hdc); EndPaint(hBox, (LPPAINTSTRUCT)&ps); break; case WM_COMMAND: /* A menu item has been selected, or a control is notifying * its parent. wParam is the menu item value (for menus), * or control ID (for controls). For controls, the low word * of lParam has the window handle of the control, and the hi * word has the notification code. For menus, lParam contains * 0L. */ FontEditCommand(hBox, GET_WM_COMMAND_ID(wParam, lParam)); break; /* Data interchange request. */ case WM_CUT: case WM_COPY: case WM_PASTE: case WM_CLEAR: case WM_UNDO: case WM_RENDERFORMAT: case WM_RENDERALLFORMATS: case WM_DESTROYCLIPBOARD: case WM_DRAWCLIPBOARD: break; case WM_INITMENU: hMenu = GetMenu(hBox); /* Gray menu if no clipboard bitmap */ mf = (WORD)(IsClipboardFormatAvailable(CF_BITMAP) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(hMenu, BOX_PASTE, mf); EnableMenuItem(hMenu, FONT_PASTE, mf); break; /* For each of following mouse window messages, wParam contains ** bits indicating whether or not various virtual keys are down, ** and lParam is a POINT containing the mouse coordinates. The ** keydown bits of wParam are: MK_LBUTTON (set if Left Button is ** down); MK_RBUTTON (set if Right Button is down); MK_SHIFT (set ** if Shift Key is down); MK_ALTERNATE (set if Alt Key is down); ** and MK_CONTROL (set if Control Key is down). */ case WM_LBUTTONDOWN: MPOINT2POINT(MAKEMPOINT(lParam), pt); if (fStartRubberBand) { /* a green signal to rubberband a rectangle for the * Fill menu command rectangle now has null dimensions. * Snap the current mouse point to nearest grid * intersection thus defining upper left corner of * rectangle */ if (PtInRect((LPRECT)&FontRect, pt)) { pt = SnapPointToGrid(pt); rectRubber.top = pt.y *scale+ptBox.y+1; rectRubber.bottom = (pt.y+1)*scale+ptBox.y-2; rectRubber.left = pt.x *scale+ptBox.x+1; rectRubber.right = (pt.x+1)*scale+ptBox.x-2; hDst = InitialiseRubberBandingRect(hBox); DrawRubberBand(hDst, &rectRubber, R2_XORPEN); } else { fStartRubberBand = fRubberBanding = FALSE; ReleaseCapture(); } } /* do operation depending upon current active command, * but not if we just added/deleted a row/column. */ if (!fJustZapped) { if (fStartRubberBand) { pt.x *= scale; pt.y *= scale; MouseInBox(hBox, message, pt); } else { MPOINT2POINT(MAKEMPOINT(lParam), pt); MouseInBox(hBox, message, pt); } } break; case WM_LBUTTONUP: /* Get other corner of rectangle */ fJustZapped = FALSE; if (fRubberBanding) { /* if rubberbanding for the Fill menu command, * terminate proceedings and clean up */ DrawRubberBand(hDst, &rectRubber, R2_NOT); EndRubberBandingRect(hDst); if (cursor) { ReadRect(); } } if (fCaptured ) { /* if cursor is + shaped, restore it to default */ ReleaseCapture(); SetCursor (hOldCursor); } break; case WM_RBUTTONDOWN: case WM_RBUTTONUP: break; case WM_MOUSEMOVE: /* If mouse is down */ MPOINT2POINT(MAKEMPOINT(lParam), pt); if ((fRubberBanding) && (wParam & MK_LBUTTON)) { /* if any of Fill menu commands is active ** (AND the mouse key depressed) draw a rubberband ** a rectangle with the mouse movements */ /* get current square number */ pt = SnapPointToGrid(pt); /* calculate grid for new square */ BoxRect.top = pt.y *scale+ptBox.y+1; BoxRect.bottom = (pt.y+1)*scale+ptBox.y-2; BoxRect.left = pt.x *scale+ptBox.x+1; BoxRect.right = (pt.x+1)*scale+ptBox.x-2; /* erase old mark */ DrawRubberBand(hDst, &rectRubber, R2_NOT); /* limit rubber band to box */ if (BoxRect.right > scale * (LONG)wBox + ptBox.x) BoxRect.right = scale * wBox + ptBox.x; if (BoxRect.bottom > scale * (LONG)kBox + ptBox.y) BoxRect.bottom = scale * kBox + ptBox.y; if (BoxRect.top < 0) BoxRect.top = 1; if (BoxRect.left < 0) BoxRect.left = 1; if (ptA.x == pt.x) { rectRubber.right = BoxRect.right; rectRubber.left = BoxRect.left; } if (ptA.y == pt.y) { rectRubber.bottom = BoxRect.bottom; rectRubber.top = BoxRect.top; } /* almost an IntersectRect */ if (ptA.x >= pt.x) rectRubber.left = BoxRect.left; else rectRubber.right = BoxRect.right; if (ptA.y >= pt.y) rectRubber.top = BoxRect.top; else rectRubber.bottom = BoxRect.bottom; /* Draw new mark */ DrawRubberBand(hDst, &rectRubber, R2_XORPEN); } else { /* if not "Fill"ing(AND mouse key depressed, * paint with the mouse movements */ if ((wParam & MK_LBUTTON) && cursor == FALSE && fJustZapped == FALSE) MouseInBox(hBox, message, pt); } break; case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: break; default: /* Everything else comes here. This call MUST exist ** in your window proc. */ return(DefWindowProc(hBox, message, wParam, lParam)); break; } /* A window proc should always return something */ return(0L); }