colorbutton.cpp

来自「ncbi源码」· C++ 代码 · 共 237 行

CPP
237
字号
/* * =========================================================================== * PRODUCTION $Log: colorbutton.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 21:08:46  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * PRODUCTION * =========================================================================== *//*  $Id: colorbutton.cpp,v 1000.2 2004/06/01 21:08:46 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors:  Robert G. Smith * * File Description: *    CColorButton: A widget that carries a CGlColor (RGB value) as state. *   When clicked it presents a color chooser to change its state. *   It displays its color state in a patch or in text format or both. *   Its color state is not the same as its FLTK color(), nor is the text *   description of the color the FLTK label. */  #include <ncbi_pch.hpp>#include <gui/widgets/fl/colorbutton.hpp>   // me// classes I use.#include <FL/Fl_Color_Chooser.H>BEGIN_NCBI_SCOPEconst int CColorButton::sm_SwatchInset = 5; // pixelsconst int CColorButton::sm_SwatchMinHeight = 10;CColorButton::CColorButton(int X, int Y, int W, int H, const char *l)   : Fl_Button(X, Y, W, H, l),      m_ColorTextType(eNoText),      m_DrawSwatch(true){    box(FL_UP_BOX);    callback((Fl_Callback*) clickCB);    when(FL_WHEN_RELEASE);}CColorButton::~CColorButton(){}void CColorButton::draw(){    Fl_Button::draw();        const CGlColor& cgl = GetGlColor();        // draw our color swatch    int sx = 0, sy = 0, sh = 0, sw = 0;    if (GetDrawSwatch()) {            sh = h() - 2*sm_SwatchInset;        if (sh < sm_SwatchMinHeight) {            sh = sm_SwatchMinHeight;        }        if (GetColorTextType() != eNoText) {            sw = min(w()/2 - sm_SwatchInset, sh);            sw = min(sw, w() - 2*sm_SwatchInset);        } else {            sw = w() - 2*sm_SwatchInset;        }        sx = x() + w() - sw - sm_SwatchInset;        sy = y() + (h() - sh)/2;                Fl_Color col = fl_rgb_color(cgl.GetRedUC(), cgl.GetGreenUC(), cgl.GetBlueUC());        draw_box(FL_ENGRAVED_BOX, sx, sy, sw, sh, col);    }        // draw our color description text    if ( GetColorTextType() != eNoText) {                string  color_str = ColorToString();                int tx = x() + sm_SwatchInset;        int ty = y();        int tw = w() - 2*sm_SwatchInset;        if (GetDrawSwatch()) {            tw -= sw;        }        int th = h();                int act_tw, act_th;        fl_measure(color_str.c_str(), act_tw, act_th, 0);        Fl_Align text_align = (Fl_Align) (FL_ALIGN_CENTER | FL_ALIGN_CLIP);        if (act_tw > tw) {            text_align = (Fl_Align) (FL_ALIGN_LEFT | FL_ALIGN_CLIP);        }        fl_color(labelcolor());        fl_draw(color_str.c_str(), tx, ty, tw, th, text_align , 0 , 0);    }}void CColorButton::SetColorTextType(CColorButton::EDrawColorText e){    m_ColorTextType = e;}CColorButton::EDrawColorText CColorButton::GetColorTextType(void) const{    return m_ColorTextType;}void CColorButton::SetDrawSwatch(bool b){    m_DrawSwatch = b;}bool CColorButton::GetDrawSwatch(void) const{    return m_DrawSwatch;}void CColorButton::SetGlColor(const CGlColor& color){    m_GlColor = color;}const CGlColor& CColorButton::GetGlColor(void) const{    return m_GlColor;}void  CColorButton::clickCB(CColorButton* o, void* p) {    o->x_ClickCB(p);}void CColorButton::x_ClickCB(void*) {    const CGlColor& glc = GetGlColor();    uchar r = glc.GetRedUC();    uchar g = glc.GetGreenUC();    uchar b = glc.GetBlueUC();    if (fl_color_chooser("Pick a color", r, g, b)) {        SetGlColor(CGlColor(r, g, b));        redraw();    }}string CColorButton::ColorToString(void) const{    const CGlColor& col     = GetGlColor();    EDrawColorText texttype = GetColorTextType();        if (texttype == CColorButton::eNoText) {        return kEmptyStr;    }            CNcbiOstrstream oss;        if (texttype == CColorButton::eHexText) {        oss << setiosflags(IOS_BASE::uppercase) << hex << setfill('0') << "#"            << setw(2) << static_cast<int>(col.GetRedUC())            << setw(2) << static_cast<int>(col.GetBlueUC())            << setw(2) << static_cast<int>(col.GetGreenUC());    } else {        oss << "(" << dec            << static_cast<int>(col.GetRedUC()) << ","            << static_cast<int>(col.GetBlueUC()) << ","            << static_cast<int>(col.GetGreenUC()) << ")";    }    return CNcbiOstrstreamToString(oss);}END_NCBI_SCOPE/* * =========================================================================== * $Log: colorbutton.cpp,v $ * Revision 1000.2  2004/06/01 21:08:46  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * * Revision 1.6  2004/05/21 22:27:53  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.5  2003/11/21 04:02:58  ucko * Use setiosflags rather than "uppercase" manipulator lacking in G++ 2.95. * * Revision 1.4  2003/10/23 16:25:22  dicuccio * Fixed compilation error on MSVC * * Revision 1.3  2003/09/27 13:10:22  dicuccio * Minor stule fixes.  Temporarily disable colorbutton pending fix of * ColorToString() * * Revision 1.2  2003/09/26 16:20:13  ucko * ColorToString: use CNcbiOstrstream rather than ostringstream, which * G++ 2.95 doesn't support. * * Revision 1.1  2003/09/25 17:11:34  rsmith * Initial checkin * * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?