原创 Labwindows/cvi8.5学习日志(34)----颜色梯度ColorRamps简单示例

2010-7-6 20:43 3345 7 7 分类: 软件与OS


 


//*********************************************************
// Labwindows/cvi8.5  颜色梯度 ColorRamps 简单示例
// 改写自 Labwindows 自带的例程
// szlihongtao
// 2010-06-12
//*********************************************************
/*----------------------------------------------------------------------------*/
/*                                                                            */
/* Created for National Instruments - LabWindows/CVI 8.5 on 9/07/07           */
/*                                                                            */
/* FILE:    ColorRamps.c                                                      */
/*                                                                            */
/* PURPOSE: This example demonstrates how to programmatically get/set         */
/*          color ramps on various numeric controls. The program simulates    */
/*          an engine which generates heat as the faster it runs. The         */
/*          redline level and shutdown temperatures are adjustable. Changing  */
/*          those values causes the color ramps on multiple controls          */
/*          to update.                                                        */
/*                                                                            */
/*----------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------*/
/* Include files                                                              */
/*----------------------------------------------------------------------------*/
#include <ansi_c.h>
#include <cvirte.h>    
#include <userint.h>
#include "ColorRamps.h"   
/*----------------------------------------------------------------------------*/
static int panelHandle; 
/*----------------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;  /* out of memory */
    if ((panelHandle = LoadPanel (0, "ColorRamps.uir", PANEL)) < 0)
        return -1;
 DisplayPanel (panelHandle);
    RunUserInterface ();
    DiscardPanel (panelHandle);
    return 0;
}  
/*----------------------------------------------------------------------------*/
/* Updates the ColorRamps on the gauge and knob                               */
/*----------------------------------------------------------------------------*/
int CVICALLBACK RedlineCB (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    ColorMapEntry speedArray[3];
    double val;
   
    switch (event)
    {
        case EVENT_VAL_CHANGED:
  {
            GetCtrlVal(panel, control, &val);
   // 相当于  GetCtrlVal(panel, PANEL_THRESHOLDSLIDE, &val); 
   
            /*  The Engine Speed ColorRamp uses interpolated colors to create smooth
                transitions between all the colors, but everything > val is colored
                with the high color VAL_RED creating an abrupt transition.           */
            speedArray[0].dataValue.valDouble = 2.0;
            speedArray[0].color = VAL_GREEN;
   
            speedArray[1].dataValue.valDouble = val/2.0;
            speedArray[1].color = VAL_YELLOW;
   
            speedArray[2].dataValue.valDouble = val;
            speedArray[2].color = VAL_RED;    
               
            SetNumericColorRamp(panel, PANEL_NUMERICGAUGE, speedArray, VAL_BLACK, 3, 0);
            SetNumericColorRamp(panel, PANEL_NUMERICMETER, speedArray, VAL_BLACK, 3, 0);
   
            break;        
  }
    }
    return 0;

/*----------------------------------------------------------------------------*/
int CVICALLBACK QuitButtonCB (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event)
    {
        case EVENT_COMMIT:
            QuitUserInterface (0);
            break;
    }
    return 0;
}
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/


 


 


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
7
关闭 站长推荐上一条 /3 下一条