Reputation: 1
I am building a deeply interactive fractal generator that will eventually be ported to something like an Arduino and made into a eurorack module, but that is beside the point, except to explain why I am trying to do this in low level graphics like windows GDI.
PUHBUTTONS (or keyboard input) simply refuse to update variables!
I am entirely new to coding, and although/because I have gotten this far without asking any real people any actual questions, and in just a few weeks, I'm sure that, although my code mostly works, I'm doing a lot wrong. I'll absolutely post all of what I've got if it comes to that, but here is what I hope will be enough for this single issue.
up at the top I've got this struct:
//container for Scaling and Shifting functions between screen and Mandelbrot values
struct ScreenScaler {
float xScale;
float yScale;
float xPos;
float yPos;
float xMin, xMax;
float yMin, yMax;
void initSpace (ScreenScaler &space) {
double zoomingBar = SendMessage(hSlider2, TBM_GETPOS, 0, 0);
float Zoom = (zoomingBar / 5);
float SlideX = SendMessage(hSlider3, TBM_GETPOS, 0, 0);
float SlideY = SendMessage(hSlider4, TBM_GETPOS, 0, 0);
space.xScale = 1 + Zoom;
space.yScale = 1 + Zoom;
space.xPos = 0; //(SlideX / 10) - 4;
space.yPos = (SlideY / 10) - 4;
space.xMin = ((-2) / space.xScale) + space.xPos;
space.xMax = ((2) / space.xScale) + space.xPos;
space.yMin = ((-2) / yScale) + space.yPos;
space.yMax = ((2) / yScale) + space.yPos;
}
void left(ScreenScaler *lscale, bool movleft) {
if (movleft) {
lscale->xPos -= 1.0; // I am passing these members by reference/pointer hoping to change their values directly. with the trackbars this works great, but buttons and keys stubbornly refuse to increment..
}
}
void right(ScreenScaler *rscale) {
rscale->xPos += 1.0;
}
};
Currently my trackbars still control up, down, and zoom, I am trying first to implement this with left/right. In this state, the trackbars still work as intended.
then, I handle WM_KEYDOWN like this (some baggage included):
case WM_KEYDOWN:
{
bool movleft = false; //so I am getting here for sure, if I uncomment the messagebeep, it sounds when its button is pressed.
//bool right = false; //id like this to be a continuous shifting while the button is held (the sound of the messagebeep implies this is already happening), as I am trying to move left and right/up and down//
if (LOWORD(wParam) == VK_LEFT)
/*case VK_LEFT:*/ {
movleft = true;
scale.left(&scale, movleft);
scale.xPos = scale.xPos -= 1;
//MessageBeep(MB_OK);
break;
}
if (LOWORD(wParam) == VK_RIGHT)
/*case VK_RIGHT: */{
scale.right(&scale);
scale.xPos = scale.xPos += 1;
//MessageBeep(MB_COMPOSITE);
break;
}
// }
return 0;
}
(to answer why there's a bool on one and not the other, it is of course another attempt to force the struct to recognize I am changing it.)
then finally I want to use the current updated value in the current frame (or next frame I guess) in WM_PAINT, in such a way as this for example:
//ScreenScaler scale declared earlier
float cx = std::lerp(scale.xMin, scale.xMax, j);
float cy = std::lerp(scale.yMin, scale.yMax, i);
I have tried trapping WM_COMMAND or WM_NOTIFY instead, I've tried building buttons (though haven't attempted subclassing, and yes with BS_NOTIFY in the appropriate case) I have tried incrementing directly from the case rather than a void in the struct, I've tried having those voids outside the struct, various permutations of '&' and '*'. Even though I only call initSpace once, the trackbars work continuously, and the best part is that when this is in its final form there will not BE buttons, it'll be voltages on pins. Right now the increment values are huge (1 is big here) just because I want to be sure I'm gonna see the damn change when it works, but the plan is for that to be much smaller, and that increment to be defined elsewhere and reduced when zoomed further in (all of this scaling will still matter when it's voltage).
as a final explainer/disclaimer, I have also done this specifically without searching for how to make what I'm making, going more for general learning, and translating what I find into this project until it functions with it.
Upvotes: -1
Views: 101