summaryrefslogtreecommitdiff
path: root/app/bin/chotbar.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/chotbar.c')
-rw-r--r--app/bin/chotbar.c187
1 files changed, 112 insertions, 75 deletions
diff --git a/app/bin/chotbar.c b/app/bin/chotbar.c
index 0b9a327..379f31a 100644
--- a/app/bin/chotbar.c
+++ b/app/bin/chotbar.c
@@ -20,22 +20,21 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include <ctype.h>
-#include <stdint.h>
-#include <string.h>
-
#include "compound.h"
#include "fileio.h"
-#include "messages.h"
#include "ccornu.h"
#include "track.h"
+#include "draw.h"
EXPORT DIST_T curBarScale = -1;
EXPORT long hotBarLabels = 0;
+EXPORT wWinPix_t hotBarHeight = 32;
#include "bitmaps/hotbarl.xbm"
#include "bitmaps/hotbarr.xbm"
+#define HOTBAR_LEFT 2
+
static wButton_p hotBarLeftB = NULL;
static wButton_p hotBarRightB = NULL;
static wMenu_p hotbarPopupM;
@@ -49,8 +48,8 @@ static drawCmd_t hotBarD = {
0.0,
{0.0, 0.0}, {0.0, 0.0},
Pix2CoOrd, CoOrd2Pix };
-static wPos_t hotBarDrawHeight = 28;
-static wPos_t hotBarHeight = 28;
+static wWinPix_t hotBarDrawHeight[] = {26, 32, 40};
+static wFontSize_t hotBarFontSize[] = {7, 8, 9};
typedef struct {
DIST_T x;
DIST_T w;
@@ -75,23 +74,35 @@ static DIST_T hotBarWidth = 0.0;
static void HotBarHighlight( int inx, DIST_T fixed_x )
{
- wPos_t x0;
- if ( inx == 0 && hotBarMap_da.cnt>0 && hotBarMap(0).isFixed) {
- x0 = (wPos_t)0;
- wDrawFilledRectangle( hotBarD.d, x0, 0, (wPos_t)(hotBarMap(0).w*hotBarD.dpi-2), hotBarHeight, wDrawColorBlack, wDrawOptTransparent );
- } else if ( inx >= hotBarCurrStart && inx < hotBarCurrEnd ) {
- x0 = (wPos_t)((hotBarMap(inx).x-hotBarMap((int)hotBarCurrStart).x + (inx>0?fixed_x:0))*hotBarD.dpi);
- wDrawFilledRectangle( hotBarD.d, x0, 0, (wPos_t)(hotBarMap(inx).w*hotBarD.dpi-2), hotBarHeight, wDrawColorBlack, wDrawOptTransparent );
- }
+ if ( inx > 0 && ( inx < hotBarCurrStart || inx >= hotBarCurrEnd ) )
+ return;
+ coOrd orig, size;
+ hotBarD.scale = 1;
+ if ( inx == 0 && hotBarMap_da.cnt>0 && hotBarMap(0).isFixed)
+ orig.x = 0;
+ else
+ orig.x = hotBarMap(inx).x-hotBarMap(hotBarCurrStart).x + (inx>0?fixed_x:0);
+ orig.y = 0;
+ size.x = hotBarMap(inx).w - 2.0/hotBarD.dpi;
+ size.y = toolbarHeight;
+#ifdef LATER
+ printf( "HotBarHilite fixed_x:%0.3f X0:%d/%0.3f X:%d/%0.3f+%0.3f X=%0.3f\n",
+ fixed_x,
+ hotBarCurrStart, hotBarMap(hotBarCurrStart).x,
+ inx, hotBarMap(inx).x, hotBarMap(inx).w,
+ orig.x );
+#endif
+ DrawRectangle( &hotBarD, orig, size, wDrawColorBlack, DRAW_TRANSPARENT );
}
static wFont_p hotBarFp = NULL;
static wFontSize_t hotBarFs = 8;
+static wWinPix_t hotBarTextHeight = 11;
-static void RedrawHotBar( wDraw_p dd, void * data, wPos_t w, wPos_t h )
+static void RedrawHotBar( wDraw_p dd, void * data, wWinPix_t w, wWinPix_t h )
{
- DIST_T hh = (double)hotBarDrawHeight/hotBarD.dpi;
+ DIST_T hh = (double)(hotBarHeight + 1)/hotBarD.dpi;
coOrd orig;
int inx;
hotBarMap_t * tbm;
@@ -101,22 +112,29 @@ static void RedrawHotBar( wDraw_p dd, void * data, wPos_t w, wPos_t h )
DIST_T x;
wDrawClear( hotBarD.d );
- wControlActive( (wControl_p)hotBarLeftB, hotBarCurrStart > 0 );
+ if (hotBarCurrStart >0)
+ wControlActive( (wControl_p)hotBarLeftB, TRUE );
+ else {
+ wButtonSetBusy(hotBarLeftB, FALSE);
+ wControlActive( (wControl_p)hotBarLeftB, FALSE );
+ }
+
if (hotBarCurrStart < 0) {
+ wButtonSetBusy(hotBarRightB, FALSE);
wControlActive( (wControl_p)hotBarRightB, FALSE );
return;
}
if ( hotBarLabels && !hotBarFp )
hotBarFp = wStandardFont( F_HELV, FALSE, FALSE );
- wPos_t textSize = wMessageGetHeight(0L);
+
DIST_T fixed_x = 0.0;
if (hotBarCurrStart>0 && hotBarMap_da.cnt>0 && hotBarMap(0).isFixed) { //Do fixed element first - Cornu
tbm = &hotBarMap(0);
barScale = tbm->barScale;
x = 0.0;
- orig.y = hh/2.0*barScale - tbm->size.y/2.0 - tbm->orig.y;
+ orig.y = barScale/hotBarD.dpi + hh/2.0*barScale - tbm->size.y/2.0 - tbm->orig.y;
if ( hotBarLabels ) {
- orig.y += textSize/hotBarD.dpi*barScale;
+ orig.y += hotBarTextHeight/hotBarD.dpi*barScale;
if ( tbm->labelW > tbm->objectW ) {
fixed_x = tbm->labelW;
x += (tbm->labelW-tbm->objectW)/2;
@@ -139,13 +157,13 @@ static void RedrawHotBar( wDraw_p dd, void * data, wPos_t w, wPos_t h )
for ( inx=hotBarCurrStart; inx < hotBarMap_da.cnt; inx++ ) {
tbm = &hotBarMap(inx);
barScale = tbm->barScale;
- x = tbm->x - hotBarMap(hotBarCurrStart).x + fixed_x; //Add space for fixed at start
- if ( x + tbm->w + fixed_x > barWidth ) {
+ x = tbm->x - hotBarMap(hotBarCurrStart).x + fixed_x;
+ if ( x + tbm->w > barWidth ) {
break;
}
- orig.y = hh/2.0*barScale - tbm->size.y/2.0 - tbm->orig.y;
+ orig.y = barScale/hotBarD.dpi + hh/2.0*barScale - tbm->size.y/2.0 - tbm->orig.y;
if ( hotBarLabels ) {
- orig.y += textSize/hotBarD.dpi*barScale;
+ orig.y += hotBarTextHeight/hotBarD.dpi*barScale;
if ( tbm->labelW > tbm->objectW ) {
x += (tbm->labelW-tbm->objectW)/2;
}
@@ -170,7 +188,12 @@ static void RedrawHotBar( wDraw_p dd, void * data, wPos_t w, wPos_t h )
HotBarHighlight( hotBarCurrSelect, fixed_x );
/* else
hotBarCurrSelect = -1;*/
- wControlActive( (wControl_p)hotBarRightB, hotBarCurrEnd < hotBarMap_da.cnt );
+ if (hotBarCurrEnd < hotBarMap_da.cnt)
+ wControlActive( (wControl_p)hotBarRightB, TRUE );
+ else {
+ wButtonSetBusy(hotBarRightB, FALSE);
+ wControlActive( (wControl_p)hotBarRightB, FALSE );
+ }
wPrefSetInteger( "misc", "hotbar-start", hotBarCurrStart );
}
@@ -187,7 +210,11 @@ static void DoHotBarRight( void * data )
}
if ( inx >= hotBarMap_da.cnt )
inx = hotBarMap_da.cnt-1;
- while ( inx > 1 && lastX - hotBarMap(inx-1).x <= barWidth )
+ DIST_T fixed_x = 0.0;
+ if (hotBarCurrStart>0 && hotBarMap(0).isFixed) {
+ fixed_x = hotBarMap(0).w;
+ }
+ while ( (inx > 1) && ((lastX - hotBarMap(inx-1).x) < (barWidth - fixed_x)) )
inx--;
if ( inx != hotBarCurrStart ) {
hotBarCurrStart = inx;
@@ -237,12 +264,12 @@ static void DoHotBarJump( int inx )
}
-static void SelectHotBar( wDraw_p d, void * context, wAction_t action, wPos_t w, wPos_t h )
+static void SelectHotBar( wDraw_p d, void * context, wAction_t action, wDrawPix_t w, wDrawPix_t h )
{
int inx;
coOrd pos;
DIST_T x;
- wPos_t px;
+ wWinPix_t px;
hotBarMap_t * tbm;
char * titleP;
@@ -279,11 +306,11 @@ static void SelectHotBar( wDraw_p d, void * context, wAction_t action, wPos_t w,
return;
tbm = &hotBarMap(inx);
if (inx==0) {
- px = (wPos_t)((tbm->x-hotBarMap(0).x)*hotBarD.dpi);
+ px = (wWinPix_t)((tbm->x-hotBarMap(0).x)*hotBarD.dpi);
} else {
- px = (wPos_t)(((tbm->x-hotBarMap(hotBarCurrStart).x)+fixed_x)*hotBarD.dpi);
+ px = (wWinPix_t)(((tbm->x-hotBarMap(hotBarCurrStart).x)+fixed_x)*hotBarD.dpi);
}
- px += (wPos_t)(tbm->w*hotBarD.dpi/2);
+ px += (wWinPix_t)(tbm->w*hotBarD.dpi/2);
titleP = tbm->proc( HB_LISTTITLE, tbm->context, NULL, NULL );
px -= wLabelWidth( titleP ) / 2;
wControlSetBalloon( (wControl_p)hotBarD.d, px, -20, titleP );
@@ -386,7 +413,7 @@ static BOOL_T HotBarSelectPlayback( char * line )
static void HotbarJump( int inx, const char * name, void * arg )
{
- hotBarCurrStart = (int)(long)arg;
+ hotBarCurrStart = (int)VP2L(arg);
RedrawHotBar( hotBarD.d, NULL, 0, 0 );
}
@@ -412,19 +439,22 @@ EXPORT void AddHotBarElement(
hotBarMap_t * tbm;
coOrd textsize;
- if ( contentsLabel && strncmp(contentsLabel, curContentsLabel, sizeof curContentsLabel) != 0 ) {
- wMenuListAdd( hotBarML, hotBarMLcnt++, contentsLabel, (void*)(intptr_t)hotBarMap_da.cnt );
+ if ( contentsLabel && strncmp(contentsLabel, curContentsLabel, sizeof curContentsLabel) != 0 && !isFixed ) {
+ wMenuListAdd( hotBarML, hotBarMLcnt++, contentsLabel, I2VP(hotBarMap_da.cnt) );
strncpy( curContentsLabel, contentsLabel, sizeof curContentsLabel );
}
-
if (barScale <= 0) {
if (!isTrack)
- barScale = size.y/((double)hotBarDrawHeight/hotBarD.dpi);
+ barScale = size.y/(((double)hotBarHeight-2.0)/hotBarD.dpi);
else if (isTrack) {
- barScale = (trackGauge>0.1)?trackGauge*24:10;
- if (size.y >= size.x)
- barScale = size.y/((double)hotBarDrawHeight/hotBarD.dpi);
+ // size.y += 2.0 * trackGauge;
+ barScale = (trackGauge>0.1)?trackGauge*(36-hotBarHeight/2):10.0;
+ // barScale = 2.0 / ((hotBarHeight-2.0) / hotBarD.dpi);
+ //if (size.y >= size.x)
+ if (size.y/barScale > ((double)hotBarHeight-2.0)/hotBarD.dpi)
+ barScale = (size.y+2.0*trackGauge)/(((double)hotBarHeight-2.0)/hotBarD.dpi);
}
+ // orig.y += 1.0/hotBarD.dpi;
}
DYNARR_APPEND( hotBarMap_t, hotBarMap_da, 10 );
tbm = &hotBarMap(hotBarMap_da.cnt-1);
@@ -465,27 +495,27 @@ static void ChangeHotBar( long changes )
if ( hotBarLabels && !hotBarFp )
hotBarFp = wStandardFont( F_HELV, FALSE, FALSE );
if (hotBarLeftB != NULL && curScaleName) {
- hotBarWidth = 0.0;
- hotBarMLcnt = 0;
- wMenuListClear( hotBarML );
- DYNARR_RESET( hotBarMap_t, hotBarMap_da );
- curContentsLabel[0] = '\0';
- if ( programMode == MODE_DESIGN ) {
- if (showFlexTrack)
- AddHotBarCornu();
- AddHotBarTurnouts();
- AddHotBarStructures();
- } else {
- AddHotBarCarDesc();
- }
+ hotBarWidth = 0.0;
+ hotBarMLcnt = 0;
+ wMenuListClear( hotBarML );
+ DYNARR_RESET( hotBarMap_t, hotBarMap_da );
+ curContentsLabel[0] = '\0';
+ if ( programMode == MODE_DESIGN ) {
+ if (showFlexTrack)
+ AddHotBarCornu();
+ AddHotBarTurnouts();
+ AddHotBarStructures();
+ } else {
+ AddHotBarCarDesc();
+ }
- if ( programModeOld != programMode ) {
- hotBarCurrSelects[0] = hotBarCurrSelects[1] = -1;
- programModeOld = programMode;
- }
- if (hotBarMap_da.cnt > 0 && (hotBarCurrStart >= hotBarMap_da.cnt||hotBarCurrStart < 0))
- hotBarCurrStart = 0;
- RedrawHotBar( NULL, NULL, 0, 0 );
+ if ( programModeOld != programMode ) {
+ hotBarCurrSelects[0] = hotBarCurrSelects[1] = -1;
+ programModeOld = programMode;
+ }
+ if (hotBarMap_da.cnt > 0 && (hotBarCurrStart >= hotBarMap_da.cnt||hotBarCurrStart < 0))
+ hotBarCurrStart = 0;
+ RedrawHotBar( NULL, NULL, 0, 0 );
}
}
@@ -501,45 +531,52 @@ EXPORT void InitHotBar( void )
hotBarCurrStart = (int)v;
hotbarPopupM = MenuRegister( "Hotbar Select" );
hotBarML = wMenuListCreate( hotbarPopupM, "", -1, HotbarJump );
+ hotBarHeight = hotBarDrawHeight[iconSize];
+ hotBarFs = hotBarFontSize[iconSize];
}
EXPORT void LayoutHotBar( void * redraw )
{
- wPos_t buttonWidth, winWidth, winHeight;
+ wWinPix_t buttonHeight, buttonWidth, winWidth, winHeight;
+ wWinPix_t hbHeight = hotBarHeight;
BOOL_T initialize = FALSE;
wWinGetSize( mainW, &winWidth, &winHeight );
- hotBarHeight = hotBarDrawHeight;
+ /** @prefs [Preference] LargeIcons=1.5 Sets Icon scaling limits 1.0 to 2.0 */
double scaleicon;
wPrefGetFloat(PREFSECTION, LARGEICON, &scaleicon, 1.0);
if (scaleicon<1.0) scaleicon=1.0;
if (scaleicon>2.0) scaleicon=2.0;
- if (scaleicon>1.0) {
- hotBarHeight = hotBarHeight*scaleicon;
- }
+ //if (scaleicon>1.0) {
+ // hotBarHeight = (wWinPix_t)(hotBarHeight);
+ //}
+ hotBarTextHeight = (wWinPix_t)round(wMessageGetHeight(0L) * (0.5 + (double)iconSize / 10.0));
+
if ( hotBarLabels) {
- hotBarHeight += wMessageGetHeight(0L);
+ hbHeight += hotBarTextHeight;
}
if (hotBarLeftB == NULL) {
wIcon_p bm_p;
if (winWidth < 50)
return;
bm_p = wIconCreateBitMap( 16, 16, turnbarl_bits, wDrawColorBlack );
- hotBarLeftB = wButtonCreate( mainW, 0, 0, "hotBarLeft", (char*)bm_p, BO_ICON, 0, DoHotBarLeft, NULL );
+ hotBarLeftB = wButtonCreate( mainW, 0, 0, "hotBarLeft", (char*)bm_p, BO_ICON|BO_REPEAT, 0, DoHotBarLeft, NULL );
bm_p = wIconCreateBitMap( 16, 16, turnbarr_bits, wDrawColorBlack );
- hotBarRightB = wButtonCreate( mainW, 0, 0, "hotBarRight", (char*)bm_p, BO_ICON, 0, DoHotBarRight, NULL );
- hotBarD.d = wDrawCreate( mainW, 0, 0, NULL, BD_NOCAPTURE|BD_NOFOCUS, 100, hotBarHeight, NULL, RedrawHotBar, SelectHotBar );
+ hotBarRightB = wButtonCreate( mainW, 0, 0, "hotBarRight", (char*)bm_p, BO_ICON|BO_REPEAT, 0, DoHotBarRight, NULL );
+ hotBarD.d = wDrawCreate( mainW, 0, 0, NULL, BD_NOCAPTURE|BD_NOFOCUS, 100, hbHeight, NULL, RedrawHotBar, SelectHotBar );
hotBarD.dpi = wDrawGetDPI( hotBarD.d );
hotBarD.scale = 1.0;
+ wSetCursor(hotBarD.d,wCursorNormal);
initialize = TRUE;
}
buttonWidth = wControlGetWidth((wControl_p)hotBarLeftB);
- wControlSetPos( (wControl_p)hotBarLeftB, 0, toolbarHeight );
- wControlSetPos( (wControl_p)hotBarRightB, winWidth-20-buttonWidth, toolbarHeight );
- wControlSetPos( (wControl_p)hotBarD.d, buttonWidth, toolbarHeight );
- wDrawSetSize( hotBarD.d, winWidth-20-buttonWidth*2, hotBarHeight+2, redraw );
+ buttonHeight = wControlGetHeight((wControl_p)hotBarLeftB);
+ wControlSetPos( (wControl_p)hotBarLeftB, HOTBAR_LEFT, toolbarHeight+(hbHeight-buttonHeight)/2 );
+ wControlSetPos( (wControl_p)hotBarRightB, winWidth-20-buttonWidth+HOTBAR_LEFT+1, toolbarHeight+(hbHeight-buttonHeight)/2 );
+ wControlSetPos( (wControl_p)hotBarD.d, buttonWidth+HOTBAR_LEFT+1, toolbarHeight );
+ wDrawSetSize( hotBarD.d, winWidth-20-buttonWidth*2, hbHeight+2, redraw );
hotBarD.size.x = ((double)(winWidth-20-buttonWidth*2))/hotBarD.dpi*hotBarD.scale;
- hotBarD.size.y = (double)hotBarDrawHeight/hotBarD.dpi*hotBarD.scale; //Exclude Label from calc
+ hotBarD.size.y = (double)hotBarHeight/hotBarD.dpi*hotBarD.scale; //Exclude Label from calc
wControlShow( (wControl_p)hotBarLeftB, TRUE );
wControlShow( (wControl_p)hotBarRightB, TRUE );
wControlShow( (wControl_p)hotBarD.d, TRUE );
@@ -547,7 +584,7 @@ EXPORT void LayoutHotBar( void * redraw )
ChangeHotBar( CHANGE_PARAMS );
else if (!redraw)
RedrawHotBar( NULL, NULL, 0, 0 );
- toolbarHeight += hotBarHeight+3;
+ toolbarHeight += hbHeight+3;
}
void HideHotBar( void )