About animated knob again


I m playing around animated knobs.
Here is an example.


Seems, the knob response is not so rapid as needed ((
Any ideas?


alex, I’m a bit reluctant to just run an untrusted exe, and your link looks a bit dodgy to me. Can you post your source code or explain the problem?


Sorry, Jules. Knob.cpp contains a bunch of png binary data as an array. Its about 3500 lines of code. This exe is a self extracting zip with 2 files Knob.h and Knob.c , which can be immediately attached to the project.
But if you are in a doubt, I ll try to explain.
Actual work in
void KNOB::mouseDrag (const MouseEvent & e )

#include "KNOB.h"

    : internalCachedImage1 (0)
	, xFrame(0), yFrame (0),wFrame (60) , hFrame(60)

    internalCachedImage1 = ImageCache::getFromMemory (knob_stitched_png, knob_stitched_pngSize);


    setSize (60, 60);
	setRepaintsOnMouseActivity (true);

    //[Constructor] You can add your own custom stuff here..

    //[Destructor_pre]. You can add your own custom destruction code here..

    ImageCache::release (internalCachedImage1);

    //[Destructor]. You can add your own custom destruction code here..

void KNOB::paint (Graphics& g)
    //[UserPrePaint] Add your own custom painting code here..
    //[/UserPrePaint]g.setColour (Colours::black);
    g.drawImage (internalCachedImage1,
                 0, 0 ,60 ,60,
                 xFrame, yFrame, wFrame, hFrame);

    //[UserPaint] Add your own custom painting code here..

void KNOB::resized()
    //[UserResized] Add your own custom resize handling here..
void KNOB::mouseDrag (const MouseEvent & e )
	int ytmp = e.getMouseDownY();

	if ( ytmp < e.y ) 
		if ( yFrame < (3780 - 60) ) 
		{yFrame= yFrame + 60 ; }
		{ yFrame= yFrame;}

       // repaint();

	if  ( ytmp > e.y )
		if ( yFrame > 0 ) 
		{yFrame= yFrame - 60 ;}
		{yFrame = yFrame ; }

	//	 repaint();


//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...

#if 0
/*  -- Jucer information section --

    This is where the Jucer puts all of its metadata, so don't change anything in here!


<JUCER_COMPONENT documentType="Component" className="KNOB" componentName="" parentClasses="public Component"
                 constructorParams="" variableInitialisers="" snapPixels="8" snapActive="1"
                 snapShown="1" overlayOpacity="0.330000013" fixedSize="1" initialWidth="60"
  <BACKGROUND backgroundColour="ffffff">
    <IMAGE pos="0 0 60 3780" resource="knob_stitched_png" opacity="1" mode="0"/>


// Binary resources - be careful not to edit any of these sections!

// JUCER_RESOURCE: knob_stitched_png, 221316, "\knob_stitched.png"
static const unsigned char resource_KNOB_knob_stitched_png[] = { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,60,0,0,14,196,8,6,0,0,0,147,2,57,91,0,0,0,9,112,72,89,115,0,0,11,19,0,0,11,19,1,0,154,
152,24,24,25,25,105,230,63,128,0,98,36,228,41,106,90,14,2,234,234,234,12,219, .......................................................


Looks fine to me, apart from your rather bizarre way of using the mouse position. What’s the problem?


The problem is :
Knob rotation (moving the xFrame/yFrame window along entire png ) actually is not related with mouse movement. (sometimes its faster, sometimes – slower)
Probably its my rather bizarre way of using the mouse position.
What way is correct?


Yes, it’s definitely your bizarre mouse routine, which just looks like gibberish to me…

A better approach would be to use a custom-drawn Slider object - i.e. use a normal slider with a custom look and feel that draws the knob.


thank you very much.